subspace_farmer/disk_piece_cache/
metrics.rs1use crate::farm::PieceCacheId;
4use prometheus_client::metrics::counter::Counter;
5use prometheus_client::metrics::gauge::Gauge;
6use prometheus_client::registry::{Registry, Unit};
7use std::sync::atomic::{AtomicI64, AtomicU64};
8
9#[derive(Debug)]
11pub(super) struct DiskPieceCacheMetrics {
12 pub(super) contents: Counter<u64, AtomicU64>,
13 pub(super) read_piece: Counter<u64, AtomicU64>,
14 pub(super) read_piece_index: Counter<u64, AtomicU64>,
15 pub(super) write_piece: Counter<u64, AtomicU64>,
16 pub(super) capacity_used: Gauge<i64, AtomicI64>,
17}
18
19impl DiskPieceCacheMetrics {
20 pub(super) fn new(
22 registry: &mut Registry,
23 cache_id: &PieceCacheId,
24 max_num_elements: u32,
25 ) -> Self {
26 let registry = registry
27 .sub_registry_with_prefix("disk_piece_cache")
28 .sub_registry_with_label(("cache_id".into(), cache_id.to_string().into()));
29
30 let contents = Counter::default();
31 registry.register_with_unit(
32 "contents",
33 "Contents requests",
34 Unit::Other("Requests".to_string()),
35 contents.clone(),
36 );
37
38 let read_piece = Counter::default();
39 registry.register_with_unit(
40 "read_piece",
41 "Read piece requests",
42 Unit::Other("Pieces".to_string()),
43 read_piece.clone(),
44 );
45
46 let read_piece_index = Counter::default();
47 registry.register_with_unit(
48 "read_piece_index",
49 "Read piece index requests",
50 Unit::Other("Requests".to_string()),
51 read_piece_index.clone(),
52 );
53
54 let write_piece = Counter::default();
55 registry.register_with_unit(
56 "write_piece",
57 "Write piece requests",
58 Unit::Other("Pieces".to_string()),
59 write_piece.clone(),
60 );
61
62 let capacity_total = Gauge::<i64, AtomicI64>::default();
63 capacity_total.set(i64::from(max_num_elements));
64 registry.register_with_unit(
65 "capacity_total",
66 "Piece cache capacity total",
67 Unit::Other("Pieces".to_string()),
68 capacity_total,
69 );
70
71 let capacity_used = Gauge::default();
72 registry.register_with_unit(
73 "capacity_used",
74 "Piece cache capacity used",
75 Unit::Other("Pieces".to_string()),
76 capacity_used.clone(),
77 );
78
79 Self {
80 contents,
81 read_piece,
82 read_piece_index,
83 write_piece,
84 capacity_used,
85 }
86 }
87}