aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/stats.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-05 00:56:24 +0100
committertv <tv@krebsco.de>2026-11-05 00:56:24 +0100
commit4c6604db27f26998b72fd815b6bd1de5a3b08780 (patch)
treef95b90cadaeeaa7f085c352836a3017a33cf672b /src/api/stats.rs
parent85c6a9a2ddeaf23066ddfa3362693604a37526ae (diff)
own tree shape
Diffstat (limited to 'src/api/stats.rs')
-rw-r--r--src/api/stats.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/api/stats.rs b/src/api/stats.rs
index 5061ff7..3851ef7 100644
--- a/src/api/stats.rs
+++ b/src/api/stats.rs
@@ -187,6 +187,18 @@ struct TopologyView {
stable: usize,
neighbours: usize,
stable_neighbours: usize,
+ /// Our own writer's tree (`swarm::tree::own_shape`); absent while we aren't in the
+ /// member list's graph.
+ own_tree: Option<OwnTree>,
+}
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "camelCase")]
+struct OwnTree {
+ members: usize,
+ depth: u32,
+ mean_depth: f64,
+ off_tree: usize,
}
#[derive(Debug, Serialize)]
@@ -264,6 +276,18 @@ pub(crate) async fn get_stats(State(state): State<AppState>, headers: HeaderMap)
/// totals over the peers from their list (`peer_list`), read once for both.
pub(crate) async fn collect(state: &AppState, list: &PeerListResponse) -> StatsResponse {
let node = state.stats.snapshot();
+ let own_tree = crate::swarm::tree::own_shape(state)
+ .await
+ .map(|shape| OwnTree {
+ members: shape.members,
+ depth: shape.depth,
+ mean_depth: if shape.members == 0 {
+ 0.0
+ } else {
+ shape.hops as f64 / shape.members as f64
+ },
+ off_tree: shape.off,
+ });
let (heads, tier, remakes) = {
let replica = state.doc.read().await;
@@ -358,6 +382,7 @@ pub(crate) async fn collect(state: &AppState, list: &PeerListResponse) -> StatsR
stable: s.stable,
neighbours: s.neighbours,
stable_neighbours: s.stable_neighbours,
+ own_tree,
}),
},
stability: StabilityStats {