⏱ Cross-platform Prometheus style process metrics collector of metrics crate

Overview

crates.io docs.rs MIT License Build Test Audit

metrics-process

This crate provides Prometheus style process metrics collector of metrics crate for Linux, macOS, and Windows. Collector code is manually re-written to Rust from an official prometheus client of go (client_golang)

Supported metrics

This crate supports the following metrics, equal to what official prometheus client of go (client_golang) provides.

Metric name Help string Linux macOS Windows
process_cpu_seconds_total Total user and system CPU time spent in seconds. x x x
process_open_fds Number of open file descriptors. x x x
process_max_fds Maximum number of open file descriptors. x x x
process_virtual_memory_bytes Virtual memory size in bytes. x x x
process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes. x x
process_resident_memory_bytes Resident memory size in bytes. x x x
process_heap_bytes Process heap size in bytes.
process_start_time_seconds Start time of the process since unix epoch in seconds. x x x
process_threads Number of OS threads in the process. x x

Usage

Use this crate with metrics-exporter-prometheus as an exporter like:

use std::thread;
use std::time::{Duration, Instant};

use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_process::Collector;

let builder = PrometheusBuilder::new();
builder
    .install()
    .expect("failed to install Prometheus recorder");

let collector = Collector::default();
// Call `describe()` method to register help string.
collector.describe();

loop {
    let s = Instant::now();
    // Periodically call `collect()` method to update information.
    collector.collect();
    thread::sleep(Duration::from_millis(750));
}

Or with axum (or any web application framework you like) to collect metrics whenever the /metrics endpoint is invoked like:

use axum::{routing::get, Router, Server};
use metrics_exporter_prometheus::PrometheusBuilder;
use metrics_process::Collector;

