1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright Materialize, Inc. and contributors. All rights reserved.
//
// Use of this software is governed by the Business Source License
// included in the LICENSE file.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0.

//! Prometheus monitoring metrics.

use mz_ore::metric;
use mz_ore::metrics::{IntCounter, MetricsRegistry};
use prometheus::{Counter, IntGaugeVec};

#[derive(Debug, Clone)]
pub struct Metrics {
    pub transactions_started: IntCounter,
    pub transaction_commits: IntCounter,
    pub transaction_commit_latency_seconds: Counter,
    pub snapshots_taken: IntCounter,
    pub snapshot_latency_seconds: Counter,
    pub syncs: IntCounter,
    pub sync_latency_seconds: Counter,
    pub collection_entries: IntGaugeVec,
}

impl Metrics {
    /// Returns a new [Metrics] instance connected to the given registry.
    pub fn new(registry: &MetricsRegistry) -> Self {
        Self {
            transactions_started: registry.register(metric!(
                name: "mz_catalog_transactions_started",
                help: "Total number of started transactions.",
            )),
            transaction_commits: registry.register(metric!(
                name: "mz_catalog_transaction_commits",
                help: "Count of transaction commits.",
            )),
            transaction_commit_latency_seconds: registry.register(metric!(
                name: "mz_catalog_transaction_commit_latency_seconds",
                help: "Total latency for committing a durable catalog transactions.",
            )),
            snapshots_taken: registry.register(metric!(
                name: "mz_catalog_snapshots_taken",
                help: "Count of snapshots taken.",
            )),
            snapshot_latency_seconds: registry.register(metric!(
                name: "mz_catalog_snapshot_latency_seconds",
                help: "Total latency for fetching a snapshot of the durable catalog.",
            )),
            syncs: registry.register(metric!(
                name: "mz_catalog_syncs",
                help: "Count of catalog syncs.",
            )),
            sync_latency_seconds: registry.register(metric!(
                name: "mz_catalog_sync_latency_seconds",
                help: "Total latency for syncing the in-memory state of the durable catalog with the persisted contents.",
            )),
            collection_entries: registry.register(metric!(
                name: "mz_catalog_collection_entries",
                help: "Total number of entries, after consolidation, per catalog collection.",
                var_labels: ["collection"],
            )),
        }
    }
}