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:
Jędrzej Stuczyński
2021-06-07 12:01:43 +01:00
committed by GitHub
parent 94a52aa2db
commit 82def1349f
22 changed files with 550 additions and 902 deletions
+1
View File
@@ -1,4 +1,5 @@
pub(crate) mod description;
pub(crate) mod stats;
pub(crate) mod verloc;
use rocket::Request;
+29
View File
@@ -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()))
}