1use std::time::Duration;
16
17use lazy_static::lazy_static;
18use prometheus::*;
19use puffin::puffin_manager::stager::StagerNotifier;
20
21pub const STAGE_LABEL: &str = "stage";
23pub const TYPE_LABEL: &str = "type";
25const CACHE_EVICTION_CAUSE: &str = "cause";
26pub const FLUSH_REASON: &str = "reason";
28pub const FILE_TYPE_LABEL: &str = "file_type";
30pub const WORKER_LABEL: &str = "worker";
32pub const PARTITION_LABEL: &str = "partition";
34pub const STAGING_TYPE: &str = "index_staging";
36pub const RECYCLE_TYPE: &str = "recycle_bin";
38
39lazy_static! {
40 pub static ref WRITE_BUFFER_BYTES: IntGauge =
42 register_int_gauge!("greptime_mito_write_buffer_bytes", "mito write buffer bytes").unwrap();
43 pub static ref MEMTABLE_DICT_BYTES: IntGauge =
45 register_int_gauge!("greptime_mito_memtable_dict_bytes", "mito memtable dictionary size in bytes").unwrap();
46 pub static ref REGION_COUNT: IntGaugeVec =
48 register_int_gauge_vec!(
49 "greptime_mito_region_count",
50 "mito region count in each worker",
51 &[WORKER_LABEL],
52 ).unwrap();
53 pub static ref HANDLE_REQUEST_ELAPSED: HistogramVec = register_histogram_vec!(
55 "greptime_mito_handle_request_elapsed",
56 "mito handle request elapsed",
57 &[TYPE_LABEL],
58 exponential_buckets(0.01, 10.0, 7).unwrap(),
60 )
61 .unwrap();
62
63 pub static ref FLUSH_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!(
67 "greptime_mito_flush_requests_total",
68 "mito flush requests total",
69 &[FLUSH_REASON]
70 )
71 .unwrap();
72 pub static ref FLUSH_FAILURE_TOTAL: IntCounter =
74 register_int_counter!("greptime_mito_flush_failure_total", "mito flush failure total").unwrap();
75 pub static ref FLUSH_ELAPSED: HistogramVec = register_histogram_vec!(
77 "greptime_mito_flush_elapsed",
78 "mito flush elapsed",
79 &[TYPE_LABEL],
80 exponential_buckets(1.0, 5.0, 6).unwrap(),
82 )
83 .unwrap();
84 pub static ref FLUSH_BYTES_TOTAL: IntCounter =
86 register_int_counter!("greptime_mito_flush_bytes_total", "mito flush bytes total").unwrap();
87 pub static ref INFLIGHT_FLUSH_COUNT: IntGauge =
89 register_int_gauge!(
90 "greptime_mito_inflight_flush_count",
91 "inflight flush count",
92 ).unwrap();
93 pub static ref WRITE_STALL_TOTAL: IntGaugeVec = register_int_gauge_vec!(
99 "greptime_mito_write_stall_total",
100 "mito stalled write request in each worker",
101 &[WORKER_LABEL]
102 ).unwrap();
103 pub static ref WRITE_REJECT_TOTAL: IntCounter =
105 register_int_counter!("greptime_mito_write_reject_total", "mito write reject total").unwrap();
106 pub static ref WRITE_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
108 "greptime_mito_write_stage_elapsed",
109 "mito write stage elapsed",
110 &[STAGE_LABEL],
111 exponential_buckets(0.01, 10.0, 6).unwrap(),
113 )
114 .unwrap();
115 pub static ref WRITE_ROWS_TOTAL: IntCounterVec = register_int_counter_vec!(
117 "greptime_mito_write_rows_total",
118 "mito write rows total",
119 &[TYPE_LABEL]
120 )
121 .unwrap();
122 pub static ref COMPACTION_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
128 "greptime_mito_compaction_stage_elapsed",
129 "mito compaction stage elapsed",
130 &[STAGE_LABEL],
131 exponential_buckets(1.0, 10.0, 6).unwrap(),
133 )
134 .unwrap();
135 pub static ref COMPACTION_ELAPSED_TOTAL: Histogram =
137 register_histogram!(
138 "greptime_mito_compaction_total_elapsed",
139 "mito compaction total elapsed",
140 exponential_buckets(1.0, 10.0, 6).unwrap(),
142 ).unwrap();
143 pub static ref COMPACTION_REQUEST_COUNT: IntCounter =
145 register_int_counter!("greptime_mito_compaction_requests_total", "mito compaction requests total").unwrap();
146 pub static ref COMPACTION_FAILURE_COUNT: IntCounter =
148 register_int_counter!("greptime_mito_compaction_failure_total", "mito compaction failure total").unwrap();
149
150 pub static ref INFLIGHT_COMPACTION_COUNT: IntGauge =
152 register_int_gauge!(
153 "greptime_mito_inflight_compaction_count",
154 "inflight compaction count",
155 ).unwrap();
156
157 pub static ref READ_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
160 "greptime_mito_read_stage_elapsed",
161 "mito read stage elapsed",
162 &[STAGE_LABEL],
163 exponential_buckets(0.01, 10.0, 7).unwrap(),
165 )
166 .unwrap();
167 pub static ref READ_STAGE_FETCH_PAGES: Histogram = READ_STAGE_ELAPSED.with_label_values(&["fetch_pages"]);
168 pub static ref IN_PROGRESS_SCAN: IntGaugeVec = register_int_gauge_vec!(
170 "greptime_mito_in_progress_scan",
171 "mito in progress scan per partition",
172 &[TYPE_LABEL, PARTITION_LABEL]
173 )
174 .unwrap();
175 pub static ref READ_ROWS_TOTAL: IntCounterVec =
177 register_int_counter_vec!("greptime_mito_read_rows_total", "mito read rows total", &[TYPE_LABEL]).unwrap();
178 pub static ref MERGE_FILTER_ROWS_TOTAL: IntCounterVec =
180 register_int_counter_vec!("greptime_mito_merge_filter_rows_total", "mito merge filter rows total", &[TYPE_LABEL]).unwrap();
181 pub static ref READ_ROW_GROUPS_TOTAL: IntCounterVec =
183 register_int_counter_vec!("greptime_mito_read_row_groups_total", "mito read row groups total", &[TYPE_LABEL]).unwrap();
184 pub static ref PRECISE_FILTER_ROWS_TOTAL: IntCounterVec =
186 register_int_counter_vec!("greptime_mito_precise_filter_rows_total", "mito precise filter rows total", &[TYPE_LABEL]).unwrap();
187 pub static ref READ_ROWS_IN_ROW_GROUP_TOTAL: IntCounterVec =
188 register_int_counter_vec!("greptime_mito_read_rows_in_row_group_total", "mito read rows in row group total", &[TYPE_LABEL]).unwrap();
189 pub static ref READ_SST_COUNT: Histogram = register_histogram!(
191 "greptime_mito_read_sst_count",
192 "Number of SSTs to scan in a scan task",
193 vec![1.0, 4.0, 8.0, 16.0, 32.0, 64.0, 256.0, 1024.0],
194 ).unwrap();
195 pub static ref READ_ROWS_RETURN: Histogram = register_histogram!(
197 "greptime_mito_read_rows_return",
198 "Number of rows returned in a scan task",
199 exponential_buckets(100.0, 10.0, 8).unwrap(),
200 ).unwrap();
201 pub static ref READ_BATCHES_RETURN: Histogram = register_histogram!(
203 "greptime_mito_read_batches_return",
204 "Number of rows returned in a scan task",
205 exponential_buckets(100.0, 10.0, 7).unwrap(),
206 ).unwrap();
207 pub static ref CACHE_HIT: IntCounterVec = register_int_counter_vec!(
212 "greptime_mito_cache_hit",
213 "mito cache hit",
214 &[TYPE_LABEL]
215 )
216 .unwrap();
217 pub static ref CACHE_MISS: IntCounterVec = register_int_counter_vec!(
219 "greptime_mito_cache_miss",
220 "mito cache miss",
221 &[TYPE_LABEL]
222 )
223 .unwrap();
224 pub static ref CACHE_BYTES: IntGaugeVec = register_int_gauge_vec!(
226 "greptime_mito_cache_bytes",
227 "mito cache bytes",
228 &[TYPE_LABEL]
229 )
230 .unwrap();
231 pub static ref WRITE_CACHE_DOWNLOAD_BYTES_TOTAL: IntCounter = register_int_counter!(
233 "mito_write_cache_download_bytes_total",
234 "mito write cache download bytes total",
235 ).unwrap();
236 pub static ref WRITE_CACHE_DOWNLOAD_ELAPSED: HistogramVec = register_histogram_vec!(
238 "mito_write_cache_download_elapsed",
239 "mito write cache download elapsed",
240 &[TYPE_LABEL],
241 exponential_buckets(0.1, 10.0, 6).unwrap(),
243 ).unwrap();
244 pub static ref WRITE_CACHE_INFLIGHT_DOWNLOAD: IntGauge = register_int_gauge!(
246 "mito_write_cache_inflight_download_count",
247 "mito write cache inflight download tasks",
248 ).unwrap();
249 pub static ref UPLOAD_BYTES_TOTAL: IntCounter = register_int_counter!(
251 "mito_upload_bytes_total",
252 "mito upload bytes total",
253 )
254 .unwrap();
255 pub static ref CACHE_EVICTION: IntCounterVec = register_int_counter_vec!(
257 "greptime_mito_cache_eviction",
258 "mito cache eviction",
259 &[TYPE_LABEL, CACHE_EVICTION_CAUSE]
260 ).unwrap();
261 pub static ref INDEX_APPLY_ELAPSED: HistogramVec = register_histogram_vec!(
266 "greptime_index_apply_elapsed",
267 "index apply elapsed",
268 &[TYPE_LABEL],
269 exponential_buckets(0.01, 10.0, 6).unwrap(),
271 )
272 .unwrap();
273 pub static ref INDEX_APPLY_MEMORY_USAGE: IntGauge = register_int_gauge!(
275 "greptime_index_apply_memory_usage",
276 "index apply memory usage",
277 )
278 .unwrap();
279 pub static ref INDEX_CREATE_ELAPSED: HistogramVec = register_histogram_vec!(
281 "greptime_index_create_elapsed",
282 "index create elapsed",
283 &[STAGE_LABEL, TYPE_LABEL],
284 exponential_buckets(0.1, 10.0, 6).unwrap(),
286 )
287 .unwrap();
288 pub static ref INDEX_CREATE_ROWS_TOTAL: IntCounterVec = register_int_counter_vec!(
290 "greptime_index_create_rows_total",
291 "index create rows total",
292 &[TYPE_LABEL],
293 )
294 .unwrap();
295 pub static ref INDEX_CREATE_BYTES_TOTAL: IntCounterVec = register_int_counter_vec!(
297 "greptime_index_create_bytes_total",
298 "index create bytes total",
299 &[TYPE_LABEL],
300 )
301 .unwrap();
302 pub static ref INDEX_CREATE_MEMORY_USAGE: IntGaugeVec = register_int_gauge_vec!(
304 "greptime_index_create_memory_usage",
305 "index create memory usage",
306 &[TYPE_LABEL],
307 ).unwrap();
308 pub static ref INDEX_IO_BYTES_TOTAL: IntCounterVec = register_int_counter_vec!(
310 "greptime_index_io_bytes_total",
311 "index io bytes total",
312 &[TYPE_LABEL, FILE_TYPE_LABEL]
313 )
314 .unwrap();
315 pub static ref INDEX_PUFFIN_READ_BYTES_TOTAL: IntCounter = INDEX_IO_BYTES_TOTAL
317 .with_label_values(&["read", "puffin"]);
318 pub static ref INDEX_PUFFIN_WRITE_BYTES_TOTAL: IntCounter = INDEX_IO_BYTES_TOTAL
320 .with_label_values(&["write", "puffin"]);
321 pub static ref INDEX_INTERMEDIATE_READ_BYTES_TOTAL: IntCounter = INDEX_IO_BYTES_TOTAL
323 .with_label_values(&["read", "intermediate"]);
324 pub static ref INDEX_INTERMEDIATE_WRITE_BYTES_TOTAL: IntCounter = INDEX_IO_BYTES_TOTAL
326 .with_label_values(&["write", "intermediate"]);
327
328 pub static ref INDEX_IO_OP_TOTAL: IntCounterVec = register_int_counter_vec!(
330 "greptime_index_io_op_total",
331 "index io op total",
332 &[TYPE_LABEL, FILE_TYPE_LABEL]
333 )
334 .unwrap();
335 pub static ref INDEX_PUFFIN_READ_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
337 .with_label_values(&["read", "puffin"]);
338 pub static ref INDEX_PUFFIN_SEEK_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
340 .with_label_values(&["seek", "puffin"]);
341 pub static ref INDEX_PUFFIN_WRITE_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
343 .with_label_values(&["write", "puffin"]);
344 pub static ref INDEX_PUFFIN_FLUSH_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
346 .with_label_values(&["flush", "puffin"]);
347 pub static ref INDEX_INTERMEDIATE_READ_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
349 .with_label_values(&["read", "intermediate"]);
350 pub static ref INDEX_INTERMEDIATE_SEEK_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
352 .with_label_values(&["seek", "intermediate"]);
353 pub static ref INDEX_INTERMEDIATE_WRITE_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
355 .with_label_values(&["write", "intermediate"]);
356 pub static ref INDEX_INTERMEDIATE_FLUSH_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
358 .with_label_values(&["flush", "intermediate"]);
359 pub static ref PARTITION_TREE_DATA_BUFFER_FREEZE_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
363 "greptime_partition_tree_buffer_freeze_stage_elapsed",
364 "mito partition tree data buffer freeze stage elapsed",
365 &[STAGE_LABEL],
366 exponential_buckets(0.01, 10.0, 6).unwrap(),
368 )
369 .unwrap();
370
371 pub static ref PARTITION_TREE_READ_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
373 "greptime_partition_tree_read_stage_elapsed",
374 "mito partition tree read stage elapsed",
375 &[STAGE_LABEL],
376 exponential_buckets(0.01, 10.0, 6).unwrap(),
378 )
379 .unwrap();
380
381 pub static ref MANIFEST_OP_ELAPSED: HistogramVec = register_histogram_vec!(
388 "greptime_manifest_op_elapsed",
389 "mito manifest operation elapsed",
390 &["op"],
391 exponential_buckets(0.01, 10.0, 6).unwrap(),
393 ).unwrap();
394
395
396 pub static ref REGION_WORKER_HANDLE_WRITE_ELAPSED: HistogramVec = register_histogram_vec!(
397 "greptime_region_worker_handle_write",
398 "elapsed time for handling writes in region worker loop",
399 &["stage"],
400 exponential_buckets(0.001, 10.0, 5).unwrap()
401 ).unwrap();
402
403}
404
405lazy_static! {
406 pub static ref COMPACTION_INPUT_BYTES: Counter = register_counter!(
408 "greptime_mito_compaction_input_bytes",
409 "mito compaction input file size",
410 ).unwrap();
411
412 pub static ref COMPACTION_OUTPUT_BYTES: Counter = register_counter!(
414 "greptime_mito_compaction_output_bytes",
415 "mito compaction output file size",
416 ).unwrap();
417}
418
419pub struct StagerMetrics {
421 cache_hit: IntCounter,
422 cache_miss: IntCounter,
423 staging_cache_bytes: IntGauge,
424 recycle_cache_bytes: IntGauge,
425 cache_eviction: IntCounter,
426 staging_miss_read: Histogram,
427}
428
429impl StagerMetrics {
430 pub fn new() -> Self {
432 Self {
433 cache_hit: CACHE_HIT.with_label_values(&[STAGING_TYPE]),
434 cache_miss: CACHE_MISS.with_label_values(&[STAGING_TYPE]),
435 staging_cache_bytes: CACHE_BYTES.with_label_values(&[STAGING_TYPE]),
436 recycle_cache_bytes: CACHE_BYTES.with_label_values(&[RECYCLE_TYPE]),
437 cache_eviction: CACHE_EVICTION.with_label_values(&[STAGING_TYPE, "size"]),
438 staging_miss_read: READ_STAGE_ELAPSED.with_label_values(&["staging_miss_read"]),
439 }
440 }
441}
442
443impl Default for StagerMetrics {
444 fn default() -> Self {
445 Self::new()
446 }
447}
448
449impl StagerNotifier for StagerMetrics {
450 fn on_cache_hit(&self, _size: u64) {
451 self.cache_hit.inc();
452 }
453
454 fn on_cache_miss(&self, _size: u64) {
455 self.cache_miss.inc();
456 }
457
458 fn on_cache_insert(&self, size: u64) {
459 self.staging_cache_bytes.add(size as i64);
460 }
461
462 fn on_load_dir(&self, duration: Duration) {
463 self.staging_miss_read.observe(duration.as_secs_f64());
464 }
465
466 fn on_load_blob(&self, duration: Duration) {
467 self.staging_miss_read.observe(duration.as_secs_f64());
468 }
469
470 fn on_cache_evict(&self, size: u64) {
471 self.cache_eviction.inc();
472 self.staging_cache_bytes.sub(size as i64);
473 }
474
475 fn on_recycle_insert(&self, size: u64) {
476 self.recycle_cache_bytes.add(size as i64);
477 }
478
479 fn on_recycle_clear(&self, size: u64) {
480 self.recycle_cache_bytes.sub(size as i64);
481 }
482}