sui_analytics_indexer/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use prometheus::HistogramOpts;
5use prometheus::HistogramVec;
6use prometheus::IntCounterVec;
7use prometheus::IntGaugeVec;
8use prometheus::Registry;
9use prometheus::register_histogram_vec_with_registry;
10use prometheus::register_int_counter_vec_with_registry;
11use prometheus::register_int_gauge_vec_with_registry;
12
13#[derive(Clone)]
14pub struct Metrics {
15    pub max_checkpoint_on_store: IntGaugeVec,
16    pub total_too_large_to_deserialize: IntCounterVec,
17    pub file_size_bytes: HistogramVec,
18    /// Latest uploaded checkpoint (inclusive) per pipeline.
19    pub latest_uploaded_checkpoint: IntGaugeVec,
20    /// Latest uploaded epoch per pipeline.
21    pub latest_uploaded_epoch: IntGaugeVec,
22}
23
24impl Metrics {
25    pub fn new(registry: &Registry) -> Self {
26        Self {
27            max_checkpoint_on_store: register_int_gauge_vec_with_registry!(
28                "max_checkpoint_on_store",
29                "Max checkpoint on the db table.",
30                &["pipeline"],
31                registry,
32            )
33            .unwrap(),
34            total_too_large_to_deserialize: register_int_counter_vec_with_registry!(
35                "total_too_large_to_deserialize",
36                "Total number of rows skipped due to size.",
37                &["pipeline"],
38                registry,
39            )
40            .unwrap(),
41            file_size_bytes: register_histogram_vec_with_registry!(
42                HistogramOpts::new("file_size_bytes", "Size of generated files in bytes.",)
43                    .buckets(vec![
44                        1_000.0,         // 1 KB
45                        10_000.0,        // 10 KB
46                        100_000.0,       // 100 KB
47                        1_000_000.0,     // 1 MB
48                        10_000_000.0,    // 10 MB
49                        50_000_000.0,    // 50 MB
50                        100_000_000.0,   // 100 MB
51                        250_000_000.0,   // 250 MB
52                        500_000_000.0,   // 500 MB
53                        1_000_000_000.0, // 1 GB
54                        2_000_000_000.0, // 2 GB
55                    ]),
56                &["pipeline"],
57                registry,
58            )
59            .unwrap(),
60            latest_uploaded_checkpoint: register_int_gauge_vec_with_registry!(
61                "latest_uploaded_checkpoint",
62                "Latest checkpoint uploaded to object store (inclusive).",
63                &["pipeline"],
64                registry,
65            )
66            .unwrap(),
67            latest_uploaded_epoch: register_int_gauge_vec_with_registry!(
68                "latest_uploaded_epoch",
69                "Latest epoch uploaded to object store.",
70                &["pipeline"],
71                registry,
72            )
73            .unwrap(),
74        }
75    }
76}