Sonar – A tiny CLI to see and kill whatever's running on localhost

Article URL: https://github.com/RasKrebs/sonar Comments URL: https://news.ycombinator.com/item?id=47452515 Points: 38 # Comments: 15

Sonar – A tiny CLI to see and kill whatever's running on localhost
Sonar – A tiny CLI to see and kill whatever's running on localhost Photo: Hacker News

Know what's running on your machine.

I got tired of running lsof -iTCP -sTCP:LISTEN | grep ...

every time a port was already taken, then spending another minute figuring out if it was a Docker container or some orphaned dev server from another worktree.

So I built sonar.

It shows everything listening on localhost, with Docker container names, Compose projects, resource usage, and clickable URLs.

You can kill processes, tail logs, shell into containers, and more — all by port number.

Downloads the latest binary to ~/.local/bin and adds it to your PATH if needed.

Restart your terminal or source ~/.zshrc .

Shell completions (tab-complete port numbers):
By default, sonar hides desktop apps and system services that listen on TCP ports but aren't relevant to development — things like Figma, Discord, Spotify, ControlCenter, AirPlay, and other macOS .app bundles and /System/Library/ daemons.

Use -a to include them.

Available columns: port , process , pid , type , url , cpu , mem , threads , uptime , state , connections , health , latency , container , image , containerport , compose , project , user , bind , ip
Shows everything about a port: full command, user, bind address, CPU/memory/threads, uptime, health check result, and Docker details if applicable.

Docker containers are stopped with docker stop instead of sending signals.

For Docker containers, runs docker logs -f .

For native processes, discovers log files via lsof and tails them.

Falls back to macOS log stream or Linux /proc/
Shows established connections between listening ports (e.g.

your backend connecting to postgres).

Proxies traffic so the service on port 6873 is also available on port 3002.

The --stats flag fetches per-process and per-container resource usage.

For Docker containers, it uses the Docker Engine API for accurate per-container metrics.

Without --stats , sonar returns instantly.

Source: This article was originally published by Hacker News

Read Full Original Article →

Share this article

Comments (0)

No comments yet. Be the first to comment!

Leave a Comment

Maximum 2000 characters