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! {
41 pub static ref WRITE_BUFFER_BYTES: IntGauge =
43 register_int_gauge!("greptime_mito_write_buffer_bytes", "mito write buffer bytes").unwrap();
44 pub static ref MEMTABLE_DICT_BYTES: IntGauge =
46 register_int_gauge!("greptime_mito_memtable_dict_bytes", "mito memtable dictionary size in bytes").unwrap();
47 pub static ref REGION_COUNT: IntGaugeVec =
49 register_int_gauge_vec!(
50 "greptime_mito_region_count",
51 "mito region count in each worker",
52 &[WORKER_LABEL],
53 ).unwrap();
54 pub static ref HANDLE_REQUEST_ELAPSED: HistogramVec = register_histogram_vec!(
56 "greptime_mito_handle_request_elapsed",
57 "mito handle request elapsed",
58 &[TYPE_LABEL],
59 exponential_buckets(0.01, 10.0, 7).unwrap(),
61 )
62 .unwrap();
63
64 pub static ref FLUSH_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!(
68 "greptime_mito_flush_requests_total",
69 "mito flush requests total",
70 &[FLUSH_REASON]
71 )
72 .unwrap();
73 pub static ref FLUSH_FAILURE_TOTAL: IntCounter =
75 register_int_counter!("greptime_mito_flush_failure_total", "mito flush failure total").unwrap();
76 pub static ref FLUSH_ELAPSED: HistogramVec = register_histogram_vec!(
78 "greptime_mito_flush_elapsed",
79 "mito flush elapsed",
80 &[TYPE_LABEL],
81 exponential_buckets(1.0, 5.0, 6).unwrap(),
83 )
84 .unwrap();
85 pub static ref FLUSH_BYTES_TOTAL: IntCounter =
87 register_int_counter!("greptime_mito_flush_bytes_total", "mito flush bytes total").unwrap();
88 pub static ref INFLIGHT_FLUSH_COUNT: IntGauge =
90 register_int_gauge!(
91 "greptime_mito_inflight_flush_count",
92 "inflight flush count",
93 ).unwrap();
94 pub static ref WRITE_REJECT_TOTAL: IntCounter =
101 register_int_counter!("greptime_mito_write_reject_total", "mito write reject total").unwrap();
102 pub static ref WRITE_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
104 "greptime_mito_write_stage_elapsed",
105 "mito write stage elapsed",
106 &[STAGE_LABEL],
107 exponential_buckets(0.01, 10.0, 6).unwrap(),
109 )
110 .unwrap();
111 pub static ref WRITE_ROWS_TOTAL: IntCounterVec = register_int_counter_vec!(
113 "greptime_mito_write_rows_total",
114 "mito write rows total",
115 &[TYPE_LABEL]
116 )
117 .unwrap();
118}
119
120lazy_static! {
122 pub static ref COMPACTION_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
132 "greptime_mito_compaction_stage_elapsed",
133 "mito compaction stage elapsed",
134 &[STAGE_LABEL],
135 exponential_buckets(1.0, 10.0, 6).unwrap(),
137 )
138 .unwrap();
139 pub static ref COMPACTION_ELAPSED_TOTAL: Histogram =
141 register_histogram!(
142 "greptime_mito_compaction_total_elapsed",
143 "mito compaction total elapsed",
144 exponential_buckets(1.0, 10.0, 6).unwrap(),
146 ).unwrap();
147 pub static ref COMPACTION_REQUEST_COUNT: IntCounter =
149 register_int_counter!("greptime_mito_compaction_requests_total", "mito compaction requests total").unwrap();
150 pub static ref COMPACTION_FAILURE_COUNT: IntCounter =
152 register_int_counter!("greptime_mito_compaction_failure_total", "mito compaction failure total").unwrap();
153
154 pub static ref INFLIGHT_COMPACTION_COUNT: IntGauge =
156 register_int_gauge!(
157 "greptime_mito_inflight_compaction_count",
158 "inflight compaction count",
159 ).unwrap();
160
161 pub static ref COMPACTION_MEMORY_IN_USE: IntGauge =
163 register_int_gauge!(
164 "greptime_mito_compaction_memory_in_use_bytes",
165 "bytes currently reserved for compaction tasks",
166 )
167 .unwrap();
168 pub static ref COMPACTION_MEMORY_LIMIT: IntGauge =
170 register_int_gauge!(
171 "greptime_mito_compaction_memory_limit_bytes",
172 "maximum bytes allowed for compaction tasks",
173 )
174 .unwrap();
175 pub static ref COMPACTION_MEMORY_WAIT: Histogram = register_histogram!(
177 "greptime_mito_compaction_memory_wait_seconds",
178 "time waiting for compaction memory",
179 exponential_buckets(0.01, 2.0, 10).unwrap(),
181 ).unwrap();
182 pub static ref COMPACTION_MEMORY_REJECTED: IntCounterVec =
184 register_int_counter_vec!(
185 "greptime_mito_compaction_memory_rejected_total",
186 "number of compaction tasks rejected due to memory limit",
187 &[TYPE_LABEL]
188 ).unwrap();
189}
190
191lazy_static! {
193 pub static ref READ_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
195 "greptime_mito_read_stage_elapsed",
196 "mito read stage elapsed",
197 &[STAGE_LABEL],
198 exponential_buckets(0.01, 10.0, 7).unwrap(),
200 )
201 .unwrap();
202 pub static ref READ_STAGE_FETCH_PAGES: Histogram = READ_STAGE_ELAPSED.with_label_values(&["fetch_pages"]);
203 pub static ref IN_PROGRESS_SCAN: IntGaugeVec = register_int_gauge_vec!(
205 "greptime_mito_in_progress_scan",
206 "mito in progress scan per partition",
207 &[TYPE_LABEL, PARTITION_LABEL]
208 )
209 .unwrap();
210 pub static ref READ_ROWS_TOTAL: IntCounterVec =
212 register_int_counter_vec!("greptime_mito_read_rows_total", "mito read rows total", &[TYPE_LABEL]).unwrap();
213 pub static ref MERGE_FILTER_ROWS_TOTAL: IntCounterVec =
215 register_int_counter_vec!("greptime_mito_merge_filter_rows_total", "mito merge filter rows total", &[TYPE_LABEL]).unwrap();
216 pub static ref READ_ROW_GROUPS_TOTAL: IntCounterVec =
218 register_int_counter_vec!("greptime_mito_read_row_groups_total", "mito read row groups total", &[TYPE_LABEL]).unwrap();
219 pub static ref PRECISE_FILTER_ROWS_TOTAL: IntCounterVec =
221 register_int_counter_vec!("greptime_mito_precise_filter_rows_total", "mito precise filter rows total", &[TYPE_LABEL]).unwrap();
222 pub static ref READ_ROWS_IN_ROW_GROUP_TOTAL: IntCounterVec =
223 register_int_counter_vec!("greptime_mito_read_rows_in_row_group_total", "mito read rows in row group total", &[TYPE_LABEL]).unwrap();
224 pub static ref READ_SST_COUNT: Histogram = register_histogram!(
226 "greptime_mito_read_sst_count",
227 "Number of SSTs to scan in a scan task",
228 vec![1.0, 4.0, 8.0, 16.0, 32.0, 64.0, 256.0, 1024.0],
229 ).unwrap();
230 pub static ref READ_ROWS_RETURN: Histogram = register_histogram!(
232 "greptime_mito_read_rows_return",
233 "Number of rows returned in a scan task",
234 exponential_buckets(100.0, 10.0, 8).unwrap(),
235 ).unwrap();
236 pub static ref READ_BATCHES_RETURN: Histogram = register_histogram!(
238 "greptime_mito_read_batches_return",
239 "Number of rows returned in a scan task",
240 exponential_buckets(100.0, 10.0, 7).unwrap(),
241 ).unwrap();
242 pub static ref SCAN_MEMORY_USAGE_BYTES: IntGauge = register_int_gauge!(
244 "greptime_mito_scan_memory_usage_bytes",
245 "current scan memory usage in bytes"
246 ).unwrap();
247 pub static ref SCAN_REQUESTS_REJECTED_TOTAL: IntCounter = register_int_counter!(
249 "greptime_mito_scan_requests_rejected_total",
250 "total number of scan requests rejected due to memory limit"
251 ).unwrap();
252 pub static ref PRUNER_ACTIVE_BUILDERS: IntGauge = register_int_gauge!(
254 "greptime_mito_pruner_active_builders",
255 "number of active file range builders in the pruner"
256 ).unwrap();
257}
258
259lazy_static! {
261 pub static ref CACHE_HIT: IntCounterVec = register_int_counter_vec!(
263 "greptime_mito_cache_hit",
264 "mito cache hit",
265 &[TYPE_LABEL]
266 )
267 .unwrap();
268 pub static ref CACHE_MISS: IntCounterVec = register_int_counter_vec!(
270 "greptime_mito_cache_miss",
271 "mito cache miss",
272 &[TYPE_LABEL]
273 )
274 .unwrap();
275 pub static ref CACHE_BYTES: IntGaugeVec = register_int_gauge_vec!(
277 "greptime_mito_cache_bytes",
278 "mito cache bytes",
279 &[TYPE_LABEL]
280 )
281 .unwrap();
282 pub static ref WRITE_CACHE_DOWNLOAD_BYTES_TOTAL: IntCounter = register_int_counter!(
284 "mito_write_cache_download_bytes_total",
285 "mito write cache download bytes total",
286 ).unwrap();
287 pub static ref WRITE_CACHE_DOWNLOAD_ELAPSED: HistogramVec = register_histogram_vec!(
289 "mito_write_cache_download_elapsed",
290 "mito write cache download elapsed",
291 &[TYPE_LABEL],
292 exponential_buckets(0.1, 10.0, 6).unwrap(),
294 ).unwrap();
295 pub static ref WRITE_CACHE_INFLIGHT_DOWNLOAD: IntGauge = register_int_gauge!(
297 "mito_write_cache_inflight_download_count",
298 "mito write cache inflight download tasks",
299 ).unwrap();
300 pub static ref UPLOAD_BYTES_TOTAL: IntCounter = register_int_counter!(
302 "mito_upload_bytes_total",
303 "mito upload bytes total",
304 )
305 .unwrap();
306 pub static ref CACHE_EVICTION: IntCounterVec = register_int_counter_vec!(
308 "greptime_mito_cache_eviction",
309 "mito cache eviction",
310 &[TYPE_LABEL, CACHE_EVICTION_CAUSE]
311 ).unwrap();
312}
313
314lazy_static! {
316 pub static ref INDEX_APPLY_ELAPSED: HistogramVec = register_histogram_vec!(
319 "greptime_index_apply_elapsed",
320 "index apply elapsed",
321 &[TYPE_LABEL],
322 exponential_buckets(0.01, 10.0, 6).unwrap(),
324 )
325 .unwrap();
326 pub static ref INDEX_APPLY_MEMORY_USAGE: IntGauge = register_int_gauge!(
328 "greptime_index_apply_memory_usage",
329 "index apply memory usage",
330 )
331 .unwrap();
332 pub static ref INDEX_CREATE_ELAPSED: HistogramVec = register_histogram_vec!(
334 "greptime_index_create_elapsed",
335 "index create elapsed",
336 &[STAGE_LABEL, TYPE_LABEL],
337 exponential_buckets(0.1, 10.0, 6).unwrap(),
339 )
340 .unwrap();
341 pub static ref INDEX_CREATE_ROWS_TOTAL: IntCounterVec = register_int_counter_vec!(
343 "greptime_index_create_rows_total",
344 "index create rows total",
345 &[TYPE_LABEL],
346 )
347 .unwrap();
348 pub static ref INDEX_CREATE_BYTES_TOTAL: IntCounterVec = register_int_counter_vec!(
350 "greptime_index_create_bytes_total",
351 "index create bytes total",
352 &[TYPE_LABEL],
353 )
354 .unwrap();
355 pub static ref INDEX_CREATE_MEMORY_USAGE: IntGaugeVec = register_int_gauge_vec!(
357 "greptime_index_create_memory_usage",
358 "index create memory usage",
359 &[TYPE_LABEL],
360 ).unwrap();
361 pub static ref INDEX_IO_BYTES_TOTAL: IntCounterVec = register_int_counter_vec!(
363 "greptime_index_io_bytes_total",
364 "index io bytes total",
365 &[TYPE_LABEL, FILE_TYPE_LABEL]
366 )
367 .unwrap();
368 pub static ref INDEX_PUFFIN_READ_BYTES_TOTAL: IntCounter = INDEX_IO_BYTES_TOTAL
370 .with_label_values(&["read", "puffin"]);
371 pub static ref INDEX_PUFFIN_WRITE_BYTES_TOTAL: IntCounter = INDEX_IO_BYTES_TOTAL
373 .with_label_values(&["write", "puffin"]);
374 pub static ref INDEX_INTERMEDIATE_READ_BYTES_TOTAL: IntCounter = INDEX_IO_BYTES_TOTAL
376 .with_label_values(&["read", "intermediate"]);
377 pub static ref INDEX_INTERMEDIATE_WRITE_BYTES_TOTAL: IntCounter = INDEX_IO_BYTES_TOTAL
379 .with_label_values(&["write", "intermediate"]);
380
381 pub static ref INDEX_IO_OP_TOTAL: IntCounterVec = register_int_counter_vec!(
383 "greptime_index_io_op_total",
384 "index io op total",
385 &[TYPE_LABEL, FILE_TYPE_LABEL]
386 )
387 .unwrap();
388 pub static ref INDEX_PUFFIN_READ_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
390 .with_label_values(&["read", "puffin"]);
391 pub static ref INDEX_PUFFIN_SEEK_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
393 .with_label_values(&["seek", "puffin"]);
394 pub static ref INDEX_PUFFIN_WRITE_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
396 .with_label_values(&["write", "puffin"]);
397 pub static ref INDEX_PUFFIN_FLUSH_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
399 .with_label_values(&["flush", "puffin"]);
400 pub static ref INDEX_INTERMEDIATE_READ_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
402 .with_label_values(&["read", "intermediate"]);
403 pub static ref INDEX_INTERMEDIATE_SEEK_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
405 .with_label_values(&["seek", "intermediate"]);
406 pub static ref INDEX_INTERMEDIATE_WRITE_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
408 .with_label_values(&["write", "intermediate"]);
409 pub static ref INDEX_INTERMEDIATE_FLUSH_OP_TOTAL: IntCounter = INDEX_IO_OP_TOTAL
411 .with_label_values(&["flush", "intermediate"]);
412}
413
414lazy_static! {
415 pub static ref PARTITION_TREE_DATA_BUFFER_FREEZE_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
417 "greptime_partition_tree_buffer_freeze_stage_elapsed",
418 "mito partition tree data buffer freeze stage elapsed",
419 &[STAGE_LABEL],
420 exponential_buckets(0.01, 10.0, 6).unwrap(),
422 )
423 .unwrap();
424
425 pub static ref PARTITION_TREE_READ_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
427 "greptime_partition_tree_read_stage_elapsed",
428 "mito partition tree read stage elapsed",
429 &[STAGE_LABEL],
430 exponential_buckets(0.01, 10.0, 6).unwrap(),
432 )
433 .unwrap();
434
435 pub static ref MANIFEST_OP_ELAPSED: HistogramVec = register_histogram_vec!(
442 "greptime_manifest_op_elapsed",
443 "mito manifest operation elapsed",
444 &["op"],
445 exponential_buckets(0.01, 10.0, 6).unwrap(),
447 ).unwrap();
448
449
450 pub static ref REGION_WORKER_HANDLE_WRITE_ELAPSED: HistogramVec = register_histogram_vec!(
451 "greptime_region_worker_handle_write",
452 "elapsed time for handling writes in region worker loop",
453 &["stage"],
454 exponential_buckets(0.001, 10.0, 5).unwrap()
455 ).unwrap();
456
457}
458
459lazy_static! {
460 pub static ref COMPACTION_INPUT_BYTES: Counter = register_counter!(
462 "greptime_mito_compaction_input_bytes",
463 "mito compaction input file size",
464 ).unwrap();
465
466 pub static ref COMPACTION_OUTPUT_BYTES: Counter = register_counter!(
468 "greptime_mito_compaction_output_bytes",
469 "mito compaction output file size",
470 ).unwrap();
471
472 pub static ref MEMTABLE_ACTIVE_SERIES_COUNT: IntGauge = register_int_gauge!(
474 "greptime_mito_memtable_active_series_count",
475 "active time series count in TimeSeriesMemtable",
476 ).unwrap();
477
478 pub static ref MEMTABLE_ACTIVE_FIELD_BUILDER_COUNT: IntGauge = register_int_gauge!(
480 "greptime_mito_memtable_field_builder_count",
481 "active field builder count in TimeSeriesMemtable",
482 ).unwrap();
483
484 pub static ref WRITE_STALLING: IntGaugeVec = register_int_gauge_vec!(
486 "greptime_mito_write_stalling_count",
487 "mito stalled write request in each worker",
488 &[WORKER_LABEL]
489 ).unwrap();
490 pub static ref GC_REF_FILE_CNT: IntGauge = register_int_gauge!(
492 "greptime_gc_ref_file_count",
493 "gc ref file count",
494 ).unwrap();
495 pub static ref WRITE_STALL_TOTAL: IntCounter = register_int_counter!(
497 "greptime_mito_write_stall_total",
498 "Total number of stalled write requests"
499 ).unwrap();
500 pub static ref REQUEST_WAIT_TIME: HistogramVec = register_histogram_vec!(
502 "greptime_mito_request_wait_time",
503 "mito request wait time before being handled by region worker",
504 &[WORKER_LABEL],
505 exponential_buckets(0.001, 10.0, 8).unwrap(),
507 )
508 .unwrap();
509
510 pub static ref GC_DELETE_FILE_CNT: IntGauge =
512 register_int_gauge!(
513 "greptime_mito_gc_delete_file_count",
514 "mito gc deleted file count",
515 ).unwrap();
516
517 pub static ref GC_SKIPPED_UNPARSABLE_FILES: IntCounter =
519 register_int_counter!(
520 "greptime_mito_gc_skipped_unparsable_files",
521 "mito gc skipped unparsable files count",
522 ).unwrap();
523
524 pub static ref GC_ORPHANED_INDEX_FILES: IntCounter =
526 register_int_counter!(
527 "greptime_mito_gc_orphaned_index_files",
528 "mito gc orphaned index files count",
529 ).unwrap();
530
531 pub static ref CACHE_FILL_DOWNLOADED_FILES: IntCounter = register_int_counter!(
533 "mito_cache_fill_downloaded_files",
534 "mito cache fill downloaded files count",
535 ).unwrap();
536
537 pub static ref CACHE_FILL_PENDING_FILES: IntGauge = register_int_gauge!(
539 "mito_cache_fill_pending_files",
540 "mito cache fill pending files count",
541 ).unwrap();
542
543 pub static ref FLUSH_FILE_TOTAL: IntCounter =
545 register_int_counter!("greptime_mito_flush_file_total", "mito flushed file count").unwrap();
546}
547
548pub struct StagerMetrics {
550 cache_hit: IntCounter,
551 cache_miss: IntCounter,
552 staging_cache_bytes: IntGauge,
553 recycle_cache_bytes: IntGauge,
554 cache_eviction: IntCounter,
555 staging_miss_read: Histogram,
556}
557
558impl StagerMetrics {
559 pub fn new() -> Self {
561 Self {
562 cache_hit: CACHE_HIT.with_label_values(&[STAGING_TYPE]),
563 cache_miss: CACHE_MISS.with_label_values(&[STAGING_TYPE]),
564 staging_cache_bytes: CACHE_BYTES.with_label_values(&[STAGING_TYPE]),
565 recycle_cache_bytes: CACHE_BYTES.with_label_values(&[RECYCLE_TYPE]),
566 cache_eviction: CACHE_EVICTION.with_label_values(&[STAGING_TYPE, "size"]),
567 staging_miss_read: READ_STAGE_ELAPSED.with_label_values(&["staging_miss_read"]),
568 }
569 }
570}
571
572impl Default for StagerMetrics {
573 fn default() -> Self {
574 Self::new()
575 }
576}
577
578impl StagerNotifier for StagerMetrics {
579 fn on_cache_hit(&self, _size: u64) {
580 self.cache_hit.inc();
581 }
582
583 fn on_cache_miss(&self, _size: u64) {
584 self.cache_miss.inc();
585 }
586
587 fn on_cache_insert(&self, size: u64) {
588 self.staging_cache_bytes.add(size as i64);
589 }
590
591 fn on_load_dir(&self, duration: Duration) {
592 self.staging_miss_read.observe(duration.as_secs_f64());
593 }
594
595 fn on_load_blob(&self, duration: Duration) {
596 self.staging_miss_read.observe(duration.as_secs_f64());
597 }
598
599 fn on_cache_evict(&self, size: u64) {
600 self.cache_eviction.inc();
601 self.staging_cache_bytes.sub(size as i64);
602 }
603
604 fn on_recycle_insert(&self, size: u64) {
605 self.recycle_cache_bytes.add(size as i64);
606 }
607
608 fn on_recycle_clear(&self, size: u64) {
609 self.recycle_cache_bytes.sub(size as i64);
610 }
611}