simple status json and prometheus
This commit is contained in:
parent
501f2b0b24
commit
d98886db14
@ -340,7 +340,7 @@ impl Web3ProxyApp {
|
||||
Ok((app, handle))
|
||||
}
|
||||
|
||||
pub fn prometheus_metrics(&self) -> anyhow::Result<String> {
|
||||
pub fn prometheus_metrics(&self) -> String {
|
||||
let globals = HashMap::new();
|
||||
// TODO: what globals? should this be the hostname or what?
|
||||
// globals.insert("service", "web3_proxy");
|
||||
@ -356,9 +356,8 @@ impl Web3ProxyApp {
|
||||
backend_rpc: &self.open_request_handle_metrics,
|
||||
};
|
||||
|
||||
let serialized = serde_prometheus::to_string(&metrics, Some("web3_proxy"), globals)?;
|
||||
|
||||
Ok(serialized)
|
||||
serde_prometheus::to_string(&metrics, Some("web3_proxy"), globals)
|
||||
.expect("prometheus metrics should always serialize")
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
|
@ -1,5 +1,7 @@
|
||||
use crate::app::Web3ProxyApp;
|
||||
use axum::{http::StatusCode, response::IntoResponse, Extension};
|
||||
use axum::{http::StatusCode, response::IntoResponse, Extension, Json};
|
||||
use moka::future::ConcurrentCacheExt;
|
||||
use serde_json::json;
|
||||
use std::sync::Arc;
|
||||
use tracing::instrument;
|
||||
|
||||
@ -13,23 +15,29 @@ pub async fn health(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoRe
|
||||
}
|
||||
}
|
||||
|
||||
/// Prometheus metrics
|
||||
/// TODO: when done debugging, remove this and only allow access on a different port
|
||||
#[instrument(skip_all)]
|
||||
pub async fn prometheus(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
|
||||
app.prometheus_metrics()
|
||||
}
|
||||
|
||||
/// Very basic status page
|
||||
/// TODO: replace this with proper stats and monitoring
|
||||
#[instrument(skip_all)]
|
||||
pub async fn status(Extension(app): Extension<Arc<Web3ProxyApp>>) -> impl IntoResponse {
|
||||
// // TODO: what else should we include? uptime?
|
||||
// app.pending_transactions.sync();
|
||||
// app.user_cache.sync();
|
||||
// let body = json!({
|
||||
// "total_queries": app.total_queries.load(atomic::Ordering::Acquire),
|
||||
// "pending_transactions_count": app.pending_transactions.entry_count(),
|
||||
// "pending_transactions_size": app.pending_transactions.weighted_size(),
|
||||
// "user_cache_count": app.user_cache.entry_count(),
|
||||
// "user_cache_size": app.user_cache.weighted_size(),
|
||||
// "balanced_rpcs": app.balanced_rpcs,
|
||||
// "private_rpcs": app.private_rpcs,
|
||||
// });
|
||||
// Json(body)
|
||||
// TODO: only expose this on a different port
|
||||
app.prometheus_metrics().unwrap()
|
||||
// TODO: what else should we include? uptime?
|
||||
app.pending_transactions.sync();
|
||||
app.user_cache.sync();
|
||||
|
||||
let body = json!({
|
||||
"pending_transactions_count": app.pending_transactions.entry_count(),
|
||||
"pending_transactions_size": app.pending_transactions.weighted_size(),
|
||||
"user_cache_count": app.user_cache.entry_count(),
|
||||
"user_cache_size": app.user_cache.weighted_size(),
|
||||
"balanced_rpcs": app.balanced_rpcs,
|
||||
"private_rpcs": app.private_rpcs,
|
||||
});
|
||||
|
||||
Json(body)
|
||||
}
|
||||
|
@ -50,8 +50,9 @@ pub async fn serve(port: u16, proxy_app: Arc<Web3ProxyApp>) -> anyhow::Result<()
|
||||
.route("/u/:user_key", post(rpc_proxy_http::user_proxy_web3_rpc))
|
||||
.route("/u/:user_key", get(rpc_proxy_ws::user_websocket_handler))
|
||||
.route("/health", get(http::health))
|
||||
// TODO: we probably want to remove /status in favor of the separate prometheus thread
|
||||
.route("/status", get(http::status))
|
||||
// TODO: make this optional or remove it since it is available on another port
|
||||
.route("/prometheus", get(http::prometheus))
|
||||
.route("/login/:user_address", get(users::get_login))
|
||||
.route("/login/:user_address/:message_eip", get(users::get_login))
|
||||
.route("/login", post(users::post_login))
|
||||
|
@ -44,7 +44,7 @@ pub async fn serve(app: Arc<Web3ProxyApp>, port: u16) -> anyhow::Result<()> {
|
||||
|
||||
#[instrument(skip_all)]
|
||||
async fn root(Extension(app): Extension<Arc<Web3ProxyApp>>) -> Response {
|
||||
let serialized = app.prometheus_metrics().unwrap();
|
||||
let serialized = app.prometheus_metrics();
|
||||
|
||||
let mut r = serialized.into_response();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user