Skip to main content

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 common_frontend::metrics::{CACHE_HIT, CACHE_MISS};
16use lazy_static::lazy_static;
17use prometheus::*;
18
19lazy_static! {
20    /// Timer of handling query in RPC handler.
21    pub static ref GRPC_HANDLE_QUERY_ELAPSED: HistogramVec = register_histogram_vec!(
22        "greptime_frontend_grpc_handle_query_elapsed",
23        "Elapsed time of handling queries in RPC handler",
24        &["type"],
25        vec![0.005, 0.01, 0.05, 0.1, 0.5, 1.0, 5.0, 10.0, 60.0, 300.0]
26    )
27    .unwrap();
28    pub static ref GRPC_HANDLE_SQL_ELAPSED: Histogram = GRPC_HANDLE_QUERY_ELAPSED
29        .with_label_values(&["sql"]);
30    pub static ref GRPC_HANDLE_PLAN_ELAPSED: Histogram = GRPC_HANDLE_QUERY_ELAPSED
31        .with_label_values(&["plan"]);
32    pub static ref GRPC_HANDLE_PROMQL_ELAPSED: Histogram = GRPC_HANDLE_QUERY_ELAPSED
33        .with_label_values(&["promql"]);
34
35    pub static ref PROMQL_QUERY_METRICS_ELAPSED: HistogramVec = register_histogram_vec!(
36        "greptime_frontend_promql_query_metrics_elapsed",
37        "frontend promql query metric names elapsed",
38        &["db"]
39    )
40    .unwrap();
41
42    /// The number of OpenTelemetry metrics send by frontend node.
43    pub static ref OTLP_METRICS_ROWS: IntCounter = register_int_counter!(
44        "greptime_frontend_otlp_metrics_rows",
45        "frontend otlp metrics rows"
46    )
47    .unwrap();
48
49    /// Failed writes of the synthesized OTLP resource descriptor table; these
50    /// surface as OTLP partial-success warnings, not request failures.
51    pub static ref OTLP_RESOURCE_INFO_WRITE_ERRORS: IntCounter = register_int_counter!(
52        "greptime_frontend_otlp_resource_info_write_errors",
53        "frontend otlp resource descriptor write errors"
54    )
55    .unwrap();
56
57    /// The number of OpenTelemetry traces send by frontend node.
58    pub static ref OTLP_TRACES_ROWS: IntCounter = register_int_counter!(
59        "greptime_frontend_otlp_traces_rows",
60        "frontend otlp traces rows"
61    )
62    .unwrap();
63
64    /// The number of OpenTelemetry trace ingest failures on the frontend node.
65    pub static ref OTLP_TRACES_FAILURE_COUNT: IntCounterVec = register_int_counter_vec!(
66        "greptime_frontend_otlp_traces_failure_count",
67        "frontend otlp trace ingest failure count",
68        &["label"]
69    )
70    .unwrap();
71
72    /// Initial trace auxiliary-cache lookups, excluding admission and write rechecks.
73    pub static ref OTLP_TRACE_AUX_CACHE_HIT: IntCounter =
74        CACHE_HIT.with_label_values(&["otlp_trace_aux"]);
75    pub static ref OTLP_TRACE_AUX_CACHE_MISS: IntCounter =
76        CACHE_MISS.with_label_values(&["otlp_trace_aux"]);
77
78    /// The number of OpenTelemetry logs send by frontend node.
79    pub static ref OTLP_LOGS_ROWS: IntCounter = register_int_counter!(
80        "greptime_frontend_otlp_logs_rows",
81        "frontend otlp logs rows"
82    )
83    .unwrap();
84
85    /// The number of heartbeats send by frontend node.
86    pub static ref HEARTBEAT_SENT_COUNT: IntCounter = register_int_counter!(
87        "greptime_frontend_heartbeat_send_count",
88        "frontend heartbeat sent",
89    )
90    .unwrap();
91    /// The number of heartbeats received by frontend node, labeled with result type.
92    pub static ref HEARTBEAT_RECV_COUNT: IntCounterVec = register_int_counter_vec!(
93        "greptime_frontend_heartbeat_recv_count",
94        "frontend heartbeat received",
95        &["result"]
96    )
97    .unwrap();
98}