Skip to main content

meta_srv/
metrics.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use lazy_static::lazy_static;
16use prometheus::*;
17
18lazy_static! {
19    /// Elapsed time to responding kv requests.
20    pub static ref METRIC_META_KV_REQUEST_ELAPSED: HistogramVec = register_histogram_vec!(
21        "greptime_meta_kv_request_elapsed",
22        "meta kv request",
23        &["target", "op"]
24    )
25    .unwrap();
26    /// The heartbeat connection gauge.
27    pub static ref METRIC_META_HEARTBEAT_CONNECTION_NUM: IntGauge = register_int_gauge!(
28        "greptime_meta_heartbeat_connection_num",
29        "meta heartbeat connection num"
30    )
31    .unwrap();
32    /// Elapsed time to execution of heartbeat handlers.
33    pub static ref METRIC_META_HANDLER_EXECUTE: HistogramVec =
34        register_histogram_vec!("greptime_meta_handler_execute", "meta handler execute", &["name"]).unwrap();
35    /// Inactive region gauge.
36    pub static ref METRIC_META_INACTIVE_REGIONS: IntGauge =
37        register_int_gauge!("greptime_meta_inactive_regions", "meta inactive regions").unwrap();
38    /// Elapsed time to leader cache kv.
39    pub static ref METRIC_META_LEADER_CACHED_KV_LOAD_ELAPSED: HistogramVec =
40        register_histogram_vec!("greptime_meta_leader_cache_kv_load", "meta load cache", &["prefix"])
41            .unwrap();
42    /// Meta kv cache hit counter.
43    pub static ref METRIC_META_KV_CACHE_HIT: IntCounterVec =
44        register_int_counter_vec!("greptime_meta_kv_cache_hit", "meta kv cache hit", &["op"]).unwrap();
45    /// Meta kv cache miss counter.
46    pub static ref METRIC_META_KV_CACHE_MISS: IntCounterVec =
47        register_int_counter_vec!("greptime_meta_kv_cache_miss", "meta kv cache miss", &["op"]).unwrap();
48    ///  Heartbeat received by metasrv.
49    pub static ref METRIC_META_HEARTBEAT_RECV: IntCounterVec =
50        register_int_counter_vec!("greptime_meta_heartbeat_recv", "heartbeats received by metasrv", &["pusher_key"]).unwrap();
51    /// Heartbeats dropped by metasrv.
52    pub static ref METRIC_META_HEARTBEAT_DROPPED: IntCounterVec =
53        register_int_counter_vec!("greptime_meta_heartbeat_dropped", "heartbeats dropped by metasrv", &["reason"]).unwrap();
54    /// The migration execute histogram.
55    pub static ref METRIC_META_REGION_MIGRATION_EXECUTE: HistogramVec =
56        register_histogram_vec!("greptime_meta_region_migration_execute", "meta region migration execute", &["state"]).unwrap();
57    /// The migration error counter.
58    pub static ref METRIC_META_REGION_MIGRATION_ERROR: IntCounterVec =
59        register_int_counter_vec!("greptime_meta_region_migration_error", "meta region migration abort", &["state", "error_type"]).unwrap();
60    /// The migration datanode counter.
61    pub static ref METRIC_META_REGION_MIGRATION_DATANODES: IntCounterVec =
62        register_int_counter_vec!("greptime_meta_region_migration_stat", "meta region migration stat", &["datanode_type", "datanode_id"]).unwrap();
63    /// The migration fail counter.
64    pub static ref METRIC_META_REGION_MIGRATION_FAIL: IntCounter =
65        register_int_counter!("greptime_meta_region_migration_fail", "meta region migration fail").unwrap();
66    // The heartbeat stat memory size histogram.
67    pub static ref METRIC_META_HEARTBEAT_STAT_MEMORY_SIZE: Histogram =
68        register_histogram!("greptime_meta_heartbeat_stat_memory_size", "meta heartbeat stat memory size", vec![
69            100.0, 500.0, 1000.0, 1500.0, 2000.0, 3000.0, 5000.0, 10000.0, 20000.0
70        ]).unwrap();
71    // The heartbeat rate counter.
72    pub static ref METRIC_META_HEARTBEAT_RATE: IntCounter =
73        register_int_counter!("greptime_meta_heartbeat_rate", "meta heartbeat arrival rate").unwrap();
74    /// The remote WAL prune execute counter.
75    pub static ref METRIC_META_REMOTE_WAL_PRUNE_EXECUTE: IntCounterVec =
76        register_int_counter_vec!("greptime_meta_remote_wal_prune_execute", "meta remote wal prune execute", &["topic_name"]).unwrap();
77    /// The migration stage elapsed histogram.
78    pub static ref METRIC_META_REGION_MIGRATION_STAGE_ELAPSED: HistogramVec = register_histogram_vec!(
79        "greptime_meta_region_migration_stage_elapsed",
80        "meta region migration stage elapsed",
81        &["stage"],
82        // 0.01 ~ 1000
83        exponential_buckets(0.01, 10.0, 7).unwrap(),
84    )
85    .unwrap();
86    /// The triggered region flush total counter.
87    pub static ref METRIC_META_TRIGGERED_REGION_FLUSH_TOTAL: IntCounterVec =
88        register_int_counter_vec!("meta_triggered_region_flush_total", "meta triggered region flush total", &["topic_name"]).unwrap();
89
90    /// The triggered region checkpoint total counter.
91    pub static ref METRIC_META_TRIGGERED_REGION_CHECKPOINT_TOTAL: IntCounterVec =
92        register_int_counter_vec!("meta_triggered_region_checkpoint_total", "meta triggered region checkpoint total", &["topic_name"]).unwrap();
93    /// The topic estimated replay size.
94    pub static ref METRIC_META_TOPIC_ESTIMATED_REPLAY_SIZE: IntGaugeVec =
95        register_int_gauge_vec!("meta_topic_estimated_replay_size", "meta topic estimated replay size", &["topic_name"]).unwrap();
96
97    /// Total GC scheduler cycles.
98    pub static ref METRIC_META_GC_SCHEDULER_CYCLES_TOTAL: IntCounter = register_int_counter!(
99        "greptime_metasrv_gc_scheduler_cycles_total",
100        "Total GC scheduler cycles",
101    )
102    .unwrap();
103
104    /// Time for a full GC scheduler cycle.
105    pub static ref METRIC_META_GC_SCHEDULER_DURATION_SECONDS: Histogram = register_histogram!(
106        "greptime_metasrv_gc_scheduler_duration_seconds",
107        "Time for a full GC scheduler cycle",
108        vec![0.1, 0.5, 1.0, 2.0, 5.0, 10.0, 30.0, 60.0, 120.0, 300.0],
109    )
110    .unwrap();
111
112    /// Number of GC candidate regions.
113    pub static ref METRIC_META_GC_CANDIDATE_REGIONS: IntGauge = register_int_gauge!(
114        "greptime_metasrv_gc_candidate_regions",
115        "Number of GC candidate regions",
116    )
117    .unwrap();
118
119    /// Calls to datanodes for GC.
120    pub static ref METRIC_META_GC_DATANODE_CALLS_TOTAL: IntCounterVec = register_int_counter_vec!(
121        "greptime_metasrv_gc_datanode_calls_total",
122        "Calls to datanodes for GC",
123        &["operation", "status"],
124    )
125    .unwrap();
126
127    /// Total regions that failed GC.
128    pub static ref METRIC_META_GC_FAILED_REGIONS_TOTAL: IntCounter = register_int_counter!(
129        "greptime_metasrv_gc_failed_regions_total",
130        "Total regions that failed GC",
131    )
132    .unwrap();
133
134}
135
136#[cfg(feature = "enterprise")]
137lazy_static! {
138    /// Soft-drop purge submissions by status.
139    pub static ref METRIC_META_GC_SOFT_DROP_PURGES_TOTAL: IntCounterVec = register_int_counter_vec!(
140        "greptime_metasrv_gc_soft_drop_purges_total",
141        "Soft-drop purge submissions by status",
142        &["status"],
143    )
144    .unwrap();
145}