lruttl/
metrics.rs

1use prometheus::{IntCounterVec, IntGaugeVec};
2use std::sync::LazyLock;
3
4pub(crate) static CACHE_LOOKUP: LazyLock<IntCounterVec> = LazyLock::new(|| {
5    prometheus::register_int_counter_vec!(
6        "lruttl_lookup_count",
7        "how many times a lruttl cache lookup was initiated for a given cache",
8        &["cache_name"]
9    )
10    .unwrap()
11});
12pub(crate) static CACHE_EVICT: LazyLock<IntCounterVec> = LazyLock::new(|| {
13    prometheus::register_int_counter_vec!(
14        "lruttl_evict_count",
15        "how many times a lruttl cache evicted an item due to capacity constraints",
16        &["cache_name"]
17    )
18    .unwrap()
19});
20pub(crate) static CACHE_EXPIRE: LazyLock<IntCounterVec> = LazyLock::new(|| {
21    prometheus::register_int_counter_vec!(
22        "lruttl_expire_count",
23        "how many times a lruttl cache removed an item due to ttl expiration",
24        &["cache_name"]
25    )
26    .unwrap()
27});
28pub(crate) static CACHE_HIT: LazyLock<IntCounterVec> = LazyLock::new(|| {
29    prometheus::register_int_counter_vec!(
30        "lruttl_hit_count",
31        "how many times a lruttl cache lookup was a hit for a given cache",
32        &["cache_name"]
33    )
34    .unwrap()
35});
36pub(crate) static CACHE_MISS: LazyLock<IntCounterVec> = LazyLock::new(|| {
37    prometheus::register_int_counter_vec!(
38        "lruttl_miss_count",
39        "how many times a lruttl cache lookup was a miss for a given cache",
40        &["cache_name"]
41    )
42    .unwrap()
43});
44pub(crate) static CACHE_INSERT: LazyLock<IntCounterVec> = LazyLock::new(|| {
45    prometheus::register_int_counter_vec!(
46        "lruttl_insert_count",
47        "how many times a lruttl cache was populated via unconditional insert",
48        &["cache_name"]
49    )
50    .unwrap()
51});
52pub(crate) static CACHE_POPULATED: LazyLock<IntCounterVec> = LazyLock::new(|| {
53    prometheus::register_int_counter_vec!(
54        "lruttl_populated_count",
55        "how many times a lruttl cache lookup resulted in performing the work to populate the entry",
56        &["cache_name"]
57    )
58    .unwrap()
59});
60pub(crate) static CACHE_ERROR: LazyLock<IntCounterVec> = LazyLock::new(|| {
61    prometheus::register_int_counter_vec!(
62        "lruttl_error_count",
63        "how many times a lruttl cache population resulted in an error",
64        &["cache_name"]
65    )
66    .unwrap()
67});
68pub(crate) static CACHE_STALE: LazyLock<IntCounterVec> = LazyLock::new(|| {
69    prometheus::register_int_counter_vec!(
70        "lruttl_stale_count",
71        "how many times a lruttl cache population was satisfied by a stale value",
72        &["cache_name"]
73    )
74    .unwrap()
75});
76pub(crate) static CACHE_WAIT: LazyLock<IntGaugeVec> = LazyLock::new(|| {
77    prometheus::register_int_gauge_vec!(
78        "lruttl_waiting_populate",
79        "how many tasks are currently waiting for a cache entry to populate",
80        &["cache_name"]
81    )
82    .unwrap()
83});
84pub(crate) static CACHE_SIZE: LazyLock<IntGaugeVec> = LazyLock::new(|| {
85    prometheus::register_int_gauge_vec!(
86        "lruttl_cache_size",
87        "number of items contained in an lruttl cache",
88        &["cache_name"]
89    )
90    .unwrap()
91});