1+ use prometheus_client:: metrics:: counter:: Counter ;
12use prometheus_client:: metrics:: family:: Family ;
23use prometheus_client:: metrics:: histogram:: { exponential_buckets, Histogram } ;
34use prometheus_client:: registry:: { Registry , Unit } ;
5+ use std:: sync:: atomic:: AtomicU64 ;
46use std:: time:: Duration ;
57use subspace_farmer:: single_disk_farm:: farming:: ProvingResult ;
68use subspace_farmer:: single_disk_farm:: SingleDiskFarmId ;
79
810#[ derive( Debug , Clone ) ]
9- pub ( crate ) struct FarmerMetrics {
11+ pub ( super ) struct FarmerMetrics {
1012 auditing_time : Family < Vec < ( String , String ) > , Histogram > ,
1113 proving_time : Family < Vec < ( String , String ) > , Histogram > ,
1214 sector_downloading_time : Family < Vec < ( String , String ) > , Histogram > ,
1315 sector_encoding_time : Family < Vec < ( String , String ) > , Histogram > ,
1416 sector_writing_time : Family < Vec < ( String , String ) > , Histogram > ,
1517 sector_plotting_time : Family < Vec < ( String , String ) > , Histogram > ,
18+ pub ( super ) sector_downloading : Counter < u64 , AtomicU64 > ,
19+ pub ( super ) sector_downloaded : Counter < u64 , AtomicU64 > ,
20+ pub ( super ) sector_encoding : Counter < u64 , AtomicU64 > ,
21+ pub ( super ) sector_encoded : Counter < u64 , AtomicU64 > ,
22+ pub ( super ) sector_writing : Counter < u64 , AtomicU64 > ,
23+ pub ( super ) sector_written : Counter < u64 , AtomicU64 > ,
24+ pub ( super ) sector_plotting : Counter < u64 , AtomicU64 > ,
25+ pub ( super ) sector_plotted : Counter < u64 , AtomicU64 > ,
1626}
1727
1828impl FarmerMetrics {
19- pub ( crate ) fn new ( registry : & mut Registry ) -> Self {
29+ pub ( super ) fn new ( registry : & mut Registry ) -> Self {
2030 let sub_registry = registry. sub_registry_with_prefix ( "subspace_farmer" ) ;
2131
2232 let auditing_time = Family :: < _ , _ > :: new_with_constructor ( || {
@@ -85,17 +95,97 @@ impl FarmerMetrics {
8595 sector_plotting_time. clone ( ) ,
8696 ) ;
8797
98+ let sector_downloading = Counter :: < _ , _ > :: default ( ) ;
99+
100+ sub_registry. register_with_unit (
101+ "sector_downloading_counter" ,
102+ "Number of sectors being downloaded" ,
103+ Unit :: Other ( "sectors" . to_string ( ) ) ,
104+ sector_downloading. clone ( ) ,
105+ ) ;
106+
107+ let sector_downloaded = Counter :: < _ , _ > :: default ( ) ;
108+
109+ sub_registry. register_with_unit (
110+ "sector_downloaded_counter" ,
111+ "Number of sectors being downloaded" ,
112+ Unit :: Other ( "sectors" . to_string ( ) ) ,
113+ sector_downloaded. clone ( ) ,
114+ ) ;
115+
116+ let sector_encoding = Counter :: < _ , _ > :: default ( ) ;
117+
118+ sub_registry. register_with_unit (
119+ "sector_encoding_counter" ,
120+ "Number of sectors being downloaded" ,
121+ Unit :: Other ( "sectors" . to_string ( ) ) ,
122+ sector_encoding. clone ( ) ,
123+ ) ;
124+
125+ let sector_encoded = Counter :: < _ , _ > :: default ( ) ;
126+
127+ sub_registry. register_with_unit (
128+ "sector_encoded_counter" ,
129+ "Number of sectors being downloaded" ,
130+ Unit :: Other ( "sectors" . to_string ( ) ) ,
131+ sector_encoded. clone ( ) ,
132+ ) ;
133+
134+ let sector_writing = Counter :: < _ , _ > :: default ( ) ;
135+
136+ sub_registry. register_with_unit (
137+ "sector_writing_counter" ,
138+ "Number of sectors being downloaded" ,
139+ Unit :: Other ( "sectors" . to_string ( ) ) ,
140+ sector_writing. clone ( ) ,
141+ ) ;
142+
143+ let sector_written = Counter :: < _ , _ > :: default ( ) ;
144+
145+ sub_registry. register_with_unit (
146+ "sector_written_counter" ,
147+ "Number of sectors being downloaded" ,
148+ Unit :: Other ( "sectors" . to_string ( ) ) ,
149+ sector_written. clone ( ) ,
150+ ) ;
151+
152+ let sector_plotting = Counter :: < _ , _ > :: default ( ) ;
153+
154+ sub_registry. register_with_unit (
155+ "sector_plotting_counter" ,
156+ "Number of sectors being downloaded" ,
157+ Unit :: Other ( "sectors" . to_string ( ) ) ,
158+ sector_plotting. clone ( ) ,
159+ ) ;
160+
161+ let sector_plotted = Counter :: < _ , _ > :: default ( ) ;
162+
163+ sub_registry. register_with_unit (
164+ "sector_plotted_counter" ,
165+ "Number of sectors being downloaded" ,
166+ Unit :: Other ( "sectors" . to_string ( ) ) ,
167+ sector_plotted. clone ( ) ,
168+ ) ;
169+
88170 Self {
89171 auditing_time,
90172 proving_time,
91173 sector_downloading_time,
92174 sector_encoding_time,
93175 sector_writing_time,
94176 sector_plotting_time,
177+ sector_downloading,
178+ sector_downloaded,
179+ sector_encoding,
180+ sector_encoded,
181+ sector_writing,
182+ sector_written,
183+ sector_plotting,
184+ sector_plotted,
95185 }
96186 }
97187
98- pub ( crate ) fn observe_auditing_time (
188+ pub ( super ) fn observe_auditing_time (
99189 & self ,
100190 single_disk_farm_id : & SingleDiskFarmId ,
101191 time : & Duration ,
@@ -108,7 +198,7 @@ impl FarmerMetrics {
108198 . observe ( time. as_secs_f64 ( ) ) ;
109199 }
110200
111- pub ( crate ) fn observe_proving_time (
201+ pub ( super ) fn observe_proving_time (
112202 & self ,
113203 single_disk_farm_id : & SingleDiskFarmId ,
114204 time : & Duration ,
@@ -122,7 +212,7 @@ impl FarmerMetrics {
122212 . observe ( time. as_secs_f64 ( ) ) ;
123213 }
124214
125- pub ( crate ) fn observe_sector_downloading_time (
215+ pub ( super ) fn observe_sector_downloading_time (
126216 & self ,
127217 single_disk_farm_id : & SingleDiskFarmId ,
128218 time : & Duration ,
@@ -135,7 +225,7 @@ impl FarmerMetrics {
135225 . observe ( time. as_secs_f64 ( ) ) ;
136226 }
137227
138- pub ( crate ) fn observe_sector_encoding_time (
228+ pub ( super ) fn observe_sector_encoding_time (
139229 & self ,
140230 single_disk_farm_id : & SingleDiskFarmId ,
141231 time : & Duration ,
@@ -148,7 +238,7 @@ impl FarmerMetrics {
148238 . observe ( time. as_secs_f64 ( ) ) ;
149239 }
150240
151- pub ( crate ) fn observe_sector_writing_time (
241+ pub ( super ) fn observe_sector_writing_time (
152242 & self ,
153243 single_disk_farm_id : & SingleDiskFarmId ,
154244 time : & Duration ,
@@ -161,7 +251,7 @@ impl FarmerMetrics {
161251 . observe ( time. as_secs_f64 ( ) ) ;
162252 }
163253
164- pub ( crate ) fn observe_sector_plotting_time (
254+ pub ( super ) fn observe_sector_plotting_time (
165255 & self ,
166256 single_disk_farm_id : & SingleDiskFarmId ,
167257 time : & Duration ,
0 commit comments