kh3rld/sysmon

★ 0Forks 0C++GitHub ↗Compare

README

SysMon - System Monitor

A real-time system monitoring application built with Dear ImGui and SDL2, providing comprehensive system information visualization including CPU, memory, network, thermal, and fan monitoring.

Quick Start

# Clone and build
git clone https://github.com/kh3rld/sysmon.git
cd sysmon
make

# Run the system monitor
./monitor

# Or try test mode for quick system info
./monitor --test

Description

SysMon is a lightweight, high-performance system monitoring tool designed for Linux systems. It provides real-time visualization of system resources with a modern, responsive GUI built using Dear ImGui. The application features intelligent caching mechanisms and optimized process scanning to ensure minimal resource usage while delivering comprehensive system insights.

Key Features:

  • Real-time monitoring of CPU, memory, network, and system processes
  • Modern GUI with dark theme optimized for system monitoring
  • Performance optimized with intelligent caching and efficient I/O
  • Command-line interface for quick system info without GUI
  • Cross-platform build support with comprehensive CI/CD pipeline

For detailed information about features, installation, and usage, see our Release Notes.

Features

System Information

  • OS Detection: Automatic detection of operating system (Linux, Windows, macOS, etc.)
  • Host Information: Display hostname and current username
  • CPU Model: Real-time CPU brand string detection
  • Process Statistics: Live count of running, sleeping, zombie, and stopped processes

Performance Monitoring

  • CPU Usage Graph: Real-time CPU utilization with configurable update rate (1-30 FPS)
  • Thermal Monitoring: Temperature tracking with color-coded status indicators
  • Fan Speed Monitoring: RPM tracking with PWM level display
  • Graph Controls: Pause/resume, FPS adjustment, and Y-axis scaling

Memory & Process Management

  • Memory Usage: RAM, SWAP, and disk usage with visual progress bars
  • Process Table: Sortable process list with filtering capabilities
  • Process Details: PID, name, state, CPU%, and memory% for each process
  • Multi-selection: Ctrl+Click to select multiple processes

Network Monitoring

  • Interface Detection: Automatic discovery of network interfaces and IP addresses
  • Statistics Tables: Detailed RX/TX statistics (bytes, packets, errors, drops)
  • Usage Visualization: Progress bars showing network usage relative to 2GB scale
  • Real-time Monitoring: Live network activity tracking

Architecture

Core Components

sysmon/
├── main.cpp          # Application entry point and window management
├── header.h          # Global declarations and data structures
├── system.cpp        # System information and performance monitoring
├── mem.cpp          # Memory management and process handling
├── network.cpp      # Network interface monitoring
├── Makefile         # Build configuration
└── imgui/           # Dear ImGui library (external dependency)

Data Structures

System Information

struct SystemInfo {
    string os_name;
    string hostname;
    string username;
    string cpu_model;
    int total_processes;
    int running_processes;
    int sleeping_processes;
    int zombie_processes;
    int stopped_processes;
};

Performance Monitoring

struct CPUStats {
    long long int user, nice, system, idle;
    long long int iowait, irq, softirq, steal;
    long long int guest, guestNice;
};

struct ThermalInfo {
    float temperature;
    bool available;
};

struct FanInfo {
    int speed;      // RPM
    int level;      // PWM level (0-255)
    bool active;
    bool available;
};

Memory & Processes

struct MemoryInfo {
    unsigned long total_ram, available_ram, used_ram;
    unsigned long total_swap, used_swap;
    unsigned long total_disk, used_disk;
};

struct Proc {
    int pid;
    string name;
    char state;
    long long int vsize, rss, utime, stime;
};

Network Monitoring

struct Networks {
    vector<IP4> ip4s;
};

struct RX {
    int bytes, packets, errs, drop;
    int fifo, frame, compressed, multicast;
};

struct TX {
    int bytes, packets, errs, drop;
    int fifo, colls, carrier, compressed;
};

Build Instructions

Prerequisites

Linux

# Install SDL2 development libraries
sudo apt-get install libsdl2-dev

# For Ubuntu/Debian
sudo apt-get install build-essential

macOS

# Install SDL2 via Homebrew
brew install sdl2

Windows (MSYS2/MinGW)

# Install SDL2 via pacman
pacman -S mingw-w64-i686-SDL2

Building

  1. Clone and navigate to project directory

    cd sysmon
  2. Build the application

    make
  3. Run the application

    ./monitor
  4. Clean build artifacts

    make clean

Usage

Main Interface

The application displays three main windows:

  1. System Window (Top-left)

    • System information display
    • Performance monitoring tabs (CPU, Fan, Thermal)
    • Real-time graphs with configurable controls
  2. Memory & Processes Window (Top-right)

    • Memory usage bars (RAM, SWAP, Disk)
    • Process table with sorting and filtering
    • Multi-process selection capabilities
  3. Network Window (Bottom)

    • Network interface overview
    • Statistics and usage visualization tabs
    • Real-time network monitoring

Controls

