{"id":33922600,"url":"https://github.com/chainbound/prometric","last_synced_at":"2026-03-27T04:09:18.979Z","repository":{"id":321258100,"uuid":"1085146537","full_name":"chainbound/prometric","owner":"chainbound","description":"An attribute macro for generating and using embedded Prometheus metrics with an ergonomic API.","archived":false,"fork":false,"pushed_at":"2026-01-22T08:39:19.000Z","size":280,"stargazers_count":28,"open_issues_count":18,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-13T12:41:50.444Z","etag":null,"topics":["metrics","prometheus","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/prometric-derive","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chainbound.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-28T16:39:21.000Z","updated_at":"2026-02-24T19:14:59.000Z","dependencies_parsed_at":"2025-10-30T10:08:47.044Z","dependency_job_id":"f838210c-3112-4f43-9888-b44c71bc931a","html_url":"https://github.com/chainbound/prometric","commit_stats":null,"previous_names":["chainbound/prom-derive","chainbound/prometric"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/chainbound/prometric","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprometric","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprometric/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprometric/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprometric/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chainbound","download_url":"https://codeload.github.com/chainbound/prometric/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chainbound%2Fprometric/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31018555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T03:51:26.850Z","status":"ssl_error","status_checked_at":"2026-03-27T03:51:09.693Z","response_time":164,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","prometheus","rust"],"created_at":"2025-12-12T09:06:15.084Z","updated_at":"2026-03-27T04:09:18.974Z","avatar_url":"https://github.com/chainbound.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `prometric`\n\n[![Lints](https://github.com/chainbound/prometric/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/chainbound/prometric/actions/workflows/lint.yml)\n[![Tests](https://github.com/chainbound/prometric/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/chainbound/prometric/actions/workflows/test.yml)\n[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/chainbound/prometric)\n\nA library for ergonomically generating and using embedded Prometheus metrics in Rust.\n\nInspired by [metrics-derive](https://github.com/ithacaxyz/metrics-derive), but works directly with [prometheus](https://docs.rs/prometheus/latest/prometheus)\ninstead of [metrics](https://docs.rs/metrics/latest/metrics), and supports dynamic labels.\n\n| Crate              | crates.io                                                                                                       | docs.rs                                                                                    |\n| ------------------ | --------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |\n| `prometric`        | [![crates.io](https://img.shields.io/crates/v/prometric.svg)](https://crates.io/crates/prometric)               | [![docs.rs](https://docs.rs/prometric/badge.svg)](https://docs.rs/prometric)               |\n| `prometric-derive` | [![crates.io](https://img.shields.io/crates/v/prometric-derive.svg)](https://crates.io/crates/prometric-derive) | [![docs.rs](https://docs.rs/prometric-derive/badge.svg)](https://docs.rs/prometric-derive) |\n\n## Usage\n\n### Basic Usage\n\nSee [`basic_usage`](./prometric-derive/examples/basic_usage.rs) example for usage. Here's a reduced example usage:\n\n``` rust\n// The `scope` attribute is used to set the prefix for the metric names in this struct.\n#[metrics(scope = \"app\")]\nstruct AppMetrics {\n    /// The total number of HTTP requests.\n    #[metric(rename = \"http_requests_total\", labels = [\"method\", \"path\"])]\n    http_requests: Counter,\n}\n\n// Build the metrics struct with static labels, which will initialize and register the metrics\n// with the default registry. A custom registry can be used by passing it to the builder\n// using `with_registry`.\nlet metrics =\n    AppMetrics::builder().with_label(\"host\", \"localhost\").with_label(\"port\", \"8080\").build();\n\n// Metric fields each get an accessor method generated, which can be used to interact with the\n// metric. The arguments to the accessor method are the labels for the metric.\nmetrics.http_requests(\"GET\", \"/\").inc();\n```\n\n#### Sample Output\n\nTODO: document how to obtain sample output\n\n```text\n# HELP app_account_balance The balance of the account, in dollars. Uses a floating point number.\n# TYPE app_account_balance gauge\napp_account_balance{account_id=\"1234567890\",host=\"localhost\",port=\"8080\"} -12.2\n\n# HELP app_current_active_users The current number of active users.\n# TYPE app_current_active_users gauge\napp_current_active_users{host=\"localhost\",port=\"8080\",service=\"service-1\"} 20\n\n# HELP app_errors The total number of errors.\n# TYPE app_errors counter\napp_errors{host=\"localhost\",port=\"8080\"} 1\n\n# HELP app_http_requests_duration The duration of HTTP requests.\n# TYPE app_http_requests_duration histogram\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"0.005\"} 0\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"0.01\"} 0\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"0.025\"} 0\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"0.05\"} 0\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"0.1\"} 0\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"0.25\"} 0\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"0.5\"} 0\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"1\"} 1\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"2.5\"} 1\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"5\"} 1\napp_http_requests_duration_bucket{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\",le=\"+Inf\"} 1\napp_http_requests_duration_sum{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\"} 1\napp_http_requests_duration_count{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\"} 1\n\n# HELP app_http_requests_total The total number of HTTP requests.\n# TYPE app_http_requests_total counter\napp_http_requests_total{host=\"localhost\",method=\"GET\",path=\"/\",port=\"8080\"} 2\napp_http_requests_total{host=\"localhost\",method=\"POST\",path=\"/\",port=\"8080\"} 2\n```\n\n### Static Metrics\n\nYou can also generate a static `LazyLock` instance by using the `static` attribute. When enabled, the builder methods and `Default` implementation are made private, ensuring the only way to access the metrics is through the static instance:\n\nSee [`static_metrics`](./prometric-derive/examples/static_metrics.rs) example for usage.\n\n### Exporting Metrics\n\nAn HTTP exporter is provided by [`prometric::exporter::ExporterBuilder`].\n\nSee [`exporter`](./prometric-derive/examples/exporter.rs) example for usage.\n\n### Process Metrics\n\nWhen the `process` feature is enabled, the `ProcessCollector` can be used to collect metrics about the current process.\n\n```rust\nuse prometric::process::ProcessCollector;\n\nlet collector = ProcessCollector::default();\ncollector.collect();\n```\n\n#### Sample Output\n\n```text\n# HELP process_collection_duration_seconds The duration of the associated collection routine in seconds.\n# TYPE process_collection_duration_seconds gauge\nprocess_collection_duration_seconds 0.016130356\n# HELP process_cpu_usage The CPU usage of the process as a percentage.\n# TYPE process_cpu_usage gauge\nprocess_cpu_usage 6.2536187171936035\n# HELP process_disk_written_bytes_total The total written bytes to disk by the process.\n# TYPE process_disk_written_bytes_total gauge\nprocess_disk_written_bytes_total 0\n# HELP process_max_fds The maximum number of open file descriptors of the process.\n# TYPE process_max_fds gauge\nprocess_max_fds 1048576\n# HELP process_open_fds The number of open file descriptors of the process.\n# TYPE process_open_fds gauge\nprocess_open_fds 639\n# HELP process_resident_memory_bytes The resident memory of the process in bytes. (RSS)\n# TYPE process_resident_memory_bytes gauge\nprocess_resident_memory_bytes 4702208\n# HELP process_resident_memory_usage The resident memory usage of the process as a percentage of the total memory available.\n# TYPE process_resident_memory_usage gauge\nprocess_resident_memory_usage 0.00007072418111501723\n# HELP process_start_time_seconds The start time of the process in UNIX seconds.\n# TYPE process_start_time_seconds gauge\nprocess_start_time_seconds 1763056609\n# HELP process_thread_usage Per-thread CPU usage as a percentage of the process's CPU usage (Linux only).\n# TYPE process_thread_usage gauge\nprocess_thread_usage{name=\"process::tests:\",pid=\"980490\"} 0.9259260296821594\nprocess_thread_usage{name=\"test-thread-1\",pid=\"980491\"} 0\nprocess_thread_usage{name=\"test-thread-2\",pid=\"980492\"} 94.44445037841797\n# HELP process_threads The number of OS threads used by the process (Linux only).\n# TYPE process_threads gauge\nprocess_threads 3\n# HELP system_cpu_cores The number of logical CPU cores available in the system.\n# TYPE system_cpu_cores gauge\nsystem_cpu_cores 16\n# HELP system_cpu_usage System-wide CPU usage percentage.\n# TYPE system_cpu_usage gauge\nsystem_cpu_usage 6.7168498039245605\n# HELP system_max_cpu_frequency The maximum CPU frequency of all cores in MHz.\n# TYPE system_max_cpu_frequency gauge\nsystem_max_cpu_frequency 5339\n# HELP system_memory_usage System-wide memory usage percentage.\n# TYPE system_memory_usage gauge\nsystem_memory_usage 6.398677876736871\n# HELP system_min_cpu_frequency The minimum CPU frequency of all cores in MHz.\n# TYPE system_min_cpu_frequency gauge\nsystem_min_cpu_frequency 545\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainbound%2Fprometric","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchainbound%2Fprometric","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchainbound%2Fprometric/lists"}