#dashboard #web-server #poem #zero-config #metrics-rs

metrics-dashboard

Zero-config dashboard with metrics-rs

5 releases

0.2.0 Jan 25, 2024
0.1.3 Dec 12, 2023
0.1.2 Dec 11, 2023
0.1.1 Dec 2, 2023
0.1.0 Dec 2, 2023

#377 in HTTP server

Download history 475/week @ 2023-12-30 362/week @ 2024-01-06 367/week @ 2024-01-13 548/week @ 2024-01-20 190/week @ 2024-01-27 147/week @ 2024-02-03 214/week @ 2024-02-10 243/week @ 2024-02-17 129/week @ 2024-02-24 54/week @ 2024-03-02 65/week @ 2024-03-09 47/week @ 2024-03-16 6/week @ 2024-03-23 56/week @ 2024-03-30 20/week @ 2024-04-06 30/week @ 2024-04-13

123 downloads per month
Used in atm0s-media-server

MIT license

130KB
921 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–50MB
~781K SLoC