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 prometheus::{Counter, IntGaugeVec};
15
16#[derive(Debug, Clone)]
17pub struct Metrics {
18    pub transactions_started: IntCounter,
19    pub transaction_commits: IntCounter,
20    pub transaction_commit_latency_seconds: Counter,
21    pub snapshots_taken: IntCounter,
22    pub snapshot_latency_seconds: Counter,
23    pub syncs: IntCounter,
24    pub sync_latency_seconds: Counter,
25    pub collection_entries: IntGaugeVec,
26}
27
28impl Metrics {
29    /// Returns a new [Metrics] instance connected to the given registry.
30    pub fn new(registry: &MetricsRegistry) -> Self {
31        Self {
32            transactions_started: registry.register(metric!(
33                name: "mz_catalog_transactions_started",
34                help: "Total number of started transactions.",
35            )),
36            transaction_commits: registry.register(metric!(
37                name: "mz_catalog_transaction_commits",
38                help: "Count of transaction commits.",
39            )),
40            transaction_commit_latency_seconds: registry.register(metric!(
41                name: "mz_catalog_transaction_commit_latency_seconds",
42                help: "Total latency for committing a durable catalog transactions.",
43            )),
44            snapshots_taken: registry.register(metric!(
45                name: "mz_catalog_snapshots_taken",
46                help: "Count of snapshots taken.",
47            )),
48            snapshot_latency_seconds: registry.register(metric!(
49                name: "mz_catalog_snapshot_latency_seconds",
50                help: "Total latency for fetching a snapshot of the durable catalog.",
51            )),
52            syncs: registry.register(metric!(
53                name: "mz_catalog_syncs",
54                help: "Count of catalog syncs.",
55            )),
56            sync_latency_seconds: registry.register(metric!(
57                name: "mz_catalog_sync_latency_seconds",
58                help: "Total latency for syncing the in-memory state of the durable catalog with the persisted contents.",
59            )),
60            collection_entries: registry.register(metric!(
61                name: "mz_catalog_collection_entries",
62                help: "Total number of entries, after consolidation, per catalog collection.",
63                var_labels: ["collection"],
64            )),
65        }
66    }
67}