Skip to main content

datanode/
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
18/// Region request type label.
19pub const REGION_REQUEST_TYPE: &str = "datanode_region_request_type";
20const REGION_REQUEST_CODE: &str = "code";
21
22pub const REGION_ROLE: &str = "region_role";
23pub const REGION_ID: &str = "region_id";
24pub const RESULT_TYPE: &str = "result";
25
26lazy_static! {
27    /// The elapsed time of handling a request in the region_server.
28    pub static ref HANDLE_REGION_REQUEST_ELAPSED: HistogramVec = register_histogram_vec!(
29        "greptime_datanode_handle_region_request_elapsed",
30        "datanode handle region request elapsed",
31        &[REGION_REQUEST_TYPE]
32    )
33    .unwrap();
34    /// The number of rows in region request received by region server, labeled with request type.
35    pub static ref REGION_CHANGED_ROW_COUNT: IntCounterVec = register_int_counter_vec!(
36        "greptime_datanode_region_changed_row_count",
37        "datanode region changed row count",
38        &[REGION_REQUEST_TYPE]
39    )
40    .unwrap();
41    /// The elapsed time since the last received heartbeat.
42    pub static ref LAST_RECEIVED_HEARTBEAT_ELAPSED: IntGauge = register_int_gauge!(
43        "greptime_last_received_heartbeat_lease_elapsed",
44        "last received heartbeat lease elapsed",
45    )
46    .unwrap();
47    /// The elapsed time since the last sent heartbeat.
48    pub static ref LAST_SENT_HEARTBEAT_ELAPSED: IntGauge = register_int_gauge!(
49        "greptime_last_sent_heartbeat_lease_elapsed",
50        "last sent heartbeat lease elapsed",
51    )
52    .unwrap();
53    pub static ref LEASE_EXPIRED_REGION: IntGaugeVec = register_int_gauge_vec!(
54        "greptime_lease_expired_region",
55        "lease expired region",
56        &[REGION_ID]
57    )
58    .unwrap();
59    /// The received region leases via heartbeat.
60    pub static ref HEARTBEAT_REGION_LEASES: IntGaugeVec = register_int_gauge_vec!(
61        "greptime_heartbeat_region_leases",
62        "received region leases via heartbeat",
63        &[REGION_ROLE]
64    )
65    .unwrap();
66    /// The number of heartbeats send by datanode.
67    pub static ref HEARTBEAT_SENT_COUNT: IntCounter = register_int_counter!(
68        "greptime_datanode_heartbeat_send_count",
69        "datanode heartbeat sent",
70    )
71    .unwrap();
72    /// The number of heartbeats received by datanode, labeled with result type.
73    pub static ref HEARTBEAT_RECV_COUNT: IntCounterVec = register_int_counter_vec!(
74        "greptime_datanode_heartbeat_recv_count",
75        "datanode heartbeat received",
76        &[RESULT_TYPE]
77    )
78    .unwrap();
79
80    /// Total count of failed region server requests.
81    pub static ref REGION_SERVER_REQUEST_FAILURE_COUNT: IntCounterVec = register_int_counter_vec!(
82        "greptime_datanode_region_request_fail_count",
83        "failed region server requests count",
84        &[REGION_REQUEST_TYPE]
85    )
86    .unwrap();
87
88    /// Ingest-task join failures, labeled by request type and reason (`panic` or `cancelled`).
89    /// Counts tasks, not write entries: a failed task can leave entry outcomes unknown.
90    pub static ref INGEST_TASK_FAILURES_TOTAL: IntCounterVec = register_int_counter_vec!(
91        "greptime_datanode_ingest_task_failures_total",
92        "Ingest-task join failures, not failed write entries",
93        &[REGION_REQUEST_TYPE, "reason"]
94    )
95    .unwrap();
96
97    /// Failed region open attempts, including individual and batch requests.
98    /// Counts every request in an engine group when no individual results are available.
99    /// Failed retries count separately; explicitly ignored missing regions do not count.
100    pub static ref REGION_OPEN_FAILURES_TOTAL: IntCounterVec = register_int_counter_vec!(
101        "greptime_datanode_region_open_failures_total",
102        "Failed region open attempts, including retries and all requests in failed engine groups, excluding ignored missing regions",
103        &["engine", "status_code"]
104    )
105    .unwrap();
106
107    /// Total count of failed insert requests to region server, labeled with request
108    /// type and status code.
109    pub static ref REGION_SERVER_INSERT_FAIL_COUNT: IntCounterVec = register_int_counter_vec!(
110        "greptime_datanode_region_failed_insert_count",
111        "failed region server insert requests count",
112        &[REGION_REQUEST_TYPE, REGION_REQUEST_CODE]
113    )
114    .unwrap();
115
116    /// Remote dynamic filter update processing outcomes, labeled with the outcome.
117    pub static ref REMOTE_DYN_FILTER_UPDATE_OUTCOME_TOTAL: IntCounterVec = register_int_counter_vec!(
118        "greptime_datanode_remote_dyn_filter_update_outcome_total",
119        "remote dynamic filter update processing outcomes",
120        &["result"]
121    )
122    .unwrap();
123
124    /// Remote dynamic filter update drops, labeled with drop reason.
125    pub static ref REMOTE_DYN_FILTER_UPDATE_DROP_TOTAL: IntCounterVec = register_int_counter_vec!(
126        "greptime_datanode_remote_dyn_filter_update_drop_total",
127        "remote dynamic filter update drops by reason",
128        &["reason"]
129    )
130    .unwrap();
131
132    /// Remote dynamic filter unregister outcomes, labeled with the outcome.
133    pub static ref REMOTE_DYN_FILTER_UNREGISTER_TOTAL: IntCounterVec = register_int_counter_vec!(
134        "greptime_datanode_remote_dyn_filter_unregister_total",
135        "remote dynamic filter unregister outcomes",
136        &["result"]
137    )
138    .unwrap();
139
140    /// Current count of remote dynamic filter registry entries.
141    pub static ref REMOTE_DYN_FILTER_REGISTRY_ENTRIES: IntGauge = register_int_gauge!(
142        "greptime_datanode_remote_dyn_filter_registry_entries",
143        "current remote dynamic filter registry entry count",
144    )
145    .unwrap();
146
147    /// Remote dynamic filter accepted update payload bytes received.
148    pub static ref REMOTE_DYN_FILTER_PAYLOAD_BYTES: Histogram = register_histogram!(
149        "greptime_datanode_remote_dyn_filter_payload_bytes",
150        "remote dynamic filter accepted update payload bytes received",
151        vec![
152            128.0, 256.0, 512.0, 1024.0, 2048.0, 4096.0, 8192.0, 16384.0, 32768.0,
153            65536.0, 131072.0, 262144.0, 524288.0,
154        ]
155    )
156    .unwrap();
157}