{"id":15018055,"url":"https://github.com/sd2k/rocket_prometheus","last_synced_at":"2025-04-09T21:12:57.310Z","repository":{"id":38362108,"uuid":"181523715","full_name":"sd2k/rocket_prometheus","owner":"sd2k","description":"Prometheus fairing and handler for Rocket","archived":false,"fork":false,"pushed_at":"2025-03-27T11:22:43.000Z","size":136,"stargazers_count":46,"open_issues_count":1,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T21:12:48.846Z","etag":null,"topics":["metrics","prometheus","rocket","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/sd2k.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","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}},"created_at":"2019-04-15T16:16:47.000Z","updated_at":"2025-03-27T11:22:41.000Z","dependencies_parsed_at":"2024-09-16T12:32:27.391Z","dependency_job_id":"e00fe703-8528-415d-9108-2b5991773d35","html_url":"https://github.com/sd2k/rocket_prometheus","commit_stats":{"total_commits":100,"total_committers":5,"mean_commits":20.0,"dds":0.35,"last_synced_commit":"8fc341b3473d734e115e51757f234faefe1c9a92"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sd2k%2Frocket_prometheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sd2k%2Frocket_prometheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sd2k%2Frocket_prometheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sd2k%2Frocket_prometheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sd2k","download_url":"https://codeload.github.com/sd2k/rocket_prometheus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111973,"owners_count":21049578,"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","prometheus","rocket","rust"],"created_at":"2024-09-24T19:51:22.549Z","updated_at":"2025-04-09T21:12:57.279Z","avatar_url":"https://github.com/sd2k.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rocket Prometheus\n\n[![Build Status](https://github.com/sd2k/rocket_prometheus/workflows/Rust/badge.svg)](https://github.com/sd2k/rocket_prometheus/actions)\n[![docs.rs](https://docs.rs/rocket_prometheus/badge.svg)](https://docs.rs/rocket_prometheus)\n[![crates.io](https://img.shields.io/crates/v/rocket_prometheus.svg)](https://crates.io/crates/rocket_prometheus)\n\n\nPrometheus instrumentation for Rocket applications.\n\n## Usage\n\nAdd this crate to your `Cargo.toml` alongside Rocket 0.5.0:\n\n```toml\n[dependencies]\nrocket = \"0.5.0\"\nrocket_prometheus = \"0.10.1\"\n```\n\nThen attach and mount a `PrometheusMetrics` instance to your Rocket app:\n\n```rust\nuse rocket_prometheus::PrometheusMetrics;\n\n#[rocket::launch]\nfn launch() -\u003e _ {\n    let prometheus = PrometheusMetrics::new();\n    rocket::build()\n        .attach(prometheus.clone())\n        .mount(\"/metrics\", prometheus)\n```\n\nThis will expose metrics like this at the /metrics endpoint of your application:\n\n```shell\n$ curl localhost:8000/metrics\n# HELP rocket_http_requests_duration_seconds HTTP request duration in seconds for all requests\n# TYPE rocket_http_requests_duration_seconds histogram\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"0.005\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"0.01\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"0.025\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"0.05\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"0.1\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"0.25\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"0.5\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"1\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"2.5\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"5\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"10\"} 2\nrocket_http_requests_duration_seconds_bucket{endpoint=\"/metrics\",method=\"GET\",status=\"200\",le=\"+Inf\"} 2\nrocket_http_requests_duration_seconds_sum{endpoint=\"/metrics\",method=\"GET\",status=\"200\"} 0.0011045669999999999\nrocket_http_requests_duration_seconds_count{endpoint=\"/metrics\",method=\"GET\",status=\"200\"} 2\n# HELP rocket_http_requests_total Total number of HTTP requests\n# TYPE rocket_http_requests_total counter\nrocket_http_requests_total{endpoint=\"/metrics\",method=\"GET\",status=\"200\"} 2\n```\n\n## Metrics\n\nBy default this crate tracks two metrics:\n\n- `rocket_http_requests_total` (labels: endpoint, method, status): the\n  total number of HTTP requests handled by Rocket.\n- `rocket_http_requests_duration_seconds` (labels: endpoint, method, status):\n  the request duration for all HTTP requests handled by Rocket.\n\nThe 'rocket' prefix of these metrics can be changed by setting the\n`ROCKET_PROMETHEUS_NAMESPACE` environment variable.\n\n### Custom Metrics\n\nFurther metrics can be tracked by registering them with the registry of the\nPrometheusMetrics instance:\n\n```rust\n#[macro_use]\nuse once_cell::sync::Lazy;\nuse rocket::{get, launch, routes};\nuse rocket_prometheus::{\n    prometheus::{opts, IntCounterVec},\n    PrometheusMetrics,\n};\n\nstatic NAME_COUNTER: Lazy\u003cIntCounterVec\u003e = Lazy::new(|| {\n    IntCounterVec::new(opts!(\"name_counter\", \"Count of names\"), \u0026[\"name\"])\n        .expect(\"Could not create NAME_COUNTER\")\n});\n\n#[get(\"/hello/\u003cname\u003e\")]\npub fn hello(name: \u0026str) -\u003e String {\n    NAME_COUNTER.with_label_values(\u0026[name]).inc();\n    format!(\"Hello, {}!\", name)\n}\n\n#[launch]\nfn launch() -\u003e _ {\n    let prometheus = PrometheusMetrics::new();\n    prometheus\n        .registry()\n        .register(Box::new(NAME_COUNTER.clone()))\n        .unwrap();\n    rocket::build()\n        .attach(prometheus.clone())\n        .mount(\"/\", routes![hello])\n        .mount(\"/metrics\", prometheus)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsd2k%2Frocket_prometheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsd2k%2Frocket_prometheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsd2k%2Frocket_prometheus/lists"}