#[tokio::main]
async fn main() {
    let builder = PrometheusBuilder::new();
    let handle = builder
        .install_recorder()
        .expect("failed to install Prometheus recorder");

    let collector = Collector::default();
    // Call `describe()` method to register help string.
    collector.describe();

    let addr = "127.0.0.1:9000".parse().unwrap();
    let app = Router::new().route(
        "/metrics",
        get(move || {
            // Collect information just before handle '/metrics'
            collector.collect();
            std::future::ready(handle.render())
        }),
    );
    Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

Difference from metrics-process-promstyle

It seems metrics-process-promstyle only support Linux but this crate (metrics-process) supports Linux, macOS, and Windows. Additionally, this crate supports process_open_fds and process_max_fds addition to what metrics-process-promstyle supports.

License

The code follows MIT license written in LICENSE. Contributors need to agree that any modifications sent in this repository follow the license.

Comments
  • Update windows requirement from 0.41.0 to 0.42.0

    Update windows requirement from 0.41.0 to 0.42.0

    Updates the requirements on windows to permit the latest version.

    Release notes

    Sourced from windows's releases.

    0.42.0

    This release provides a major update to the windows-sys crate, the first update since 0.36.1, and includes numerous fixes and improvements to the completeness and correctness of both API definitions and import libs.

    What's Changed

    Changelog for windows crate: https://github.com/microsoft/windows-rs/compare/0.41.0...0.42.0 Changelog for windows-sys crate: https://github.com/microsoft/windows-rs/compare/0.36.1...0.42.0

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 2
  • Update windows requirement from 0.39.0 to 0.41.0

    Update windows requirement from 0.39.0 to 0.41.0

    Updates the requirements on windows to permit the latest version.

    Release notes

    Sourced from windows's releases.

    0.41.0

    This is a minor service release addressing a number of issues mostly originating from the underlying win32 metadata which have now been resolved.

    This release does not include an update to the windows-sys crate, which remains stable and unchanged.

    What's Changed

    New Contributors

    Full Changelog: https://github.com/microsoft/windows-rs/compare/0.40.0...0.41.0

    Commits
    • b1f53ea Version 0.41.0 (#2058)
    • b13b328 Fix HSTRING to conform to Rust's aliasing rules (#2057)
    • 49317c3 Separate Vtable support from Interface trait (#2051)
    • bd3eac8 Remove dlltool prefix hack (#2052)
    • a9728b2 Update the win32 metadata to version 33.0.18 (#2050)
    • de158fb Add support for declaring interfaces derived from existing interfaces (#2048)
    • 29e5510 Add Natvis definitions for types defined in the core module of the `windows...
    • e018d41 Further constrain transforming array parameters to avoid potentially polymorp...
    • dd244b5 Add macros for creating null-terminated string literals to windows-sys (#2043)
    • ba4566c Add WMI sample (#2041)
    • Additional commits viewable in compare view

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 2
  • Update axum requirement from 0.5.15 to 0.6.0

    Update axum requirement from 0.5.15 to 0.6.0

    Updates the requirements on axum to permit the latest version.

    Release notes

    Sourced from axum's releases.

    axum - v0.6.0

    Routing

    • fixed: Nested routers are now allowed to have fallbacks (#1521):

      let api_router = Router::new()
          .route("/users", get(|| { ... }))
          .fallback(api_fallback);
      

      let app = Router::new() // this would panic in 0.5 but in 0.6 it just works // // requests starting with /api but not handled by api_router // will go to /api_fallback .nest("/api", api_router);

      The outer router's fallback will still apply if a nested router doesn't have its own fallback:

      // this time without a fallback
      let api_router = Router::new().route("/users", get(|| { ... }));
      

      let app = Router::new() .nest("/api", api_router) // api_fallback will inherit this fallback .fallback(app_fallback);

    • breaking: The request /foo/ no longer matches /foo/*rest. If you want to match /foo/ you have to add a route specifically for that (#1086)

      For example:

      use axum::{Router, routing::get, extract::Path};
      

      let app = Router::new() // this will match /foo/bar/baz .route("/foo/*rest", get(handler)) // this will match /foo/ .route("/foo/", get(handler)) // if you want /foo to match you must also add an explicit route for it .route("/foo", get(handler));

      async fn handler( // use an Option because /foo/ and /foo don't have any path params params: Option<Path<String>>,

    ... (truncated)

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
  • Update windows requirement from 0.41.0 to 0.43.0

    Update windows requirement from 0.41.0 to 0.43.0

    Updates the requirements on windows to permit the latest version.

    Release notes

    Sourced from windows's releases.

    0.43.0

    String constants now preserve their original encoding as either UTF-8 or UTF-16 null-terminated string constants. This makes many string constants directly and efficiently usable as constants to pass to various Windows APIs that expect either "ansi" or wide null-terminated string literals. This update also provides a collection of small improvements, particularly to string handling. Updated Win32 metadata provides fixes to various API definitions.

    This release does not include an update to the windows-sys crate, which remains stable and unchanged.

    What's Changed

    Full Changelog: https://github.com/microsoft/windows-rs/compare/0.42.0...0.43.0

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
  • Update windows requirement from 0.39.0 to 0.40.0

    Update windows requirement from 0.39.0 to 0.40.0

    Updates the requirements on windows to permit the latest version.

    Release notes

    Sourced from windows's releases.

    0.40.0

    This release includes a rollup of fixes and improvements to the Win32 metadata and many small fixes to the Rust bindings themselves. Notably, fixed-size array parameters, APIs with non-system calling conventions such as cdecl, reproducible builds, and far more accurate import libs.

    This release does not include an update to the windows-sys crate, which remains stable and unchanged.

    What's Changed

    New Contributors

    ... (truncated)

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
  • Update rlimit requirement from 0.8.3 to 0.9.0

    Update rlimit requirement from 0.8.3 to 0.9.0

    Updates the requirements on rlimit to permit the latest version.

    Changelog

    Sourced from rlimit's changelog.

    0.9.0 - 2022-12-28

    • rlimit v0.9.0 follows the latest libc definitions.
    • The MSRV of v0.9.* is explicitly guaranteed to be 1.59.0.

    0.8.3 - 2022-04-06

    [PR #43](Nugine/rlimit#43): Downgrade MSRV

    0.8.2 - 2022-04-06

    rlimit v0.8.2 uses libc definitions again instead of incorrect custom bindings.

    rlimit v0.8.0 and v0.8.1 are yanked now.

    0.8.1 - 2022-04-01

    [PR #36](Nugine/rlimit#36): Fix the bindings for aarch64-apple-darwin.

    0.8.0 - 2022-03-31

    rlimit v0.8.0 uses custom ffi bindings instead of libc for rlimit symbols and constants. The custom bindings are kept in sync with system headers automatically.

    All resource constants are available on all unix platforms. Passing an unsupported resource to [set|get|p]rlimit will result in a custom IO error.

    Added

    • Resource::is_supported

    Changed

    • Resource::as_raw is a private method now.

    Removed

    • Resource::available_names
    • Resource::available_resources
    • RawResource

    ... (truncated)

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 1
An asynchronous dumb exporter proxy for prometheus. This aggregates all the metrics and exposes as a single scrape endpoint.

A dumb light weight asynchronous exporter proxy This is a dumb lightweight asynchronous exporter proxy that will help to expose multiple application m

Dark streams 3 Dec 4, 2022
Easily add metrics to your system -- and actually understand them using automatically customized Prometheus queries

Autometrics ?? ✨ Autometrics is a macro that makes it trivial to add useful metrics to any function in your codebase. Easily understand and debug your

Fiberplane 341 Feb 6, 2023
Easily add metrics to your system -- and actually understand them using automatically customized Prometheus queries

A Rust macro that makes it easy to understand the error rate, response time, and production usage of any function in your code. Jump from your IDE to

Autometrics 462 Mar 6, 2023
A minimal, allocation-free Prometheus/OpenMetrics metrics implementation for `no-std` and embedded Rust.

tinymetrics a minimal, allocation-free Prometheus/OpenMetrics metrics implementation for no-std and embedded projects. why should you use it? you may

Eliza Weisman 282 Apr 16, 2023
Parse, edit and merge Prometheus metrics exposition format

promerge Promerge provides minimalistic and easy to use API to parse and manipulate Prometheus metrics. A simple usecase could be collecting metrics f

Mike Taghavi 4 Aug 12, 2023
🔍 Fully-featured metrics collection agent for First Tech Challenge competitions. Supports Prometheus.

Scout Scout is a fully-featured free and open source metrics collector for FTC competitions. The project is licensed under the GNU LGPLv3 license. Fea

hivemind 3 Oct 24, 2023
An asynchronous Prometheus exporter for iptables

iptables_exporter An asynchronous Prometheus exporter for iptables iptables_exporter runs iptables-save --counter and scrapes the output to build Prom

Kevin K. 21 Dec 29, 2022
A Prometheus Aggregation Gateway for FAAS applications

Gravel Gateway Gravel Gateway is a Prometheus Push Gateway for FAAS applications. In particular it allows aggregation to be controlled by the incoming

Colin Douch 85 Nov 23, 2022
A Prometheus Aggregation Gateway for FAAS applications

Gravel Gateway Gravel Gateway is a Prometheus Push Gateway for FAAS applications. In particular it allows aggregation to be controlled by the incoming

Colin Douch 85 Nov 23, 2022
A Prometheus exporter for WireGuard

wireguard_exporter An asynchronous Prometheus exporter for wireguard wireguard_exporter runs wg show [..] and scrapes the output to build Prometheus m

Kevin K. 15 Dec 29, 2022
Export statistics of Mosquitto MQTT broker (topic: $SYS) to Prometheus

Preface The Mosquitto MQTT broker provides a number of statistics on the special $SYS/# topic (see mosquitto(8)). Build requirements As a Rust program

Bobobo-bo Bo-bobo 2 Dec 15, 2022
Prometheus instrumentation service for the NGINX RTMP module.

nginx-rtmp-exporter Prometheus instrumentation service for the NGINX RTMP module. Usage nginx-rtmp-exporter [OPTIONS] --scrape-url <SCRAPE_URL> O

kaylen ✨ 2 Jul 3, 2022
Cross-platform, low level networking using the Rust programming language.

libpnet Linux ∪ OS X Build Status: Windows Build Status: Discussion and support: #libpnet on freenode / #rust-networking on irc.mozilla.org / #rust on

null 1.8k Jan 6, 2023
A cross-platform, user-space WireGuard port-forwarder that requires no system network configurations.

Cross-platform, user-space WireGuard port-forwarder that requires no system network configurations.

Aram Peres 629 Jan 4, 2023
A simple cross-platform remote file management tool to upload and download files over HTTP/S

A simple cross-platform remote file management tool to upload and download files over HTTP/S

sexnine 13 Dec 30, 2022
A high-performance, lightweight, and cross-platform QUIC library

TQUIC English | 中文 TQUIC is a high-performance, lightweight, and cross-platform library for the IETF QUIC protocol. Advantages High performance: TQUIC

Tencent 11 Oct 27, 2023
A metrics collection application for Linux machines. Created for MSCS 710 Project at Marist College.

Linux-Metrics-Collector A metrics collection application for Linux machines. Created for MSCS 710 Project at Marist College. Development Environment S

Christopher Ravosa 2 May 2, 2022
🚀 10x easier, 🚀 10x cheaper, 🚀 high performance, 🚀 petabyte scale - Elasticsearch/Splunk/Datadog alternative for 🚀 (logs, metrics, traces).

?? 10x easier, ?? 10x cheaper, ?? petabyte scale - Elasticsearch/Splunk/Datadog alternative for ?? (logs, metrics, traces). ZincObserve ZincObserve is

Zinc Labs Inc. 80 Feb 22, 2023
Druid Exporter plays a fundamental role as a receiver of metrics events coming from Druid clusters, adopting the HTTP format as a means of communication

Druid Exporter plays a fundamental role as a receiver of metrics events coming from Druid clusters, adopting the HTTP format as a means of communication. In addition to this capability, its primary function is to export these metrics to Prometheus, thus allowing the creation of meaningful graphs and visualizations.

Kiwfy 3 Sep 21, 2023