Feature/stats endpoint (#631)
* Idea for stats endpoint * Introduced /stats endpoint replacing sending data to metrics server * Removed metrics client * Removed old metrics file * cargo fmt
This commit is contained in:
committed by
GitHub
parent
94a52aa2db
commit
82def1349f
@@ -1,4 +1,5 @@
|
||||
pub(crate) mod description;
|
||||
pub(crate) mod stats;
|
||||
pub(crate) mod verloc;
|
||||
|
||||
use rocket::Request;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
use crate::node::node_statistics::{NodeStats, NodeStatsSimple, NodeStatsWrapper};
|
||||
use rocket::State;
|
||||
use rocket_contrib::json::Json;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[serde(untagged)]
|
||||
pub(crate) enum NodeStatsResponse {
|
||||
Full(NodeStats),
|
||||
Simple(NodeStatsSimple),
|
||||
}
|
||||
|
||||
/// Returns a running stats of the node.
|
||||
#[get("/stats?<debug>")]
|
||||
pub(crate) async fn stats(
|
||||
stats: State<'_, NodeStatsWrapper>,
|
||||
debug: Option<bool>,
|
||||
) -> Json<NodeStatsResponse> {
|
||||
let snapshot_data = stats.clone_data().await;
|
||||
|
||||
// there's no point in returning the entire hashmap of sending destinations in regular mode
|
||||
if let Some(debug) = debug {
|
||||
if debug {
|
||||
return Json(NodeStatsResponse::Full(snapshot_data));
|
||||
}
|
||||
}
|
||||
|
||||
Json(NodeStatsResponse::Simple(snapshot_data.simplify()))
|
||||
}
|
||||
Reference in New Issue
Block a user