Skip to main content

A real-time process monitor with support for ROS2 nodes, showing CPU, RAM, and GPU usage

Project description

ROS2Top

A real-time monitor for ROS2 nodes showing CPU, RAM, and GPU usage - like htop but for ROS2 nodes.

Features

  • ๐Ÿ” Real-time monitoring of all ROS2 nodes
  • ๐Ÿ’ป CPU usage tracking per node
  • ๐Ÿง  RAM usage monitoring
  • ๐ŸŽฎ GPU usage tracking (NVIDIA GPUs via NVML)
  • ๐Ÿ–ฅ๏ธ Terminal-based interface using curses
  • ๐Ÿ”„ Auto-refresh with configurable intervals
  • ๐Ÿท๏ธ Process tree awareness (includes child processes)
  • ๐Ÿ“ Node registration API for reliable node-to-monitor communication

Installation

From PyPI (when published)

pip install ros2top

From Source

git clone https://github.com/AhmedARadwan/ros2top.git
cd ros2top
pip install -e .

Requirements

  • Python 3.8+
  • NVIDIA drivers (for GPU monitoring)

Python Dependencies

  • psutil>=5.8.0
  • pynvml>=11.0.0

CPP Dependencies

Usage

Examples

  • Python Example: Complete ROS2 Python node with ros2top integration
  • C++ Example: Complete ROS2 C++ package with ros2top integration

Basic Usage

# Run ros2top
ros2top

Command Line Options

ros2top --help                # Show help
ros2top --refresh 2          # Refresh every 2 seconds (default: 5)
ros2top --version           # Show version

Interactive Controls

The enhanced terminal UI provides responsive and interactive controls:

Key Action
q or Q Quit application
h or H Show help dialog
r or R Force refresh node list
p or P Pause/resume monitoring
+ or = Increase refresh rate
- Decrease refresh rate
โ†‘ / โ†“ Navigate through nodes
Tab Cycle focus between UI panels
Space Force immediate update
Home/End Jump to first/last node

Terminal UI

Visual Features

  • Color-coded usage bars: Green (low), Yellow (medium), Red (high)
  • Real-time progress bars for CPU, memory, and GPU
  • Interactive navigation with keyboard shortcuts
  • Adaptive refresh rates for optimal performance

System Overview Panel

The top panel shows real-time system information:

  • CPU usage (per-core or summary based on terminal size)
  • Memory usage with progress bar
  • GPU utilization and memory (if available)
  • ROS2 status and active node count

Display Columns

Column Description
Node ROS2 node name
PID Process ID
%CPU CPU usage percentage (normalized by core count)
RAM(MB) RAM usage in megabytes
GPU# GPU device number (if using GPU)
GPU% GPU utilization percentage
GMEM GPU memory usage in MB

Examples

Monitor nodes with 2-second refresh

ros2top --refresh 2

How It Works

  1. Node Registartion: Every node registers its name and PID at startup with ros2top.
  2. Resource Monitoring: Uses psutil for CPU/RAM and pynvml for GPU metrics.
  3. Display: Curses-based terminal interface for real-time updates.

Troubleshooting

No GPU monitoring

  • Install NVIDIA drivers
  • Install pynvml: pip install pynvml

Nodes not showing up

  • Verify nodes are running: ros2 node list
  • Check node info: ros2 node info /your_node
  • Some nodes might not have detectable PIDs

Development

Setup Development Environment

git clone https://github.com/AhmedARadwan/ros2top.git
cd ros2top
pip install -e .

Running Tests

python -m pytest tests/

Code Style

black ros2top/
flake8 ros2top/
mypy ros2top/

Architecture

