A Prometheus exporter that reads host telemetry straight from /proc and
/sys. Most agents wrap the kernel in layers; this one parses the raw files
the kernel already exposes, runs a poller thread per subsystem, and serves the
numbers on a /metrics endpoint.
Single C++17 file, no dependencies beyond libc and pthreads. Builds to one static-ish binary you can drop on any Linux host.
/proc, /sys files -> collectors -> poller threads -> registry -> /metrics
Each poller reads its source on a fixed interval and writes the latest values into a mutex-guarded registry. The HTTP server renders whatever is in the registry and handles each scrape on its own thread, so a scrape never blocks on a file read or on another scrape.
Names follow node_exporter where one exists, so dashboards and alerts built
for it work here too.
| Source | Metrics |
|---|---|
/proc/stat |
node_cpu_seconds_total, node_context_switches_total, node_boot_time_seconds, node_forks_total, node_procs_running, node_procs_blocked |
/proc/meminfo |
node_memory_*_bytes |
/proc/loadavg |
node_load1, node_load5, node_load15 |
/proc/net/dev |
node_network_receive_*_total, node_network_transmit_*_total |
/proc/diskstats |
node_disk_reads_completed_total, node_disk_read_bytes_total, node_disk_writes_completed_total, node_disk_written_bytes_total, node_disk_io_time_seconds_total |
/proc/mounts + statvfs |
node_filesystem_size_bytes, node_filesystem_free_bytes, node_filesystem_avail_bytes, node_filesystem_files, node_filesystem_files_free |
/sys/class/thermal |
node_thermal_zone_temp |
make
./monitor --listen :9101 --interval 5
curl -s localhost:9101/metricsOr without make:
c++ -std=c++17 -O2 -pthread -o monitor monitor.cppFlags:
--listenhost:port to bind (default:9101)--intervalseconds between polls (default5)--procfsprocfs root (default/proc)--sysfssysfs root (default/sys)
The --procfs and --sysfs flags let you point at a mounted host root from
inside a container, or at the test fixtures on a non-Linux machine.
make test # builds, then runs ./monitor --selftestThe self-test parses the sample files under fixtures/ and checks the parsed
numbers and the rendered output. It needs no Linux and no network, so it runs
on any dev machine.
scrape_configs:
- job_name: linux-system-monitor
static_configs:
- targets: ["localhost:9101"]Build, copy the binary to /opt/linux-system-monitor, and install the unit:
make
sudo mkdir -p /opt/linux-system-monitor
sudo cp monitor /opt/linux-system-monitor/
sudo cp deploy/linux-system-monitor.service /etc/systemd/system/
sudo systemctl enable --now linux-system-monitor- A collector whose source file is missing returns nothing instead of failing, so a wrong kernel or a missing mount just omits that data.
loopandramblock devices are filtered from disk stats; pseudo filesystems (tmpfs, cgroup, and similar) are filtered from filesystem stats.- The HTTP server reads one request buffer per connection, which is all a Prometheus GET needs. It is a scrape target, not a general web server.
- All values are doubles, matching Prometheus, which stores every sample as a float64.