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::{Counter, Histogram, 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: Counter,
22    pub snapshots_taken: IntCounter,
23    pub snapshot_latency_seconds: Counter,
24    pub syncs: IntCounter,
25    pub sync_latency_seconds: Counter,
26    pub collection_entries: IntGaugeVec,
27    pub allocate_id_seconds: Histogram,
28}
29
30impl Metrics {
31    /// Returns a new [Metrics] instance connected to the given registry.
32    pub fn new(registry: &MetricsRegistry) -> Self {
33        Self {
34            transactions_started: registry.register(metric!(
35                name: "mz_catalog_transactions_started",
36                help: "Total number of started transactions.",
37            )),
38            transaction_commits: registry.register(metric!(
39                name: "mz_catalog_transaction_commits",
40                help: "Count of transaction commits.",
41            )),
42            transaction_commit_latency_seconds: registry.register(metric!(
43                name: "mz_catalog_transaction_commit_latency_seconds",
44                help: "Total latency for committing a durable catalog transactions.",
45            )),
46            snapshots_taken: registry.register(metric!(
47                name: "mz_catalog_snapshots_taken",
48                help: "Count of snapshots taken.",
49            )),
50            snapshot_latency_seconds: registry.register(metric!(
51                name: "mz_catalog_snapshot_latency_seconds",
52                help: "Total latency for fetching a snapshot of the durable catalog.",
53            )),
54            syncs: registry.register(metric!(
55                name: "mz_catalog_syncs",
56                help: "Count of catalog syncs.",
57            )),
58            sync_latency_seconds: registry.register(metric!(
59                name: "mz_catalog_sync_latency_seconds",
60                help: "Total latency for syncing the in-memory state of the durable catalog with the persisted contents.",
61            )),
62            collection_entries: registry.register(metric!(
63                name: "mz_catalog_collection_entries",
64                help: "Total number of entries, after consolidation, per catalog collection.",
65                var_labels: ["collection"],
66            )),
67            allocate_id_seconds: registry.register(metric!(
68                name: "mz_catalog_allocate_id_seconds",
69                help: "The time it takes to allocate IDs in the durable catalog.",
70                buckets: histogram_seconds_buckets(0.001, 32.0),
71            )),
72        }
73    }
74}