A native collectd reader plugin written in Rust that reports the top processes by CPU usage. Each read interval, the plugin samples process CPU times over a 500ms window and submits the top 10 processes as gauge values representing percentage CPU usage.
- Reads all process CPU times from
/proc/[pid]/stat - Waits 500ms and reads them again
- Calculates per-process CPU usage as a percentage (scaled by number of CPUs)
- Submits the top 10 processes to collectd
This plugin reads from /proc, so it only works on Linux systems.
Tested with:
- collectd 5.7+
Ensure you have Rust installed, then:
cargo build --releaseThe compiled shared library will be at ./target/release/libtop.so.
Note: As of collectd-plugin 0.14+, the
COLLECTD_VERSIONenvironment variable is no longer required — it defaults to the 5.7 API.
You can build without installing Rust locally. This compiles the plugin inside a container and copies libtop.so to ./dist/:
docker compose --profile build up --buildRun an integration test that starts collectd with the plugin and verifies it produces output:
docker compose --profile test up --builddocker compose --profile build --profile test up --build-
Copy the shared library to your collectd plugin directory:
sudo cp ./target/release/libtop.so /usr/lib64/collectd/top.so
-
Add the following to your
collectd.conf:LoadPlugin topNo additional plugin configuration is needed — the plugin has no configurable parameters.
-
Restart collectd:
sudo systemctl restart collectd
The plugin submits values with the following identifiers:
| Field | Value |
|---|---|
| Plugin | top |
| Type | percent |
| Plugin Instance | Process name (e.g. httpd, postgres) |
| Type Instance | cpu |
Data is stored in RRD files at paths like:
<hostname>/top-<process>/percent-cpu.rrd
For example: myserver/top-httpd/percent-cpu.rrd
A custom CGP plugin template is included in cgp/plugin/top.json. To install it, copy the file into CGP's local plugin override directory:
cp cgp/plugin/top.json /path/to/cgp/plugin/local/top.jsonTo test CGP locally with Docker, run:
docker compose --profile cgp up --buildThen open http://localhost:8080/cgp/ in your browser. After ~20 seconds (one collectd read cycle), the top plugin will appear in the sidebar with per-process CPU graphs.
MIT