This Go application is a Prometheus exporter for turbostat metrics.
It collects CPU and core statistics using the turbostat
tool and exposes them in a format that Prometheus can scrape.
- Prometheus Integration: Exposes metrics via an HTTP server for Prometheus to scrape.
- Dynamic Metric Registration: Automatically registers metrics based on turbostat output headers.
- Configuration via Environment Variables: Customize behavior using
.env
files. - Background Collection Mode: Optionally collect metrics in the background at specified intervals.
You can download the binaries for available platforms in the Releases.
- Run with
turbostat-exporter
. Default listener on0.0.0.0:9101
(also displayed as logs), - or run with docker (but must be run as priviliged to have all information available):
docker run -p 9101:9101 --privileged ghcr.io/blackdark/prometheus_turbotstat_exporter:main
Part of the output from the scrape:
...
turbostat_cpu_states_percent{num_cpu="6",type="c1e"} 0.03
turbostat_cpu_states_percent{num_cpu="6",type="c3"} 0.05
turbostat_cpu_states_percent{num_cpu="6",type="c6"} 1.37
turbostat_cpu_states_percent{num_cpu="6",type="c7s"} 0
turbostat_cpu_states_percent{num_cpu="6",type="c8"} 1.11
turbostat_cpu_states_percent{num_cpu="6",type="c9"} 0.13
turbostat_cpu_states_percent{num_cpu="6",type="poll"} 0
turbostat_cpu_states_percent{num_cpu="7",type="c1"} 0.01
turbostat_cpu_states_percent{num_cpu="7",type="c10"} 96.91
turbostat_cpu_states_percent{num_cpu="7",type="c1e"} 0.03
turbostat_cpu_states_percent{num_cpu="7",type="c3"} 0.01
turbostat_cpu_states_percent{num_cpu="7",type="c6"} 1.36
...
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies: Ensure Go is installed on your system, then run:
go mod tidy
-
Build the application:
go build -o turbostat_exporter
-
Run the exporter:
./turbostat_exporter
-
Access metrics: Open a browser or use
curl
to accesshttp://localhost:9101/metrics
.
The application can be configured using environment variables defined in a .env
file:
TURBOSTAT_EXPORTER_LOG_LEVEL
: Set logging level (debug
orinfo
).TURBOSTAT_EXPORTER_DEFAULT_COLLECT_SECONDS
: Default interval for data collection.TURBOSTAT_EXPORTER_DEBUG_CAT_EXEC
: If set totrue
, uses a test mode with sample data.TURBOSTAT_COLLECT_IN_BACKGROUND
: Enables background data collection if set totrue
.TURBOSTAT_COLLECT_IN_BACKGROUND_INTERVAL
: Interval for background data collection.
To modify the code:
- Edit source files in your preferred editor.
- Rebuild the application using the build command above.