9 releases

0.3.1 Oct 5, 2024
0.3.0 Oct 4, 2024
0.2.2 Sep 5, 2024
0.2.1 May 29, 2024
0.1.3 Dec 12, 2023

#451 in HTTP server

Download history 1/week @ 2024-07-23 44/week @ 2024-07-30 2/week @ 2024-08-06 85/week @ 2024-08-13 4/week @ 2024-08-20 17/week @ 2024-08-27 216/week @ 2024-09-03 107/week @ 2024-09-10 141/week @ 2024-09-17 164/week @ 2024-09-24 405/week @ 2024-10-01 234/week @ 2024-10-08 32/week @ 2024-10-15 184/week @ 2024-10-22 19/week @ 2024-10-29 175/week @ 2024-11-05

426 downloads per month
Used in 2 crates

MIT license

130KB
911 lines

metrics-dashboard-rs

Crates.io Docs.rs CI

This crate provide simple auto-generate dashboard for metric-rs crate.

Screenshot

How to use

  • run cargo add metrics-dashboard
  • include into poem webserver like bellow:
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
}

License

Licensed under (LICENSE-MIT or http://opensource.org/licenses/MIT)

Contribution

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.

Dependencies

~18–48MB
~758K SLoC