1use prometheus_client::metrics::counter::Counter;
4use prometheus_client::metrics::gauge::Gauge;
5use prometheus_client::metrics::histogram::{Histogram, exponential_buckets};
6use prometheus_client::registry::{Registry, Unit};
7use std::num::NonZeroUsize;
8use std::sync::atomic::{AtomicI64, AtomicU64};
9
10#[derive(Debug)]
12pub(super) struct GpuPlotterMetrics {
13 pub(super) sector_downloading_time: Histogram,
14 pub(super) sector_encoding_time: Histogram,
15 pub(super) sector_plotting_time: Histogram,
16 pub(super) sector_downloading: Counter<u64, AtomicU64>,
17 pub(super) sector_downloaded: Counter<u64, AtomicU64>,
18 pub(super) sector_encoding: Counter<u64, AtomicU64>,
19 pub(super) sector_encoded: Counter<u64, AtomicU64>,
20 pub(super) sector_plotting: Counter<u64, AtomicU64>,
21 pub(super) sector_plotted: Counter<u64, AtomicU64>,
22 pub(super) sector_plotting_error: Counter<u64, AtomicU64>,
23 pub(super) plotting_capacity_used: Gauge<i64, AtomicI64>,
24}
25
26impl GpuPlotterMetrics {
27 pub(super) fn new(registry: &mut Registry, total_capacity: NonZeroUsize) -> Self {
29 let registry = registry
30 .sub_registry_with_prefix("plotter")
31 .sub_registry_with_label(("kind".into(), "gpu".into()));
33
34 let sector_downloading_time = Histogram::new(exponential_buckets(0.1, 2.0, 15));
35 registry.register_with_unit(
36 "sector_downloading_time",
37 "Sector downloading time",
38 Unit::Seconds,
39 sector_downloading_time.clone(),
40 );
41
42 let sector_encoding_time = Histogram::new(exponential_buckets(0.1, 2.0, 15));
43 registry.register_with_unit(
44 "sector_encoding_time",
45 "Sector encoding time",
46 Unit::Seconds,
47 sector_encoding_time.clone(),
48 );
49
50 let sector_plotting_time = Histogram::new(exponential_buckets(0.1, 2.0, 15));
51 registry.register_with_unit(
52 "sector_plotting_time",
53 "Sector plotting time",
54 Unit::Seconds,
55 sector_plotting_time.clone(),
56 );
57
58 let sector_downloading = Counter::default();
59 registry.register_with_unit(
60 "sector_downloading_counter",
61 "Number of sectors being downloaded",
62 Unit::Other("Sectors".to_string()),
63 sector_downloading.clone(),
64 );
65
66 let sector_downloaded = Counter::default();
67 registry.register_with_unit(
68 "sector_downloaded_counter",
69 "Number of downloaded sectors",
70 Unit::Other("Sectors".to_string()),
71 sector_downloaded.clone(),
72 );
73
74 let sector_encoding = Counter::default();
75 registry.register_with_unit(
76 "sector_encoding_counter",
77 "Number of sectors being encoded",
78 Unit::Other("Sectors".to_string()),
79 sector_encoding.clone(),
80 );
81
82 let sector_encoded = Counter::default();
83 registry.register_with_unit(
84 "sector_encoded_counter",
85 "Number of encoded sectors",
86 Unit::Other("Sectors".to_string()),
87 sector_encoded.clone(),
88 );
89
90 let sector_plotting = Counter::default();
91 registry.register_with_unit(
92 "sector_plotting_counter",
93 "Number of sectors being plotted",
94 Unit::Other("Sectors".to_string()),
95 sector_plotting.clone(),
96 );
97
98 let sector_plotted = Counter::default();
99 registry.register_with_unit(
100 "sector_plotted_counter",
101 "Number of plotted sectors",
102 Unit::Other("Sectors".to_string()),
103 sector_plotted.clone(),
104 );
105
106 let sector_plotting_error = Counter::default();
107 registry.register_with_unit(
108 "sector_plotting_error_counter",
109 "Number of sector plotting failures",
110 Unit::Other("Sectors".to_string()),
111 sector_plotting_error.clone(),
112 );
113
114 let plotting_capacity_total = Gauge::<i64, AtomicI64>::default();
115 plotting_capacity_total.set(total_capacity.get() as i64);
116 registry.register_with_unit(
117 "plotting_capacity_total",
118 "Plotting capacity total",
119 Unit::Other("Sectors".to_string()),
120 plotting_capacity_total,
121 );
122
123 let plotting_capacity_used = Gauge::default();
124 registry.register_with_unit(
125 "plotting_capacity_used",
126 "Plotting capacity used",
127 Unit::Other("Sectors".to_string()),
128 plotting_capacity_used.clone(),
129 );
130
131 Self {
132 sector_downloading_time,
133 sector_encoding_time,
134 sector_plotting_time,
135 sector_downloading,
136 sector_downloaded,
137 sector_encoding,
138 sector_encoded,
139 sector_plotting,
140 sector_plotted,
141 sector_plotting_error,
142 plotting_capacity_used,
143 }
144 }
145}