Skip to main content

Crate fastmetrics_process

Crate fastmetrics_process 

Source
Expand description

§fastmetrics-process

Prometheus-style process metrics built on top of fastmetrics.

This crate provides a small set of commonly used process metrics aligned with Prometheus naming conventions (for example: process_cpu_seconds_total, process_resident_memory_bytes).

Metrics are implemented as lazy (scrape-time) metrics and grouped via fastmetrics::metrics::lazy_group::LazyGroup so a single OS sampling operation is shared across all metrics per scrape.

§Usage

use fastmetrics::{error::Result, registry::{Register, Registry}};
use fastmetrics_process::ProcessMetrics;

fn main() -> Result<()> {
    let mut registry = Registry::default();
    let metrics = ProcessMetrics::default();

    // Standard Prometheus-style names: `process_*`
    let process = registry.subsystem("process")?;
    metrics.register(process)?;

    Ok(())
}

§Platform support and fallbacks

This crate uses sysinfo to collect process information. Some values may be unavailable on certain platforms or blocked by permissions; unavailable values fall back to 0.

§Exposed metrics

This crate registers base names so you can choose your prefixing strategy (for example, register into registry.subsystem("process")? to get process_* names).

  • Register into registry.subsystem("process")? to get process_* names.
  • Register at root to get unprefixed names (useful if you already have a namespace that should prefix everything).

Registered base names:

  • pid — Process ID. (type: gauge)
  • cpu — Total user and system CPU time spent in seconds. (type: counter, unit: seconds)
  • cpu_usage_percent — CPU usage of the process in percent. (type: gauge)
  • resident_memory — Resident memory size in bytes. (type: gauge, unit: bytes)
  • virtual_memory — Virtual memory size in bytes. (type: gauge, unit: bytes)
  • start_time — Start time of the process since Unix epoch in seconds. (type: gauge, unit: seconds)
  • run_time — Process run time in seconds. (type: gauge, unit: seconds)
  • open_fds — Number of open file descriptors. (type: gauge)
  • max_fds — Maximum number of open file descriptors. (type: gauge)
  • threads — Number of OS threads in the process. (type: gauge)

Standard names when registered into a process subsystem:

  • process_pid
  • process_cpu_seconds_total
  • process_cpu_usage_percent
  • process_resident_memory_bytes
  • process_virtual_memory_bytes
  • process_start_time_seconds
  • process_run_time_seconds
  • process_open_fds
  • process_max_fds
  • process_threads

§License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

Structs§

ProcessMetrics
A set of process metrics aligned with Prometheus’ standard naming conventions.