GitHub - raskrebs/sonar: CLI tool for inspecting and managing services listening on localhost ports

Source

Summary

Sonar is a single-binary CLI that replaces the lsof -iTCP | grep workflow with a rich, Docker-aware port inspector. It lists every service listening on localhost, shows container names, Compose projects, resource usage, and offers kill/logs/attach/watch/wait/profile commands all by port number.

Key Insight

  • Goes well beyond simple port listing: sonar list --stats adds CPU, memory, state, uptime per process/container. sonar graph maps inter-service connections (e.g. backend to postgres) and can output Graphviz DOT.
  • sonar wait with --http=/health is the standout feature for scripting: blocks until an endpoint returns HTTP 200-399, not just TCP open, solving the common “service accepts connections before it’s actually ready” race condition in CI/dev scripts.
  • sonar profile lets you snapshot expected ports for a project, then sonar up checks if they’re all running and sonar down tears them all down — essentially a lightweight service orchestrator on top of whatever you’re already using.
  • Hides macOS noise (Figma, Discord, AirPlay, system daemons) by default, so the output is immediately useful for dev work.
  • Supports remote machines via --host user@server (SSH), so you can inspect staging/dev servers the same way.
  • sonar map does quick port forwarding (proxy from one local port to another), and sonar next finds free ports in a range — both useful for multi-service setups where port collisions are common.
  • Single binary install via curl, no dependencies. Works on macOS (lsof) and Linux (ss).