Graph Controls

  • Pause/Resume: Stop or resume data collection
  • FPS Slider: Adjust update rate (1-30 FPS)
  • Y-Scale: Modify graph vertical scale

Process Table

  • Filter Input: Type to filter processes by name
  • Column Sorting: Click column headers to sort
  • Multi-selection: Ctrl+Click to select multiple processes
  • Clear Selection: Button to deselect all processes

Network Monitoring

  • Tab Navigation: Switch between statistics and visualization
  • Real-time View: Combined RX/TX activity display

API Reference

System Information Functions

SystemInfo getSystemInfo()

Returns comprehensive system information including OS, hostname, username, CPU model, and process counts.

CPUStats getCurrentCPUStats()

Reads current CPU statistics from /proc/stat.

float calculateCPUUsage(CPUStats prev, CPUStats curr)

Calculates CPU usage percentage between two measurements.

Memory & Process Functions

MemoryInfo getMemoryInfo()

Parses /proc/meminfo and filesystem statistics to return memory usage information.

vector<Proc> getAllProcesses()

Scans /proc directory to collect information about all running processes.

Proc getProcessInfo(int pid)

Retrieves detailed information about a specific process from /proc/[pid]/stat.

float calculateProcessMemory(const Proc &proc, unsigned long total_memory)

Calculates memory usage percentage for a process relative to total system memory.

Network Functions

Networks getNetworkInterfaces()

Discovers network interfaces and their IPv4 addresses using getifaddrs().

void parseNetworkDevFile()

Parses /proc/net/dev to collect network statistics for all interfaces.

string formatNetworkBytes(uint64_t bytes)

Formats byte counts into human-readable strings (B, KB, MB, GB).

Thermal & Fan Functions

ThermalInfo getThermalInfo()

Searches for thermal sensors in /sys/class/thermal/ and /sys/class/hwmon/.

FanInfo getFanInfo()

Discovers fan sensors and retrieves speed, PWM level, and status information.

Graph Management

Global Variables

// CPU Graph
extern vector<float> cpu_history;
extern atomic<float> current_cpu_usage;
extern bool graph_paused;
extern float graph_fps;
extern float graph_scale;

// Thermal Graph
extern vector<float> thermal_history;
extern atomic<float> current_temperature;
extern atomic<bool> thermal_available;

// Fan Graph
extern vector<int> fan_speed_history;
extern atomic<int> current_fan_speed;
extern atomic<bool> fan_available;

Update Functions

void updateCPUHistory();      // Updates CPU usage data
void updateThermalHistory();  // Updates temperature data
void updateFanHistory();      // Updates fan speed data

Rendering Functions

void renderCPUGraph();        // Renders CPU usage graph
void renderThermalGraph();    // Renders temperature graph
void renderFanGraph();        // Renders fan speed graph

Technical Details

Thread Safety

  • All shared data structures use std::atomic for thread-safe access
  • Critical sections are protected with std::mutex
  • Graph data updates are synchronized to prevent race conditions

Performance Considerations

  • Process scanning is limited to 3-second intervals to reduce system load
  • Network data updates occur every 2 seconds
  • Graph history is limited to 100 data points to prevent memory bloat
  • CPU usage calculations use efficient /proc/stat parsing

Platform Compatibility

  • Primary: Linux (uses /proc filesystem extensively)
  • Secondary: Windows, macOS (limited functionality)
  • Dependencies: SDL2, OpenGL 3.0+, Dear ImGui

File System Dependencies

  • /proc/stat - CPU and process statistics
  • /proc/meminfo - Memory information
  • /proc/net/dev - Network interface statistics
  • /proc/[pid]/stat - Individual process information
  • /sys/class/thermal/ - Thermal sensor data
  • /sys/class/hwmon/ - Hardware monitoring data

Contributing

Code Style

  • Use consistent naming conventions (snake_case for functions, camelCase for variables)
  • Include comprehensive error handling for file operations
  • Add comments for complex algorithms and data structures
  • Follow the existing modular architecture

Adding New Features

  1. Define data structures in header.h
  2. Implement functionality in appropriate .cpp file
  3. Add rendering functions for UI components
  4. Update main window functions to include new features
  5. Test on multiple Linux distributions

License

This project is open source. Please refer to the individual component licenses for Dear ImGui and SDL2.

Troubleshooting

Common Issues

Build Errors

  • SDL2 not found: Install development libraries (libsdl2-dev)
  • OpenGL errors: Ensure OpenGL 3.0+ support
  • Compilation errors: Check C++11 compatibility

Runtime Issues

  • No thermal data: System may not have accessible thermal sensors
  • No fan data: Fan sensors may not be available or accessible
  • Permission errors: Some /proc files may require elevated privileges

Performance Issues

  • High CPU usage: Reduce graph FPS or pause monitoring
  • Memory leaks: Ensure proper cleanup in destructors
  • UI lag: Check for excessive process scanning or network polling

Debug Information

  • Enable debug output by adding -DDEBUG to CXXFLAGS
  • Check console output for error messages
  • Verify file permissions for /proc and /sys access

Contributors

kh3rld

Issues