Crates.io | metrics-dashboard |
lib.rs | metrics-dashboard |
version | 0.3.3 |
source | src |
created_at | 2023-12-02 14:07:40.366172 |
updated_at | 2024-11-26 17:04:25.848471 |
description | Zero-config dashboard with metrics-rs |
homepage | |
repository | https://github.com/giangndm/metrics-dashboard-rs |
max_upload_size | |
id | 1056149 |
size | 272,123 |
This crate provide simple auto-generate dashboard for metric-rs crate.
cargo add metrics-dashboard
use std::time::Duration;
use metrics_dashboard::build_dashboard_route;
use metrics::{describe_counter, increment_counter};
use poem::{
get, handler, listener::TcpListener, middleware::Tracing, web::Path, EndpointExt, Route, Server,
};
#[handler]
fn hello(Path(name): Path<String>) -> String {
format!("hello: {name}")
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "poem=debug");
}
tracing_subscriber::fmt::init();
let dashboard_options = DashboardOptions {
custom_charts: vec![
ChartType::Line {
metrics: vec![
"demo_live_time".to_string(),
"demo_live_time_max".to_string(),
],
desc: Some("Demo metric line".to_string()),
}
],
include_default: true,
};
let app = Route::new()
.at("/hello/:name", get(hello))
.nest("/dashboard/", build_dashboard_route())
.with(Tracing);
tokio::spawn(async move {
describe_counter!("demo_metric1", "Demo metric1");
loop {
tokio::time::sleep(Duration::from_secs(1)).await;
increment_counter!("demo_metric1");
}
});
tokio::spawn(async move {
describe_counter!("demo_metric2", "Demo metric2");
loop {
tokio::time::sleep(Duration::from_secs(1)).await;
increment_counter!("demo_metric2");
}
});
Server::new(TcpListener::bind("0.0.0.0:3000"))
.name("hello-world")
.run(app)
.await
}
Licensed under (LICENSE-MIT or http://opensource.org/licenses/MIT)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MIT license, without any additional terms or conditions.
See CONTRIBUTING.md.