epoch_db/metrics/
mod.rs

1//! The `metrics` module defines the `Metrics` struct and its associated
2//! methods.
3//!
4//! The corresponding struct is used to update all of the Prometheus metrics
5//! that the database contains.
6
7// TODO: Refactor the whole file to use Prometheus crate instead for testing
8// purposes
9
10use metrics::{
11    counter,
12    gauge
13};
14
15/// A stateless struct that provides a clean, organized API for updating
16/// the application's global Prometheus metrics via the `metrics` facade.
17#[derive(Debug)]
18pub struct Metrics {}
19
20impl Metrics {
21    /// Sets the current number of keys for a given tree.
22    pub fn set_keys_total(tree: &str, value: u64) {
23        gauge!("epochdb_keys_total", "tree" => tree.to_string()).set(value as f64);
24    }
25
26    /// Sets the current number of keys for a given tree.
27    pub fn inc_keys_total(tree: &str) {
28        gauge!("epochdb_keys_total", "tree" => tree.to_string()).increment(1);
29    }
30
31    /// Sets the current number of keys for a given tree.
32    pub fn dec_keys_total(tree: &str) {
33        gauge!("epochdb_keys_total", "tree" => tree.to_string()).decrement(1);
34    }
35
36    /// Increments the counter for a specific database operation.
37    pub fn increment_operations(op: &str) {
38        counter!("epochdb_operations_total", "operation" => op.to_string()).increment(1);
39    }
40
41    /// Sets the current total disk size of the database.
42    pub fn set_disk_size(bytes: f64) {
43        gauge!("epochdb_disk_size_bytes").set(bytes);
44    }
45
46    /// Sets the size of the last successful backup.
47    pub fn set_backup_size(bytes: f64) {
48        gauge!("epochdb_backup_size_bytes").set(bytes);
49    }
50
51    /// Increments the counter for expired TTL keys.
52    pub fn increment_ttl_expired_keys() {
53        counter!("epochdb_ttl_expired_keys_total").increment(1);
54    }
55
56    /// Sets the current number of keys for a given tree.
57    pub fn inc_amount_keys_total(tree: &str, value: u64) {
58        gauge!("epochdb_keys_total", "tree" => tree.to_string()).set(value as f64);
59    }
60
61    /// Sets the current number of keys for a given tree.
62    pub fn dec_amount_keys_total(tree: &str, amount: u64) {
63        gauge!("epochdb_keys_total", "tree" => tree.to_string()).decrement(amount as f64);
64    }
65
66    /// Increments the counter for a specific database operation.
67    pub fn increment_amount_operations(op: &str, amount: u64) {
68        counter!("epochdb_operations_total", "operation" => op.to_string()).increment(amount);
69    }
70}