Skip to content

nicolasembleton/port-monitor

Repository files navigation

Port Monitor Tray

A macOS system tray application for monitoring and managing processes running on specific ports. Features real-time port monitoring, process management with an intuitive GUI, and flexible configuration options.

Features

Core Monitoring

  • Real-time Port Monitoring: Continuously scans specified port ranges for active processes
  • System Tray Integration: Clean, native macOS status bar icon with live indicators
  • Instant Notifications: Visual indicators when processes start/stop on monitored ports
  • Lightweight: Minimal system resource usage with efficient scanning algorithms

Process Management GUI

  • Dedicated Management Interface: Separate GUI for advanced process management
  • Smart Process Detection: Identifies Node.js, Bun, Deno, Python, and other server types
  • Advanced Filtering:
    • Text search across commands, ports, PIDs, and process types
    • Option to hide .sock entries and system processes
    • Real-time filter updates
  • Bulk Operations:
    • Select All checkbox for filtered results
    • Kill multiple selected processes at once
    • Selective process termination with safety controls
  • Lightning-Fast Scanning: Sub-second port range scanning using optimized lsof commands

Configuration Management

  • Flexible Port Ranges: Configure any port range (e.g., 3000-3020, 1025-65000)
  • Multiple Interfaces: Command-line arguments, configuration files, and GUI configuration
  • Live Configuration Updates: Changes apply immediately without restart

Architecture

The application consists of three main components:

  1. Port Monitor Tray (port-monitor-tray): Main system tray application
  2. Configuration GUI (port-monitor-config-gui): Settings management interface
  3. Process Management GUI (port-monitor-process-gui): Advanced process control interface

Building and Installation

Prerequisites

  • Rust: Install via rustup.rs
  • macOS: 10.15+ recommended
  • Xcode Command Line Tools: xcode-select --install

Build All Components

# Clone the repository
git clone <repository-url>
cd PortMonitoringApp

# Build all binaries (release mode for optimal performance)
cargo build --release

# Or build individual components:
cargo build --release --bin port-monitor-tray
cargo build --release --bin port-monitor-config-gui
cargo build --release --bin port-monitor-process-gui

Running the Applications

# Start the main tray application
./target/release/port-monitor-tray

# Open configuration GUI
./target/release/port-monitor-config-gui

# Open process management GUI
./target/release/port-monitor-process-gui

Creating macOS App Bundle

# Use the provided build script
chmod +x build_app.sh
./build_app.sh

# The app bundle will be created at: ./PortMonitor.app
# Move to Applications folder:
mv PortMonitor.app /Applications/

Usage

Main Tray Application

  1. Launch: Run port-monitor-tray or launch from Applications folder
  2. Status Indicators:
    • 🟒 Green dot: Processes detected on monitored ports
    • ⚫ Black dot: No processes detected
  3. Menu Options:
    • View current process list
    • Open Configuration GUI
    • Open Process Management GUI
    • Quit application

Configuration GUI

  • Port Range: Set start and end ports for monitoring
  • Poll Interval: Configure how often to check for processes (in seconds)
  • Real-time Preview: See current processes as you adjust settings
  • Save/Load: Automatic configuration persistence

Process Management GUI

  • Process List: View all processes listening on monitored ports
  • Search & Filter:
    • Search by command, port, PID, or process type
    • Toggle to hide .sock entries
    • Real-time filtering updates
  • Bulk Selection:
    • Individual checkboxes for each process
    • "Select All" for filtered results
  • Actions:
    • Refresh: Rescan for current processes
    • Kill Selected: Terminate chosen processes
    • Close Window: Exit GUI

Configuration

Configuration File Location

~/.config/port-monitor/config.toml

Configuration Format

[port_range]
start = 3000
end = 3020

poll_interval_seconds = 2

Example Configurations

Development Setup (Common dev ports):

[port_range]
start = 3000
end = 3020

poll_interval_seconds = 2

Full Range Monitoring (Catch services like Playwright):

[port_range]
start = 1025
end = 65000

poll_interval_seconds = 5

High-Frequency Monitoring:

[port_range]
start = 8000
end = 8100

poll_interval_seconds = 1

Command Line Arguments

# Set port range
./target/release/port-monitor-tray --start-port 3000 --end-port 3020

# Set polling interval
./target/release/port-monitor-tray --poll-interval 5

# Combined options
./target/release/port-monitor-tray --start-port 1025 --end-port 65000 --poll-interval 3

Technical Details

Performance Optimizations

  • Fast Scanning: Uses lsof -b -n -i:PORT_RANGE -sTCP:LISTEN for sub-second scans
  • Efficient Parsing: Optimized port and process parsing with service name resolution
  • Minimal Resource Usage: Event-driven architecture with configurable polling intervals

Process Detection

The application detects and categorizes:

  • Node.js processes (including npm, pnpm, bun dev servers)
  • Bun runtime processes
  • Deno applications
  • Python servers (including Django, Flask)
  • Unknown processes (with full command display)

Safety Features

  • Selective Termination: Only kill explicitly selected processes
  • System Process Protection: Filters out critical system processes
  • Confirmation Required: Visual feedback for all termination actions
  • Error Handling: Graceful failure handling with user notifications

Troubleshooting

Common Issues

"No processes found" despite running services:

  • Ensure processes are listening on TCP ports (not UDP)
  • Check that port range includes your process ports
  • Verify processes are actually bound to network interfaces

Permission errors when killing processes:

  • Some processes require elevated permissions
  • Run with sudo if needed for system processes
  • Check process ownership matches current user

GUI windows not appearing:

  • Windows may appear behind other applications
  • Check Activity Monitor for running processes
  • Try closing and reopening the GUI

Debug Information

Enable detailed logging:

RUST_LOG=debug ./target/release/port-monitor-tray

Development

Project Structure

src/
β”œβ”€β”€ main.rs              # Main tray application entry point
β”œβ”€β”€ tray.rs              # System tray integration and menu handling
β”œβ”€β”€ monitor.rs           # Port scanning and process detection
β”œβ”€β”€ config.rs            # Configuration management
β”œβ”€β”€ config_gui.rs        # Configuration GUI application
β”œβ”€β”€ process_gui.rs       # Process management GUI
β”œβ”€β”€ terminator.rs        # Process termination utilities
└── types.rs             # Shared data structures

Key Dependencies

  • tray-icon: macOS system tray integration
  • eframe/egui: GUI framework for configuration and process management
  • crossbeam-channel: Thread-safe communication
  • serde/toml: Configuration serialization
  • anyhow: Error handling

Adding New Features

  1. New Process Types: Extend ServerType enum in process_gui.rs
  2. Additional Filters: Add filter logic in ProcessGuiApp::filtered_processes()
  3. Configuration Options: Update Config struct in config.rs

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Development Guidelines

  • Follow Rust naming conventions
  • Add error handling for all system calls
  • Update README for user-facing changes
  • Test on macOS 10.15+ before submitting

About

Vibe-coded rust app to monitor ports and shut them off

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published