Something went wrong. Try again.
very fast at protocol indexer with flexible filtering, xrpc queries, cursor-backed event stream, and more, built on fjall
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293use super::Hydrant;use miette::{IntoDiagnostic, Result};use std::collections::BTreeMap;
/// database statistics returned by [`Hydrant::stats`].#[derive(serde::Serialize)]pub struct StatsResponse { /// record counts per logical category (repos, records, events, error kinds, etc.) pub counts: BTreeMap<&'static str, u64>, /// on-disk size in bytes per keyspace pub sizes: BTreeMap<&'static str, u64>,}
impl Hydrant { /// return database counts and on-disk sizes for all keyspaces. /// /// counts include: `repos`, `pending`, `resync`, `records`, `blocks`, `events`, /// `error_ratelimited`, `error_transport`, `error_generic`. /// /// sizes are in bytes, reported per keyspace. pub async fn stats(&self) -> Result<StatsResponse> { let state = self.state.clone();
#[allow(unused_mut)] let mut count_keys = vec![ "repos", "error_ratelimited", "error_transport", "error_generic", ];
#[cfg(feature = "indexer")] { count_keys.push("pending"); count_keys.push("records"); count_keys.push("blocks"); count_keys.push("resync"); }
#[cfg_attr( not(any(feature = "indexer_stream", feature = "relay")), allow(unused_mut) )] let mut counts: BTreeMap<&'static str, u64> = futures::future::join_all(count_keys.into_iter().map(|name| { let state = state.clone(); async move { (name, state.db.get_count(name).await) } })) .await .into_iter() .collect();
#[cfg(feature = "indexer_stream")] counts.insert("events", state.db.stream.approximate_event_count() as u64);
#[cfg(feature = "relay")] counts.insert( "relay_events", state.db.relay.events.approximate_len() as u64, ); #[cfg(feature = "jetstream")] counts.insert( "jetstream_events", state.db.jetstream.events.approximate_len() as u64, );
#[cfg(feature = "indexer")] { // dictionary occupancy against its budget, so a run that hits the // guard and falls back to NSID text in keys is visible rather than // silent counts.insert("collections", state.db.indexer.collections.len() as u64); counts.insert( "collections_bytes", state.db.indexer.collections.used_bytes() as u64, ); }
let sizes = state .db .run(move |db| { Ok(db .all_keyspaces() .into_iter() .map(|(name, ks)| (name, ks.disk_space())) .collect::<BTreeMap<_, _>>()) }) .await?;
Ok(StatsResponse { counts, sizes }) }}