Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added prometheus endpoint #134

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions webserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bigdecimal.workspace = true
shared.workspace = true
strum.workspace = true
strum_macros.workspace = true
axum-prometheus = "0.7.0"

[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "git", "gitcl"] }
5 changes: 5 additions & 0 deletions webserver/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use axum::http::{HeaderValue, StatusCode};
use axum::response::IntoResponse;
use axum::routing::get;
use axum::{BoxError, Json, Router};
use axum_prometheus::PrometheusMetricLayer;
use lazy_static::lazy_static;
use namada_sdk::tendermint_rpc::HttpClient;
use serde_json::json;
Expand Down Expand Up @@ -37,6 +38,8 @@ impl ApplicationServer {
let db_url = config.database_url.clone();
let cache_url = config.cache_url.clone();

let (prometheus_layer, metric_handle) = PrometheusMetricLayer::pair();

let app_state = AppState::new(db_url, cache_url);
let client = HttpClient::new(config.tendermint_url.as_str()).unwrap();

Expand Down Expand Up @@ -131,6 +134,7 @@ impl ApplicationServer {
)
// Server sent events endpoints
.route("/chain/status", get(chain_handlers::chain_status))
.route("/metrics", get(|| async move { metric_handle.render() }))
.with_state(common_state)
};

Expand All @@ -148,6 +152,7 @@ impl ApplicationServer {
.layer(
ServiceBuilder::new()
.layer(TraceLayer::new_for_http())
.layer(prometheus_layer)
.layer(HandleErrorLayer::new(Self::handle_timeout_error))
.timeout(Duration::from_secs(*HTTP_TIMEOUT))
.layer(cors)
Expand Down
Loading