cat_gateway/metrics/caches/
txo_assets.rs1use super::cache_metric_inc;
4use crate::{db::index::session::CassandraSession, settings::Settings};
5
6const PERSISTENT: bool = true;
8
9pub(crate) fn update() {
11 let api_host_names = Settings::api_host_names().join(",");
12 let service_id = Settings::service_id();
13 let network = Settings::cardano_network().to_string();
14
15 CassandraSession::get(PERSISTENT).inspect(|session| {
17 let cache = session.caches().assets_ada();
18 reporter::TXO_ASSETS_CACHE_SIZE
19 .with_label_values(&[&api_host_names, service_id, &network])
20 .set(i64::try_from(cache.weighted_size()).unwrap_or(-1));
21
22 reporter::TXO_ASSETS_CACHE_ENTRIES_COUNT
23 .with_label_values(&[&api_host_names, service_id, &network])
24 .set(i64::try_from(cache.entry_count()).unwrap_or(-1));
25 });
26}
27
28pub(crate) fn txo_assets_hits_inc() {
30 cache_metric_inc!(TXO_ASSETS_CACHE_HIT_COUNT);
31}
32
33pub(crate) fn txo_assets_misses_inc() {
35 cache_metric_inc!(TXO_ASSETS_CACHE_MISSES_COUNT);
36}
37
38mod reporter {
39 use std::sync::LazyLock;
41
42 use prometheus::{
43 register_int_counter_vec, register_int_gauge_vec, IntCounterVec, IntGaugeVec,
44 };
45
46 const METRIC_LABELS: [&str; 3] = ["api_host_names", "service_id", "network"];
48
49 pub(super) static TXO_ASSETS_CACHE_SIZE: LazyLock<IntGaugeVec> = LazyLock::new(|| {
51 register_int_gauge_vec!(
52 "cache_txo_assets_size",
53 "Returns the total weighted size of TXO Assets entries in this cache",
54 &METRIC_LABELS
55 )
56 .unwrap()
57 });
58
59 pub(super) static TXO_ASSETS_CACHE_ENTRIES_COUNT: LazyLock<IntGaugeVec> = LazyLock::new(|| {
61 register_int_gauge_vec!(
62 "cache_txo_assets_entries_count",
63 "Returns the number of TXO Assets entries in this cache",
64 &METRIC_LABELS
65 )
66 .unwrap()
67 });
68
69 pub(super) static TXO_ASSETS_CACHE_HIT_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
71 register_int_counter_vec!(
72 "cache_txo_assets_hits_count",
73 "Returns the number of hits (entries found) in the TXO Assets cache",
74 &METRIC_LABELS
75 )
76 .unwrap()
77 });
78
79 pub(super) static TXO_ASSETS_CACHE_MISSES_COUNT: LazyLock<IntCounterVec> =
81 LazyLock::new(|| {
82 register_int_counter_vec!(
83 "cache_txo_assets_misses_count",
84 "Returns the number of misses (entries not found) in the TXO Assets cache",
85 &METRIC_LABELS
86 )
87 .unwrap()
88 });
89}