{"id":27938392,"url":"https://github.com/koushiro/fastmetrics","last_synced_at":"2025-05-07T08:47:54.897Z","repository":{"id":288240752,"uuid":"904055978","full_name":"koushiro/fastmetrics","owner":"koushiro","description":"OpenMetrics client library for Rust","archived":false,"fork":false,"pushed_at":"2025-04-21T14:57:39.000Z","size":238,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T09:11:23.287Z","etag":null,"topics":["metrics","openmetrics","prometheus","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koushiro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-16T07:04:37.000Z","updated_at":"2025-04-21T14:57:41.000Z","dependencies_parsed_at":"2025-04-20T06:00:30.657Z","dependency_job_id":null,"html_url":"https://github.com/koushiro/fastmetrics","commit_stats":null,"previous_names":["koushiro/fastmetrics"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koushiro%2Ffastmetrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koushiro%2Ffastmetrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koushiro%2Ffastmetrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koushiro%2Ffastmetrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koushiro","download_url":"https://codeload.github.com/koushiro/fastmetrics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252846822,"owners_count":21813434,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["metrics","openmetrics","prometheus","rust"],"created_at":"2025-05-07T08:47:54.183Z","updated_at":"2025-05-07T08:47:54.883Z","avatar_url":"https://github.com/koushiro.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastmetrics\n\n[![CI Status](https://github.com/koushiro/fastmetrics/actions/workflows/ci.yml/badge.svg)](https://github.com/koushiro/fastmetrics/actions)\n[![Crates.io](https://img.shields.io/crates/v/fastmetrics)](https://crates.io/crates/fastmetrics)\n[![Documentation](https://img.shields.io/docsrs/fastmetrics)](https://docs.rs/fastmetrics)\n[![MSRV 1.75.0](https://img.shields.io/badge/MSRV-1.75.0-green?logo=rust)](https://www.whatrustisit.com)\n[![License](https://img.shields.io/crates/l/fastmetrics)](LICENSE)\n\nA pure-Rust implementation of the [OpenMetrics] specification for transmitting cloud-native metrics at scale,\nand it's compatible with Prometheus.\n\n[OpenMetrics]: https://github.com/prometheus/OpenMetrics/blob/main/specification/OpenMetrics.md\n\n## Features\n\n- Full support for [OpenMetrics] specification\n- Fast encoding in both text and protobuf exposition format\n- Customizable metric types (currently a set of commonly used metric types are provided)\n- Hierarchical metric organization with namespaces and subsystems\n- Support for variable and constant labels\n- Derive macros to simplify code (e.g., like label handling, stateset value handling, etc.)\n\n## Usage\n\n```rust\nuse fastmetrics::{\n    encoder::{EncodeLabelSet, EncodeLabelValue},\n    format::text,\n    metrics::{counter::Counter, family::Family},\n    registry::Registry,\n};\n\n// Define label types\n// Need to enable `derive` feature to use `#[derive(EncodeLabelSet)]`\n#[derive(Clone, Eq, PartialEq, Hash, EncodeLabelSet)]\nstruct Labels {\n    method: Method,\n    status: u32,\n}\n\n// Need to enable `derive` feature to use `#[derive(EncodeLabelValue)]`\n#[derive(Clone, Eq, PartialEq, Hash, EncodeLabelValue)]\nenum Method {\n    Get,\n    Put,\n}\n\nfn main() -\u003e Box\u003cdyn std::error::Error\u003e {\n    // Create a registry with a namespace and some constant labels\n    let mut registry = Registry::builder()\n        .with_namespace(\"myapp\")\n        .with_const_labels([(\"env\", \"prod\")])\n        .build();\n\n    // Register a simple counter\n    let requests = \u003cCounter\u003e::default();\n    registry.register(\"requests\", \"Total requests processed\", requests.clone())?;\n\n    // Register a counter metric family for tracking requests with labels\n    let http_requests = Family::\u003cLabels, Counter\u003e::default();\n    registry.register(\n        \"http_requests\",\n        \"Total HTTP requests\",\n        http_requests.clone()\n    )?;\n\n    // Update the simple counter\n    requests.inc();\n    assert_eq!(requests.total(), 1);\n\n    // Update the counter family\n    let labels = Labels { method: Method::Get, status: 200 };\n    http_requests.with_or_new(\u0026labels, |req| req.inc());\n    assert_eq!(http_requests.with(\u0026labels, |req| req.total()), Some(1));\n\n    // Export metrics in text format\n    let mut output = String::new();\n    text::encode(\u0026mut output, \u0026registry)?;\n    println!(\"{}\", output);\n\n    Ok(())\n}\n```\n\nSee [documentation](https://docs.rs/fastmetrics) and [examples](./examples) for more details.\n\n## Performance\n\nCompared with the existing rust client libraries, its text encoding is about 20%~30% faster than the fastest rust library (prometheus-client),\nwhile its Protobuf encoding is on par with the fastest rust library (prometheus).\n\nSee [benchmarks](./benchmarks/README.md) for more details\n\n## Acknowledgment\n\nI drew a lot of inspiration from the following libraries, retaining the designs I thought were good and experimenting with some different ones.\n\n- [prometheus/client_golang](https://github.com/prometheus/client_golang): Official prometheus client library for Golang applications.\n- [prometheus/client_rust](https://github.com/prometheus/client_rust): Official prometheus client library for Rust applications.\n- [tikv/rust-prometheus](https://github.com/tikv/rust-prometheus): Another prometheus instrumentation library for Rust applications.\n\n## License\n\nThis project is licensed under the Apache License, Version 2.0 - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoushiro%2Ffastmetrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoushiro%2Ffastmetrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoushiro%2Ffastmetrics/lists"}