#![cfg_attr(not(any(feature = "stats", feature = "http")), allow(dead_code))]
#[cfg(any(feature = "stats", feature = "http"))]
pub mod dynamic;
#[cfg(any(feature = "stats", feature = "http"))]
pub mod histograms;
#[cfg(any(feature = "stats", feature = "http"))]
pub mod metrics;
#[cfg(any(feature = "stats", feature = "http"))]
pub mod stats;
#[cfg(feature = "http")]
pub mod http;
#[cfg(any(feature = "stats", feature = "http"))]
pub use dynamic::{DynHistogram, DynOp, register_counter, register_gauge, register_histogram};
#[cfg(any(feature = "stats", feature = "http"))]
pub use metrics::MAX_SHARDS;
#[repr(usize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Op {
Get = 0,
Set = 1,
Del = 2,
VSet = 3,
VSearch = 4,
VDel = 5,
Ping = 6,
}
impl Op {
pub const COUNT: usize = 7;
pub const ALL: [Op; Self::COUNT] = [
Op::Get,
Op::Set,
Op::Del,
Op::VSet,
Op::VSearch,
Op::VDel,
Op::Ping,
];
#[inline]
pub const fn name(self) -> &'static str {
match self {
Op::Get => "get",
Op::Set => "set",
Op::Del => "del",
Op::VSet => "vset",
Op::VSearch => "vsearch",
Op::VDel => "vdel",
Op::Ping => "ping",
}
}
}
#[inline(always)]
pub fn record_op(op: Op, shard_id: u16, duration: core::time::Duration) {
#[cfg(any(feature = "stats", feature = "http"))]
{
metrics::tick_op(op, shard_id);
histograms::observe_us(op, duration.as_micros() as u64);
}
#[cfg(not(any(feature = "stats", feature = "http")))]
{
let _ = (op, shard_id, duration);
}
}
#[inline(always)]
pub fn set_gauge(g: Gauge, value: u64) {
#[cfg(any(feature = "stats", feature = "http"))]
{
metrics::set_gauge(g, value);
}
#[cfg(not(any(feature = "stats", feature = "http")))]
{
let _ = (g, value);
}
}
#[inline(always)]
pub fn incr_gauge(g: Gauge) {
#[cfg(any(feature = "stats", feature = "http"))]
{
metrics::incr_gauge(g);
}
#[cfg(not(any(feature = "stats", feature = "http")))]
{
let _ = g;
}
}
#[inline(always)]
pub fn decr_gauge(g: Gauge) {
#[cfg(any(feature = "stats", feature = "http"))]
{
metrics::decr_gauge(g);
}
#[cfg(not(any(feature = "stats", feature = "http")))]
{
let _ = g;
}
}
#[inline(always)]
pub fn tick_counter(c: Counter) {
#[cfg(any(feature = "stats", feature = "http"))]
{
metrics::tick_counter(c, 1);
}
#[cfg(not(any(feature = "stats", feature = "http")))]
{
let _ = c;
}
}
#[inline(always)]
pub fn add_counter(c: Counter, delta: u64) {
#[cfg(any(feature = "stats", feature = "http"))]
{
metrics::tick_counter(c, delta);
}
#[cfg(not(any(feature = "stats", feature = "http")))]
{
let _ = (c, delta);
}
}
#[repr(usize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Counter {
CacheHits = 0,
CacheMisses = 1,
CacheEvictions = 2,
CompactionRunsTotal = 3,
CompactionBytesTotal = 4,
VlogSyncs = 5,
VlogGroupCommitBatches = 6,
}
impl Counter {
pub const COUNT: usize = 7;
pub const ALL: [Counter; Self::COUNT] = [
Counter::CacheHits,
Counter::CacheMisses,
Counter::CacheEvictions,
Counter::CompactionRunsTotal,
Counter::CompactionBytesTotal,
Counter::VlogSyncs,
Counter::VlogGroupCommitBatches,
];
#[inline]
pub const fn name(self) -> &'static str {
match self {
Counter::CacheHits => "skeg_cache_hits_total",
Counter::CacheMisses => "skeg_cache_misses_total",
Counter::CacheEvictions => "skeg_cache_evictions_total",
Counter::CompactionRunsTotal => "skeg_compaction_runs_total",
Counter::CompactionBytesTotal => "skeg_compaction_bytes_total",
Counter::VlogSyncs => "skeg_vlog_syncs_total",
Counter::VlogGroupCommitBatches => "skeg_vlog_group_commit_batches_total",
}
}
}
#[repr(usize)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Gauge {
VlogSegmentsLive = 0,
VlogSegmentsCompacting = 1,
VlogLiveBytes = 2,
VlogTotalBytes = 3,
CompactionInProgress = 4,
VindexSizeBytes = 5,
VindexVectors = 6,
}
impl Gauge {
pub const COUNT: usize = 7;
pub const ALL: [Gauge; Self::COUNT] = [
Gauge::VlogSegmentsLive,
Gauge::VlogSegmentsCompacting,
Gauge::VlogLiveBytes,
Gauge::VlogTotalBytes,
Gauge::CompactionInProgress,
Gauge::VindexSizeBytes,
Gauge::VindexVectors,
];
#[inline]
pub const fn name(self) -> &'static str {
match self {
Gauge::VlogSegmentsLive => "skeg_vlog_segments_live",
Gauge::VlogSegmentsCompacting => "skeg_vlog_segments_compacting",
Gauge::VlogLiveBytes => "skeg_vlog_live_bytes",
Gauge::VlogTotalBytes => "skeg_vlog_total_bytes",
Gauge::CompactionInProgress => "skeg_compaction_in_progress",
Gauge::VindexSizeBytes => "skeg_vindex_size_bytes",
Gauge::VindexVectors => "skeg_vindex_vectors",
}
}
}
#[allow(dead_code)]
const _ASSERT_ZERO_COST: () = {
};