### Register Process Metrics in Rust Source: https://github.com/koushiro/fastmetrics/blob/main/fastmetrics-process/README.md Demonstrates how to initialize ProcessMetrics and register them with a fastmetrics Registry. This setup is necessary to expose process-related metrics. ```rust 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(()) } ``` -------------------------------- ### Basic Usage of FastMetrics with Derive Macros Source: https://github.com/koushiro/fastmetrics/blob/main/README.md Demonstrates how to define, register, and update metrics using derive macros. Includes examples for simple counters and counter families, and exporting metrics in text format. Ensure the 'derive' feature is enabled for macro usage. ```rust use fastmetrics::{ derive::*, error::Result, format::text::{self, TextProfile}, metrics::{counter::Counter, family::Family}, registry::*, }; // Define label types // Need to enable `derive` feature to use `#[derive(LabelSet)]` // or `#[derive(EncodeLabelSet, LabelSetSchema)]` #[derive(Clone, Eq, PartialEq, Hash, LabelSet)] struct Labels { method: Method, status: u16, } // Need to enable `derive` feature to use `#[derive(EncodeLabelValue)]` #[derive(Clone, Eq, PartialEq, Hash, EncodeLabelValue)] enum Method { Get, Put, } // Need to enable `derive` feature to use `#[derive(Register)]` #[derive(Default, Register)] struct Metrics { /// Total requests processed requests: Counter, /// Total HTTP requests http_requests: Family, } fn main() -> Result<()> { // Create a registry with a namespace and some constant labels let mut registry = Registry::builder() .with_namespace("myapp") .with_const_labels([("env", "prod")]) .build()?; // Register metrics let metrics = Metrics::default(); metrics.register(&mut registry)?; // Update the simple counter metrics.requests.inc(); assert_eq!(metrics.requests.total(), 1); // Update the counter family let labels = Labels { method: Method::Get, status: 200 }; metrics.http_requests.with_or_new(&labels, |req| req.inc()); assert_eq!(metrics.http_requests.with(&labels, |req| req.total()), Some(1)); // Export metrics in text format let mut output = String::new(); text::encode(&mut output, ®istry, TextProfile::default())?; println!("{}", output); Ok(()) } ``` -------------------------------- ### Metric Benchmark Results Source: https://github.com/koushiro/fastmetrics/blob/main/benchmarks/README.md Example output from the metric benchmarks, showing performance (time in ns or ps) for incrementing and setting operations on different metric types and libraries. ```text counter(u64)::inc/metrics time: [7.1701 ns 7.1929 ns 7.2269 ns] counter(u64)::inc/measured time: [2.1799 ns 2.2218 ns 2.3099 ns] counter(u64)::inc/prometheus time: [2.2067 ns 2.2344 ns 2.2827 ns] counter(u64)::inc/prometheus_client time: [2.1296 ns 2.1533 ns 2.1980 ns] counter(u64)::inc/fastmetrics time: [2.2060 ns 2.2085 ns 2.2112 ns] counter(u64)::saturating_inc/fastmetrics time: [2.4990 ns 2.5028 ns 2.5066 ns] counter(f64)::inc/metrics time: [7.1656 ns 7.1736 ns 7.1822 ns] counter(f64)::inc/prometheus time: [10.758 ns 10.961 ns 11.381 ns] counter(f64)::inc/prometheus_client time: [5.6103 ns 5.6167 ns 5.6232 ns] counter(f64)::inc/fastmetrics time: [5.6669 ns 5.7429 ns 5.8925 ns] gauge(i64)::set/metrics time: [6.4548 ns 6.5041 ns 6.5539 ns] gauge(i64)::set/measured time: [987.40 ps 992.07 ps 997.34 ps] gauge(i64)::set/prometheus time: [582.40 ps 586.00 ps 589.92 ps] gauge(i64)::set/prometheus_client time: [1.6853 ns 1.6986 ns 1.7138 ns] gauge(i64)::set/fastmetrics time: [582.01 ps 585.49 ps 589.64 ps] gauge(i64)::inc_by/metrics time: [6.8636 ns 6.9125 ns 7.0066 ns] gauge(i64)::inc_by/measured time: [2.1678 ns 2.1752 ns 2.1825 ns] gauge(i64)::inc_by/prometheus time: [2.1674 ns 2.1747 ns 2.1821 ns] gauge(i64)::inc_by/prometheus_client time: [2.2545 ns 2.2651 ns 2.2755 ns] gauge(i64)::inc_by/fastmetrics time: [2.1702 ns 2.1917 ns 2.2227 ns] gauge(i64)::saturating_inc_by/fastmetrics time: [3.1359 ns 3.1726 ns 3.2193 ns] gauge(i64)::dec_by/metrics time: [6.8622 ns 6.8784 ns 6.8966 ns] gauge(i64)::dec_by/measured time: [2.1534 ns 2.1618 ns 2.1719 ns] gauge(i64)::dec_by/prometheus time: [2.1767 ns 2.1990 ns 2.2294 ns] gauge(i64)::dec_by/prometheus_client time: [2.2337 ns 2.2838 ns 2.3661 ns] gauge(i64)::dec_by/fastmetrics time: [2.1700 ns 2.2096 ns 2.2679 ns] gauge(i64)::saturating_dec_by/fastmetrics time: [3.1386 ns 3.1577 ns 3.1844 ns] gauge(f64)::set/metrics time: [6.4696 ns 6.5152 ns 6.5631 ns] gauge(f64)::set/measured time: [1.0005 ns 1.0271 ns 1.0726 ns] gauge(f64)::set/prometheus time: [590.97 ps 604.58 ps 629.78 ps] gauge(f64)::set/prometheus_client time: [1.6941 ns 1.7136 ns 1.7357 ns] gauge(f64)::set/fastmetrics time: [586.80 ps 609.50 ps 658.87 ps] gauge(f64)::inc_by/metrics time: [6.8960 ns 6.9484 ns 7.0249 ns] gauge(f64)::inc_by/measured time: [10.818 ns 10.918 ns 11.098 ns] gauge(f64)::inc_by/prometheus time: [10.888 ns 10.981 ns 11.108 ns] gauge(f64)::inc_by/prometheus_client time: [5.8338 ns 5.8601 ns 5.8900 ns] gauge(f64)::inc_by/fastmetrics time: [5.7928 ns 5.8059 ns 5.8189 ns] gauge(f64)::dec_by/metrics time: [6.9126 ns 6.9316 ns 6.9507 ns] gauge(f64)::dec_by/measured time: [10.855 ns 10.890 ns 10.931 ns] gauge(f64)::dec_by/prometheus time: [10.851 ns 10.880 ns 10.909 ns] gauge(f64)::dec_by/prometheus_client time: [5.7687 ns 5.8194 ns 5.9032 ns] gauge(f64)::dec_by/fastmetrics time: [5.8120 ns 5.8299 ns 5.8484 ns] histogram::observe/metrics time: [10.552 ns 10.644 ns 10.751 ns] histogram::observe/measured time: [11.623 ns 11.656 ns 11.691 ns] histogram::observe/prometheus time: [10.928 ns 10.968 ns 11.013 ns] histogram::observe/prometheus_client time: [8.9747 ns 9.0023 ns 9.0369 ns] histogram::observe/fastmetrics time: [5.7546 ns 5.7678 ns 5.7813 ns] ``` -------------------------------- ### Run Protobuf Benchmarks Source: https://github.com/koushiro/fastmetrics/blob/main/benchmarks/README.md Execute the protobuf benchmark suite using Cargo. The --quiet flag suppresses benchmark output. ```bash cargo bench --bench protobuf -- --quiet ``` -------------------------------- ### Run Metric Benchmarks Source: https://github.com/koushiro/fastmetrics/blob/main/benchmarks/README.md Execute the metric benchmarks using Cargo. The `--quiet` flag reduces output verbosity. Alternatively, use the `just bench metric` command if available. ```bash cargo bench --bench metric -- --quiet # Or `just bench metric` ``` -------------------------------- ### Run Metric Family Benchmarks Source: https://github.com/koushiro/fastmetrics/blob/main/benchmarks/README.md Execute the metric family benchmarks using Cargo. The `--quiet` flag reduces output verbosity. ```bash cargo bench --bench family -- --quiet ``` -------------------------------- ### Run Text Encoding Benchmark Source: https://github.com/koushiro/fastmetrics/blob/main/benchmarks/README.md This command executes the text encoding benchmark with quiet output. Ensure you have the 'text' benchmark enabled in your Cargo.toml. ```bash cargo bench --bench text -- --quiet ``` -------------------------------- ### Benchmark Output for Metrics Families Source: https://github.com/koushiro/fastmetrics/blob/main/benchmarks/README.md This output shows the performance of different metrics families across various libraries. It highlights the time taken for each family with different label configurations. ```text family with empty labels/metrics_cached time: [12.247 ns 12.294 ns 12.344 ns] family with empty labels/metrics_dynamic time: [84.531 ns 84.784 ns 85.054 ns] family with empty labels/measured time: [12.758 ns 12.797 ns 12.843 ns] family with empty labels/prometheus time: [24.863 ns 24.942 ns 25.046 ns] family with empty labels/prometheus_client time: [27.119 ns 27.181 ns 27.247 ns] family with empty labels/fastmetrics_cached time: [5.8060 ns 5.8214 ns 5.8389 ns] family with empty labels/fastmetrics_dynamic time: [17.144 ns 17.184 ns 17.227 ns] family with custom labels/metrics_cached time: [12.474 ns 12.551 ns 12.640 ns] family with custom labels/metrics_dynamic time: [158.01 ns 158.35 ns 158.72 ns] family with custom labels/measured time: [15.481 ns 15.528 ns 15.581 ns] family with custom labels/prometheus time: [25.950 ns 26.034 ns 26.133 ns] family with custom labels/prometheus_client time: [39.168 ns 39.287 ns 39.416 ns] family with custom labels/fastmetrics_cached time: [6.2012 ns 6.2307 ns 6.2638 ns] family with custom labels/fastmetrics_dynamic time: [20.316 ns 20.406 ns 20.506 ns] family with [(&'static str, &'static str)] labels/prometheus_client time: [67.111 ns 67.294 ns 67.484 ns] family with [(&'static str, &'static str)] labels/fastmetrics time: [50.827 ns 50.924 ns 51.027 ns] family with Vec<(&'static str, &'static str)> labels/prometheus_client time: [89.712 ns 89.958 ns 90.188 ns] family with Vec<(&'static str, &'static str)> labels/fastmetrics time: [65.653 ns 65.816 ns 65.991 ns] family with Vec<(String, String)> labels/prometheus_client time: [106.18 ns 106.57 ns 107.05 ns] family with Vec<(String, String)> labels/fastmetrics time: [82.871 ns 83.151 ns 83.447 ns] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.