subspace_farmer/plotter/gpu/
metrics.rs

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