web3-proxy/web3_proxy/src/frontend/http.rs

34 lines
1.1 KiB
Rust
Raw Normal View History

2022-06-05 22:58:47 +03:00
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
use serde_json::json;
use std::sync::Arc;
2022-06-16 05:53:37 +03:00
use crate::app::Web3ProxyApp;
2022-06-29 21:22:53 +03:00
/// Health check page for load balancers to use
2022-07-07 06:22:09 +03:00
pub async fn health(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
2022-08-04 01:23:10 +03:00
if app.balanced_rpcs().synced() {
2022-06-29 21:22:53 +03:00
(StatusCode::OK, "OK")
} else {
(StatusCode::SERVICE_UNAVAILABLE, ":(")
}
}
2022-06-05 22:58:47 +03:00
/// Very basic status page
2022-08-05 22:22:23 +03:00
/// TODO: replace this with proper stats and monitoring
2022-07-07 06:22:09 +03:00
pub async fn status(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
// TODO: what else should we include? uptime? prometheus?
2022-08-04 01:23:10 +03:00
let balanced_rpcs = app.balanced_rpcs();
let private_rpcs = app.private_rpcs();
let num_active_requests = app.active_requests().len();
let num_pending_transactions = app.pending_transactions().len();
2022-06-05 22:58:47 +03:00
let body = json!({
"balanced_rpcs": balanced_rpcs,
"private_rpcs": private_rpcs,
"num_active_requests": num_active_requests,
"num_pending_transactions": num_pending_transactions,
2022-06-05 22:58:47 +03:00
});
(StatusCode::INTERNAL_SERVER_ERROR, Json(body))
}