⏱ metrics-process
This crate provides a Prometheus-style process metrics collector for the metrics crate, supporting Linux, macOS, and Windows. The collector code is manually rewritten in Rust from the official Prometheus client for Go (client_golang).
Supported Metrics
This crate supports the following metrics provided by Prometheus for process metrics.
Metric name | Help string |
---|---|
process_cpu_seconds_total |
Total user and system CPU time spent in seconds. |
process_open_fds |
Number of open file descriptors. |
process_max_fds |
Maximum number of open file descriptors. |
process_virtual_memory_bytes |
Virtual memory size in bytes. |
process_virtual_memory_max_bytes |
Maximum amount of virtual memory available in bytes. |
process_resident_memory_bytes |
Resident memory size in bytes. |
process_heap_bytes |
Process heap size in bytes. |
process_start_time_seconds |
Start time of the process since the Unix epoch in seconds. |
process_threads |
Number of OS threads in the process. |
For each platform, it is equivalent to what the official Prometheus client for Go (client_golang) provides.
Metric name | Linux | macOS | Windows |
---|---|---|---|
process_cpu_seconds_total |
x | x | x |
process_open_fds |
x | x | x |
process_max_fds |
x | x | x |
process_virtual_memory_bytes |
x | x | x |
process_virtual_memory_max_bytes |
x | x | |
process_resident_memory_bytes |
x | x | x |
process_heap_bytes |
|||
process_start_time_seconds |
x | x | x |
process_threads |
x | x |
Please note that if you only need to compile this crate on non-supported
platforms, you can use the dummy
feature. Enabling this feature activates a
dummy collector, which returns an empty Metrics
.
Usage
Use this crate with metrics-exporter-prometheus as an exporter like:
use thread;
use ;
use PrometheusBuilder;
use Collector;
let builder = new;
builder
.install
.expect;
let collector = default;
// Call `describe()` method to register help string.
collector.describe;
loop
Or with axum (or any web application framework you like) to collect metrics
whenever the /metrics
endpoint is invoked like:
use ;
use PrometheusBuilder;
use Collector;
use TcpListener;
async
Features
This crate offers the following features:
Feature Name | Description |
---|---|
dummy |
Enables a dummy collector that returns an empty Metrics on non-supported platforms. |
Difference from metrics-process-promstyle
It appears that metrics-process-promstyle only supports Linux, but this crate
(metrics-process) supports Linux, macOS, and Windows. Additionally, this crate
supports process_open_fds
and process_max_fds
in addition to what
metrics-process-promstyle supports.
License
The code follows the MIT license written in LICENSE. Contributors need to agree that any modifications sent to this repository follow the license.