ros2top/
โ”œโ”€โ”€ ros2top/                 # Python package
โ”‚   โ”œโ”€โ”€ __init__.py         # Package initialization and public API
โ”‚   โ”œโ”€โ”€ main.py             # CLI entry point
โ”‚   โ”œโ”€โ”€ node_monitor.py     # Core monitoring logic
โ”‚   โ”œโ”€โ”€ node_registry.py    # Node registration system
โ”‚   โ”œโ”€โ”€ gpu_monitor.py      # GPU monitoring
โ”‚   โ”œโ”€โ”€ ros2_utils.py       # ROS2 utilities
โ”‚   โ””โ”€โ”€ ui/                 # User interface components
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ terminal_ui.py  # Main curses interface
โ”‚       โ”œโ”€โ”€ components.py   # UI components
โ”‚       โ””โ”€โ”€ layout.py       # UI layout management
โ”œโ”€โ”€ include/                # C++ headers
โ”‚   โ””โ”€โ”€ ros2top/
โ”‚       โ””โ”€โ”€ ros2top.hpp     # C++ API for node registration
โ”œโ”€โ”€ examples/               # Example integrations
โ”‚   โ”œโ”€โ”€ python/             # Python examples
โ”‚   โ”‚   โ”œโ”€โ”€ README.md
โ”‚   โ”‚   โ””โ”€โ”€ example_node.py
โ”‚   โ””โ”€โ”€ cpp/                # C++ examples
โ”‚       โ”œโ”€โ”€ README.md
โ”‚       โ””โ”€โ”€ example_monitored_node/  # Complete ROS2 package
โ”œโ”€โ”€ tests/                  # Test suite
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ test_ros2top.py
โ”œโ”€โ”€ cmake/                  # CMake configuration
โ”œโ”€โ”€ pyproject.toml          # Python build configuration
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ”œโ”€โ”€ LICENSE                 # MIT license
โ””โ”€โ”€ README.md              # This file

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Changelog

v0.1.3

  • Remove dependency on ROS2 to start ros2top.

v0.1.2

  • Enhance README

v0.1.1

  • Add example usage
  • Enhance README

v0.1.0

  • Initial release
  • Basic node monitoring with CPU, RAM, GPU usage
  • Terminal interface with curses
  • Command line options
  • Node registration and process mapping

Similar Tools

  • htop - System process monitor
  • nvtop - GPU process monitor
  • ros2 node list - Basic ROS2 node listing

Acknowledgments

  • Inspired by htop and nvtop
  • Built for the ROS2 community
  • Uses psutil for system monitoring and pynvml for GPU monitoring

Node Registration API

For the most reliable monitoring, ROS2 nodes can register themselves with ros2top. This is especially useful for:

  • Multiple nodes running in the same Python process
  • Complex applications where automatic detection might miss some nodes
  • Getting additional metadata about nodes

Basic Registration

import ros2top

# Register your node (call this once when your node starts)
ros2top.register_node('/my_node_name')

# Send periodic heartbeats (optional, but recommended)
ros2top.heartbeat('/my_node_name')

# Unregister when shutting down (optional, automatic cleanup on process exit)
ros2top.unregister_node('/my_node_name')

Advanced Registration with Metadata

import ros2top

# Register with additional information
ros2top.register_node('/camera_processor', {
    'description': 'Processes camera feed for object detection',
    'type': 'vision_processor',
    'input_topics': ['/camera/image_raw'],
    'output_topics': ['/detected_objects'],
    'framerate': 30
})

# In your main loop, send heartbeats every few seconds
ros2top.heartbeat('/camera_processor')

Node Detection

ros2top uses a node registration system for reliable node detection:

Primary Method: Node Registration API

The most reliable way is for ROS2 nodes to explicitly register themselves:

import ros2top

# Register your node
ros2top.register_node('/my_node', {'description': 'My awesome node'})

# Send periodic heartbeats (recommended)
ros2top.heartbeat('/my_node')

# Unregister when shutting down (optional - automatic cleanup on exit)
ros2top.unregister_node('/my_node')

Automatic Cleanup

  • Nodes are automatically unregistered when the process exits
  • Stale registrations are cleaned up periodically
  • Registry is stored in ~/.ros2top/registry/

Benefits of Registration API

  • Reliable: No dependency on tracing or process matching
  • Fast: Instant node detection without scanning
  • Accurate: Direct PID mapping from the registering process
  • Simple: Works with any ROS2 node type (Python, C++, etc.)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ros2top-0.2.0.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ros2top-0.2.0-py3-none-any.whl (34.0 kB view details)

Uploaded Python 3

File details

Details for the file ros2top-0.2.0.tar.gz.

File metadata

  • Download URL: ros2top-0.2.0.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ros2top-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4808ba732a20eb754db2a31f397379f56ec76d8e36c8b3b396b51290e668f13f
MD5 80f369e459d1158dfa572ae683b0fdf6
BLAKE2b-256 ed0dee681a865f285d4447a1fcf19b389545a9fb46f27412cb7b67dde6225a50

See more details on using hashes here.

File details

Details for the file ros2top-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ros2top-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 34.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ros2top-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8c74b75ac282da871fc708f1b8d4c45430d1e7d21928fe3cfe862f277369501
MD5 690fec9d4aa0bdff3c842d3dbb487f29
BLAKE2b-256 7ecfc75f5886b143bf41d334fb3facc8d3068a60896345676109b605827b5a0f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page