at protocol indexer with flexible filtering, xrpc queries, and a cursor-backed event stream, built on fjall
at-protocol
atproto
indexer
rust
fjall
1use crate::api::AppState;
2use axum::{Json, extract::State, response::Result};
3use ordermap::OrderMap;
4use serde::Serialize;
5use std::sync::Arc;
6
7#[derive(Serialize)]
8pub struct StatsResponse {
9 pub counts: OrderMap<&'static str, u64>,
10}
11
12pub async fn get_stats(State(state): State<Arc<AppState>>) -> Result<Json<StatsResponse>> {
13 let db = &state.db;
14
15 let mut counts: OrderMap<&'static str, u64> = futures::future::join_all(
16 [
17 "repos",
18 "pending",
19 "resync",
20 "records",
21 "blocks",
22 "error_ratelimited",
23 "error_transport",
24 "error_generic",
25 ]
26 .into_iter()
27 .map(|name| async move { (name, db.get_count(name).await) }),
28 )
29 .await
30 .into_iter()
31 .collect();
32 // this should be accurate since we dont remove events
33 counts.insert("events", db.events.approximate_len() as u64);
34
35 Ok(Json(StatsResponse { counts }))
36}