frontend/
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    /// Timer of handling query in RPC handler.
20    pub static ref GRPC_HANDLE_QUERY_ELAPSED: HistogramVec = register_histogram_vec!(
21        "greptime_frontend_grpc_handle_query_elapsed",
22        "Elapsed time of handling queries in RPC handler",
23        &["type"],
24        vec![0.005, 0.01, 0.05, 0.1, 0.5, 1.0, 5.0, 10.0, 60.0, 300.0]
25    )
26    .unwrap();
27    pub static ref GRPC_HANDLE_SQL_ELAPSED: Histogram = GRPC_HANDLE_QUERY_ELAPSED
28        .with_label_values(&["sql"]);
29    pub static ref GRPC_HANDLE_PLAN_ELAPSED: Histogram = GRPC_HANDLE_QUERY_ELAPSED
30        .with_label_values(&["plan"]);
31    pub static ref GRPC_HANDLE_PROMQL_ELAPSED: Histogram = GRPC_HANDLE_QUERY_ELAPSED
32        .with_label_values(&["promql"]);
33
34    pub static ref PROMQL_QUERY_METRICS_ELAPSED: HistogramVec = register_histogram_vec!(
35        "greptime_frontend_promql_query_metrics_elapsed",
36        "frontend promql query metric names elapsed",
37        &["db"]
38    )
39    .unwrap();
40
41    /// The number of OpenTelemetry metrics send by frontend node.
42    pub static ref OTLP_METRICS_ROWS: IntCounter = register_int_counter!(
43        "greptime_frontend_otlp_metrics_rows",
44        "frontend otlp metrics rows"
45    )
46    .unwrap();
47
48    /// The number of OpenTelemetry traces send by frontend node.
49    pub static ref OTLP_TRACES_ROWS: IntCounter = register_int_counter!(
50        "greptime_frontend_otlp_traces_rows",
51        "frontend otlp traces rows"
52    )
53    .unwrap();
54
55    /// The number of OpenTelemetry logs send by frontend node.
56    pub static ref OTLP_LOGS_ROWS: IntCounter = register_int_counter!(
57        "greptime_frontend_otlp_logs_rows",
58        "frontend otlp logs rows"
59    )
60    .unwrap();
61
62    /// The number of heartbeats send by frontend node.
63    pub static ref HEARTBEAT_SENT_COUNT: IntCounter = register_int_counter!(
64        "greptime_frontend_heartbeat_send_count",
65        "frontend heartbeat sent",
66    )
67    .unwrap();
68    /// The number of heartbeats received by frontend node, labeled with result type.
69    pub static ref HEARTBEAT_RECV_COUNT: IntCounterVec = register_int_counter_vec!(
70        "greptime_frontend_heartbeat_recv_count",
71        "frontend heartbeat received",
72        &["result"]
73    )
74    .unwrap();
75}