Crates.io | err_metrics |
lib.rs | err_metrics |
version | 0.1.2 |
source | src |
created_at | 2024-11-01 10:51:04.122286 |
updated_at | 2024-11-21 01:10:05.795126 |
description | A Rust library and tool for tracking and exposing error metrics in Prometheus format, with asynchronous support using Tokio and an HTTP server powered by Warp. |
homepage | |
repository | |
max_upload_size | |
id | 1431659 |
size | 34,060 |
err_metrics
is a Rust library and command-line tool for tracking and exposing error metrics in Prometheus format. It uses asynchronous support from Tokio and serves metrics over HTTP using Warp, making it easy to integrate with observability platforms like Prometheus and Grafana.
Add err_metrics
to your Cargo.toml
:
[dependencies]
err_metrics = "0.1.0" # Replace with the correct version
Note: Make sure to use the latest version published on crates.io.
Here's a simple example to get you started:
use err_metrics::ErrorMetrics;
use tokio::main;
#[main]
async fn main() {
let metrics = ErrorMetrics::new();
// Simulate some errors
metrics.record_error("database_error", "db_service");
metrics.record_error("http_error", "web_service");
// Serve metrics on http://127.0.0.1:3030/metrics
println!("Serving metrics on http://127.0.0.1:3030/metrics");
metrics.serve_metrics().await;
}
bash
cargo run Visit http://127.0.0.1:3030/metrics to see the metrics.
Recording Errors You can record errors using the record_error method, specifying the error type and source: metrics.record_error("database_error", "db_service"); metrics.record_error("http_error", "web_service");
err_metrics exposes a /metrics endpoint that Prometheus can scrape. The endpoint is served using Warp on a configurable port (default: 3030).
To monitor your error metrics using Prometheus:
scrape_configs:
- job_name: 'err_metrics'
static_configs:
- targets: ['127.0.0.1:3030']
You can easily customize the HTTP server port and other settings by modifying the serve_metrics method or using environment variables (future feature).
This project is licensed under the MIT License. See the LICENSE file for details.
Prometheus: For providing a powerful metrics collection system. Tokio: For async runtime support. Warp: For the fast and easy-to-use HTTP server.
##Author bensatlantik