{"id":17710117,"url":"https://github.com/alexanderthaller/prometheus_exporter","last_synced_at":"2025-04-05T02:04:54.918Z","repository":{"id":38553997,"uuid":"167374614","full_name":"AlexanderThaller/prometheus_exporter","owner":"AlexanderThaller","description":"Helper libary to export prometheus metrics using tiny_http and rust-prometheus.","archived":false,"fork":false,"pushed_at":"2025-01-16T12:48:12.000Z","size":71,"stargazers_count":29,"open_issues_count":7,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T01:03:53.417Z","etag":null,"topics":["helper-libary","library","metrics","prometheus-crate","prometheus-exporter","prometheus-metrics","rust","rust-prometheus"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexanderThaller.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-24T13:46:55.000Z","updated_at":"2025-02-22T20:22:58.000Z","dependencies_parsed_at":"2023-02-09T11:01:27.870Z","dependency_job_id":null,"html_url":"https://github.com/AlexanderThaller/prometheus_exporter","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderThaller%2Fprometheus_exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderThaller%2Fprometheus_exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderThaller%2Fprometheus_exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexanderThaller%2Fprometheus_exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexanderThaller","download_url":"https://codeload.github.com/AlexanderThaller/prometheus_exporter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276163,"owners_count":20912288,"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":["helper-libary","library","metrics","prometheus-crate","prometheus-exporter","prometheus-metrics","rust","rust-prometheus"],"created_at":"2024-10-25T06:22:07.598Z","updated_at":"2025-04-05T02:04:54.893Z","avatar_url":"https://github.com/AlexanderThaller.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prometheus_exporter\n\n[![Build Status](https://github.com/AlexanderThaller/prometheus_exporter/workflows/Rust/badge.svg?branch=master)](https://github.com/AlexanderThaller/prometheus_exporter/actions?query=workflow%3ARust)\n[![crates.io](https://img.shields.io/crates/v/prometheus_exporter.svg)](https://crates.io/crates/prometheus_exporter)\n[![docs.rs](https://docs.rs/prometheus_exporter/badge.svg)](https://docs.rs/prometheus_exporter)\n\nHelper libary to export prometheus metrics using tiny-http. It's intended to\nhelp writing prometheus exporters without the need to setup and maintain a http\nwebserver. If the program also uses a http server for other purposes this\npackage is probably not the best way and\n[rust-prometheus](https://github.com/pingcap/rust-prometheus) should be used\ndirectly.\n\nIt uses [rust-prometheus](https://github.com/pingcap/rust-prometheus) for\ncollecting and rendering the prometheus metrics and\n[tiny-http](https://github.com/tiny-http/tiny-http) for exposing the metrics\nthrough http.\n\n**NOTICE:** You have to use the same prometheus crate version that is used by\nthis crate. This crate currently uses the metrics stored in the global registry.\nA different prometheus crate will register to a different global registry. This\nmeans that the macros used to register new metrics do not expose metrics to this\nexporter.\n\nThis crate re-exports the prometheus crate to make it easier to keep versions in\nsync (see examples). Currently this crate uses prometheus version `0.13`.\n\nFor information on how to migrate from an older crate version follow\n[MIGRATION](/MIGRATION.md).\n\n**NOTICE** Version `0.8.0` used a vulnerable version of `tiny_http` please update\nto version `0.8.1` or higher. See issue\n[#18](https://github.com/AlexanderThaller/prometheus_exporter/issues/18) for\nmore information.\n\n## Usage\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nprometheus_exporter = \"0.8\"\n```\n\nThe most basic way to use this crate is to run the following:\n```rust\nprometheus_exporter::start(\"0.0.0.0:9184\".parse().expect(\n\"failed to parse binding\",\n))\n.expect(\"failed to start prometheus exporter\");\n```\n\nThis will start the exporter and bind the http server to `0.0.0.0:9184`. After\nthat you can just update the metrics how you see fit. As long as those metrics\nare put into the global prometheus registry the changed metrics will be\nexported.\n\nAnother way to use the crate is like this:\n\n```rust\nlet exporter = prometheus_exporter::start(\"0.0.0.0:9184\".parse().expect(\n\"failed to parse binding\",\n))\n.expect(\"failed to start prometheus exporter\");\n\nlet guard = exporter.wait_request()\n```\n\nThis will block the current thread until a request has been received on the http\nserver. It also returns a guard which will make the http server wait until the\nguard is dropped. This is useful to always export consistent metrics as all of\nthe metrics can be updated before they get exported.\n\nSee the [documentation](https://docs.rs/prometheus_exporter) and the\n[examples](/examples) for more information on how to use this crate.\n\n## Basic Example\n\nYou will need the following in your Cargo.toml\n```rust\n[dependencies]\nprometheus_exporter = \"0.8\"\nenv_logger = \"0.9\"\nlog = \"0.4\"\nreqwest = { version = \"0.11\",features = [\"blocking\"] }\n```\n\nA very simple example looks like this (from\n[`examples/simple.rs`](/examples/simple.rs)):\n\n```rust\n// Will create an exporter with a single metric that does not change\n\nuse env_logger::{\n    Builder,\n    Env,\n};\nuse log::info;\nuse prometheus_exporter::prometheus::register_gauge;\nuse std::net::SocketAddr;\n\nfn main() {\n    // Setup logger with default level info so we can see the messages from\n    // prometheus_exporter.\n    Builder::from_env(Env::default().default_filter_or(\"info\")).init();\n\n    // Parse address used to bind exporter to.\n    let addr_raw = \"0.0.0.0:9184\";\n    let addr: SocketAddr = addr_raw.parse().expect(\"can not parse listen addr\");\n\n    // Create metric\n    let metric = register_gauge!(\"simple_the_answer\", \"to everything\")\n        .expect(\"can not create gauge simple_the_answer\");\n\n    metric.set(42.0);\n\n    // Start exporter\n    prometheus_exporter::start(addr).expect(\"can not start exporter\");\n\n    // Get metrics from exporter\n    let body = reqwest::blocking::get(\u0026format!(\"http://{}/metrics\", addr_raw))\n        .expect(\"can not get metrics from exporter\")\n        .text()\n        .expect(\"can not body text from request\");\n\n    info!(\"Exporter metrics:\\n{}\", body);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderthaller%2Fprometheus_exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexanderthaller%2Fprometheus_exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderthaller%2Fprometheus_exporter/lists"}