Skip to main content

mz_catalog/durable/
metrics.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Prometheus monitoring metrics.
11
12use mz_ore::metric;
13use mz_ore::metrics::{IntCounter, MetricsRegistry};
14use mz_ore::stats::histogram_seconds_buckets;
15use prometheus::{Histogram, IntGauge, IntGaugeVec};
16
17#[derive(Debug, Clone)]
18pub struct Metrics {
19    pub transactions_started: IntCounter,
20    pub transaction_commits: IntCounter,
21    pub transaction_commit_latency_seconds: Histogram,
22    pub snapshots_taken: IntCounter,
23    pub snapshot_latency_seconds: Histogram,
24    pub syncs: IntCounter,
25    pub sync_latency_seconds: Histogram,
26    pub collection_entries: IntGaugeVec,
27    pub allocate_id_seconds: Histogram,
28    pub snapshot_consolidations: IntCounter,
29    pub snapshot_max_entries: IntGauge,
30}
31
32impl Metrics {
33    /// Returns a new [Metrics] instance connected to the given registry.
34    pub fn new(registry: &MetricsRegistry) -> Self {
35        Self {
36            transactions_started: registry.register(metric!(
37                name: "mz_catalog_transactions_started",
38                help: "Total number of started transactions.",
39            )),
40            transaction_commits: registry.register(metric!(
41                name: "mz_catalog_transaction_commits",
42                help: "Count of transaction commits.",
43            )),
44            transaction_commit_latency_seconds: registry.register(metric!(
45                name: "mz_catalog_transaction_commit_latency_seconds",
46                help: "Latency for committing a durable catalog transaction.",
47                buckets: histogram_seconds_buckets(0.000_128, 32.0),
48            )),
49            snapshots_taken: registry.register(metric!(
50                name: "mz_catalog_snapshots_taken",
51                help: "Count of snapshots taken.",
52            )),
53            snapshot_latency_seconds: registry.register(metric!(
54                name: "mz_catalog_snapshot_latency_seconds",
55                help: "Latency for fetching a snapshot of the durable catalog.",
56                buckets: histogram_seconds_buckets(0.000_128, 32.0),
57            )),
58            syncs: registry.register(metric!(
59                name: "mz_catalog_syncs",
60                help: "Count of catalog syncs.",
61            )),
62            sync_latency_seconds: registry.register(metric!(
63                name: "mz_catalog_sync_latency_seconds",
64                help: "Latency for syncing the in-memory state of the durable catalog with the persisted contents.",
65                buckets: histogram_seconds_buckets(0.000_128, 32.0),
66            )),
67            collection_entries: registry.register(metric!(
68                name: "mz_catalog_collection_entries",
69                help: "Total number of entries, after consolidation, per catalog collection.",
70                var_labels: ["collection"],
71            )),
72            allocate_id_seconds: registry.register(metric!(
73                name: "mz_catalog_allocate_id_seconds",
74                help: "The time it takes to allocate IDs in the durable catalog.",
75                buckets: histogram_seconds_buckets(0.001, 32.0),
76            )),
77            snapshot_consolidations: registry.register(metric!(
78                name: "mz_catalog_snapshot_consolidations",
79                help: "Count of snapshot consolidation passes.",
80            )),
81            snapshot_max_entries: registry.register(metric!(
82                name: "mz_catalog_snapshot_max_entries",
83                help: "High-water mark of entries in the unconsolidated in-memory \
84                       snapshot since process start.",
85            )),
86        }
87    }
88}