use std::sync::atomic::Ordering::Relaxed;
use kevy_store::Store;
use crate::state::{ObsState, ShardCtx};
pub(crate) fn publish_gauges(shard: &ShardCtx, store: &Store) {
let (cmds, conns) = shard.counters();
shard.with_stats_slot(|s| {
s.used_memory.store(store.used_memory(), Relaxed);
s.used_memory_peak.store(store.used_memory_peak(), Relaxed);
s.keys.store(store.dbsize() as u64, Relaxed);
s.expires.store(store.expires_count() as u64, Relaxed);
s.expired_keys.store(store.expired_keys_total(), Relaxed);
s.evicted_keys.store(store.evictions_total(), Relaxed);
s.commands_processed.store(cmds, Relaxed);
s.connections_received.store(conns, Relaxed);
s.tier.enabled.store(u64::from(store.tier_enabled()), Relaxed);
if store.tier_enabled() {
let ts = store.tier_stats();
s.tier.budget.store(ts.budget, Relaxed);
s.tier.effective_target.store(ts.effective_target, Relaxed);
s.tier.reserved_bytes.store(ts.reserved_bytes, Relaxed);
s.tier.stub_bytes.store(ts.stub_bytes, Relaxed);
s.tier.cold_keys.store(ts.cold_keys, Relaxed);
s.tier.cold_bytes.store(ts.cold_bytes, Relaxed);
s.tier.demotions_total.store(ts.demotions_total, Relaxed);
s.tier.promotions_total.store(ts.promotions_total, Relaxed);
s.tier.peek_preads_total.store(ts.peek_preads_total, Relaxed);
s.tier.batch_submissions_total.store(ts.batch_submissions_total, Relaxed);
s.tier.vlog_files.store(ts.vlog_files, Relaxed);
s.tier.vlog_bytes.store(ts.vlog_bytes, Relaxed);
s.tier.vlog_live_bytes.store(ts.vlog_live_bytes, Relaxed);
s.tier.vlog_epoch.store(ts.vlog_epoch, Relaxed);
}
publish_alloc_gauges(s);
});
}
#[cfg(feature = "kevy-alloc")]
fn publish_alloc_gauges(s: &crate::state::ShardStats) {
let Some(a) = kevy_alloc::thread_stats().filter(|a| a.mapped > 0) else { return };
s.alloc.mapped.store(a.mapped, Relaxed);
s.alloc.live.store(a.live, Relaxed);
s.alloc.rounding.store(a.rounding, Relaxed);
s.alloc.cache.store(a.cache, Relaxed);
s.alloc.span_free.store(a.span_free, Relaxed);
s.alloc.returned.store(a.returned, Relaxed);
s.alloc.virgin.store(a.virgin, Relaxed);
s.alloc.hysteresis.store(a.hysteresis, Relaxed);
s.alloc.segment_overhead.store(a.segment_overhead, Relaxed);
s.alloc.large_count.store(a.large_count, Relaxed);
s.alloc.spans_assigned.store(a.spans_assigned, Relaxed);
s.alloc.reporting.store(1, Relaxed);
}
#[cfg(not(feature = "kevy-alloc"))]
fn publish_alloc_gauges(_s: &crate::state::ShardStats) {}
pub(crate) fn sample_ops_if_lead(shard: &ShardCtx, obs: &ObsState) {
if !shard.is_lead_shard() {
return;
}
obs.push_ops_sample(obs.aggregate().commands_processed);
}