Coverage Report

Created: 2026-05-28 07:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/common/metrics/doris_metrics.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "common/metrics/doris_metrics.h"
19
20
// IWYU pragma: no_include <bthread/errno.h>
21
#include <errno.h> // IWYU pragma: keep
22
#include <glog/logging.h>
23
#include <inttypes.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <string.h>
27
#include <unistd.h>
28
29
#include <algorithm>
30
#include <functional>
31
#include <ostream>
32
33
#include "common/metrics/metrics.h"
34
#include "common/metrics/system_metrics.h"
35
#include "common/status.h"
36
#include "io/fs/local_file_system.h"
37
38
namespace doris {
39
namespace io {
40
struct FileInfo;
41
} // namespace io
42
43
DEFINE_COUNTER_METRIC_PROTOTYPE_3ARG(fragment_requests_total, MetricUnit::REQUESTS,
44
                                     "Total fragment requests received.");
45
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(fragment_request_duration_us, MetricUnit::MICROSECONDS);
46
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_scan_bytes, MetricUnit::BYTES);
47
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_scan_bytes_from_local, MetricUnit::BYTES);
48
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_scan_bytes_from_remote, MetricUnit::BYTES);
49
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_scan_rows, MetricUnit::ROWS);
50
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_scan_count, MetricUnit::NOUNIT);
51
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(push_requests_success_total, MetricUnit::REQUESTS, "",
52
                                     push_requests_total, Labels({{"status", "SUCCESS"}}));
53
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(push_requests_fail_total, MetricUnit::REQUESTS, "",
54
                                     push_requests_total, Labels({{"status", "FAIL"}}));
55
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(push_request_duration_us, MetricUnit::MICROSECONDS);
56
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(push_request_write_bytes, MetricUnit::BYTES);
57
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(push_request_write_rows, MetricUnit::ROWS);
58
59
#define DEFINE_ENGINE_COUNTER_METRIC(name, type, status)                                        \
60
    DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(name, MetricUnit::REQUESTS, "", engine_requests_total, \
61
                                         Labels({{"type", #type}, {"status", #status}}));
62
63
DEFINE_ENGINE_COUNTER_METRIC(create_tablet_requests_total, create_tablet, total);
64
DEFINE_ENGINE_COUNTER_METRIC(create_tablet_requests_failed, create_tablet, failed);
65
DEFINE_ENGINE_COUNTER_METRIC(drop_tablet_requests_total, drop_tablet, total);
66
DEFINE_ENGINE_COUNTER_METRIC(report_all_tablets_requests_skip, report_all_tablets, skip)
67
DEFINE_ENGINE_COUNTER_METRIC(schema_change_requests_total, schema_change, total);
68
DEFINE_ENGINE_COUNTER_METRIC(schema_change_requests_failed, schema_change, failed);
69
DEFINE_ENGINE_COUNTER_METRIC(create_rollup_requests_total, create_rollup, total);
70
DEFINE_ENGINE_COUNTER_METRIC(create_rollup_requests_failed, create_rollup, failed);
71
DEFINE_ENGINE_COUNTER_METRIC(storage_migrate_requests_total, storage_migrate, total);
72
DEFINE_ENGINE_COUNTER_METRIC(storage_migrate_v2_requests_total, storage_migrate_v2, total);
73
DEFINE_ENGINE_COUNTER_METRIC(storage_migrate_v2_requests_failed, storage_migrate_v2, failed);
74
DEFINE_ENGINE_COUNTER_METRIC(delete_requests_total, delete, total);
75
DEFINE_ENGINE_COUNTER_METRIC(delete_requests_failed, delete, failed);
76
DEFINE_ENGINE_COUNTER_METRIC(clone_requests_total, clone, total);
77
DEFINE_ENGINE_COUNTER_METRIC(clone_requests_failed, clone, failed);
78
DEFINE_ENGINE_COUNTER_METRIC(finish_task_requests_total, finish_task, total);
79
DEFINE_ENGINE_COUNTER_METRIC(finish_task_requests_failed, finish_task, failed);
80
DEFINE_ENGINE_COUNTER_METRIC(base_compaction_request_total, base_compaction, total);
81
DEFINE_ENGINE_COUNTER_METRIC(base_compaction_request_failed, base_compaction, failed);
82
DEFINE_ENGINE_COUNTER_METRIC(cumulative_compaction_request_total, cumulative_compaction, total);
83
DEFINE_ENGINE_COUNTER_METRIC(cumulative_compaction_request_failed, cumulative_compaction, failed);
84
DEFINE_ENGINE_COUNTER_METRIC(publish_task_request_total, publish, total);
85
DEFINE_ENGINE_COUNTER_METRIC(publish_task_failed_total, publish, failed);
86
DEFINE_ENGINE_COUNTER_METRIC(alter_inverted_index_requests_total, alter_inverted_index, total);
87
DEFINE_ENGINE_COUNTER_METRIC(alter_inverted_index_requests_failed, alter_inverted_index, failed);
88
89
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(base_compaction_deltas_total, MetricUnit::ROWSETS, "",
90
                                     compaction_deltas_total, Labels({{"type", "base"}}));
91
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_deltas_total, MetricUnit::ROWSETS, "",
92
                                     compaction_deltas_total, Labels({{"type", "cumulative"}}));
93
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(full_compaction_deltas_total, MetricUnit::ROWSETS, "",
94
                                     compaction_deltas_total, Labels({{"type", "full"}}));
95
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(base_compaction_bytes_total, MetricUnit::BYTES, "",
96
                                     compaction_bytes_total, Labels({{"type", "base"}}));
97
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_bytes_total, MetricUnit::BYTES, "",
98
                                     compaction_bytes_total, Labels({{"type", "cumulative"}}));
99
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(full_compaction_bytes_total, MetricUnit::BYTES, "",
100
                                     compaction_bytes_total, Labels({{"type", "full"}}));
101
102
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(base_compaction_task_running_total, MetricUnit::ROWSETS, "",
103
                                     compaction_task_state_total, Labels({{"type", "base"}}));
104
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(base_compaction_task_pending_total, MetricUnit::ROWSETS, "",
105
                                     compaction_task_state_total, Labels({{"type", "base"}}));
106
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_task_running_total, MetricUnit::ROWSETS,
107
                                     "", compaction_task_state_total,
108
                                     Labels({{"type", "cumulative"}}));
109
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_task_pending_total, MetricUnit::ROWSETS,
110
                                     "", compaction_task_state_total,
111
                                     Labels({{"type", "cumulative"}}));
112
113
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(segment_read_total, MetricUnit::OPERATIONS,
114
                                     "(segment_v2) total number of segments read", segment_read,
115
                                     Labels({{"type", "segment_read_total"}}));
116
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(
117
        segment_row_total, MetricUnit::ROWS,
118
        "(segment_v2) total number of rows in queried segments (before index pruning)",
119
        segment_read, Labels({{"type", "segment_row_total"}}));
120
121
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(condition_cache_search_count, MetricUnit::OPERATIONS,
122
                                     "number of condition cache lookups when digest != 0",
123
                                     condition_cache, Labels({{"type", "condition_cache_search"}}));
124
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(condition_cache_hit_count, MetricUnit::OPERATIONS,
125
                                     "number of condition cache hits", condition_cache,
126
                                     Labels({{"type", "condition_cache_hit"}}));
127
128
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_begin_request_total, MetricUnit::OPERATIONS,
129
                                     "", stream_load_txn_request, Labels({{"type", "begin"}}));
130
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_commit_request_total, MetricUnit::OPERATIONS,
131
                                     "", stream_load_txn_request, Labels({{"type", "commit"}}));
132
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_rollback_request_total, MetricUnit::OPERATIONS,
133
                                     "", stream_load_txn_request, Labels({{"type", "rollback"}}));
134
135
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_receive_bytes_total, MetricUnit::BYTES, "", stream_load,
136
                                     Labels({{"type", "receive_bytes"}}));
137
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_rows_total, MetricUnit::ROWS, "", stream_load,
138
                                     Labels({{"type", "load_rows"}}));
139
140
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(compaction_producer_callback_a_round_time,
141
                                     MetricUnit::ROWSETS);
142
143
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_read_rows_total, MetricUnit::ROWS, "",
144
                                     compaction_rows_total, Labels({{"type", "read"}}));
145
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_read_bytes_total, MetricUnit::BYTES, "",
146
                                     compaction_bytes_total, Labels({{"type", "read"}}));
147
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_write_rows_total, MetricUnit::ROWS, "",
148
                                     compaction_rows_total, Labels({{"type", "write"}}));
149
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_write_bytes_total, MetricUnit::BYTES, "",
150
                                     compaction_bytes_total, Labels({{"type", "write"}}));
151
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_read_rows_total, MetricUnit::ROWS, "",
152
                                     compaction_rows_total, Labels({{"type", "read"}}));
153
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_read_bytes_total, MetricUnit::BYTES, "",
154
                                     compaction_bytes_total, Labels({{"type", "read"}}));
155
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_write_rows_total, MetricUnit::ROWS, "",
156
                                     compaction_rows_total, Labels({{"type", "write"}}));
157
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_write_bytes_total, MetricUnit::BYTES, "",
158
                                     compaction_bytes_total, Labels({{"type", "write"}}));
159
160
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(load_rows, MetricUnit::ROWS);
161
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(load_bytes, MetricUnit::BYTES);
162
163
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_get_msg_latency, MetricUnit::MILLISECONDS);
164
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_get_msg_count, MetricUnit::NOUNIT);
165
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_consume_rows, MetricUnit::ROWS);
166
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_consume_bytes, MetricUnit::BYTES);
167
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_get_records_latency,
168
                                     MetricUnit::MILLISECONDS);
169
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_get_records_count, MetricUnit::NOUNIT);
170
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_throttle_count, MetricUnit::NOUNIT);
171
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_retriable_error_count,
172
                                     MetricUnit::NOUNIT);
173
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_closed_shard_count, MetricUnit::NOUNIT);
174
175
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(memtable_flush_total, MetricUnit::OPERATIONS);
176
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(memtable_flush_duration_us, MetricUnit::MICROSECONDS);
177
178
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(memory_pool_bytes_total, MetricUnit::BYTES);
179
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(process_thread_num, MetricUnit::NOUNIT);
180
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(process_fd_num_used, MetricUnit::NOUNIT);
181
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(process_fd_num_limit_soft, MetricUnit::NOUNIT);
182
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(process_fd_num_limit_hard, MetricUnit::NOUNIT);
183
184
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_cumulative_max_compaction_score, MetricUnit::NOUNIT);
185
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_base_max_compaction_score, MetricUnit::NOUNIT);
186
187
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(all_rowsets_num, MetricUnit::NOUNIT);
188
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(all_segments_num, MetricUnit::NOUNIT);
189
190
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(compaction_used_permits, MetricUnit::NOUNIT);
191
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(compaction_waitting_permits, MetricUnit::NOUNIT);
192
193
DEFINE_HISTOGRAM_METRIC_PROTOTYPE_2ARG(tablet_version_num_distribution, MetricUnit::NOUNIT);
194
195
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_scan_bytes_per_second, MetricUnit::BYTES);
196
197
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(readable_blocks_total, MetricUnit::BLOCKS);
198
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(writable_blocks_total, MetricUnit::BLOCKS);
199
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(blocks_created_total, MetricUnit::OPERATIONS);
200
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(blocks_deleted_total, MetricUnit::OPERATIONS);
201
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(bytes_read_total, MetricUnit::BYTES);
202
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(bytes_written_total, MetricUnit::BYTES);
203
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(disk_sync_total, MetricUnit::OPERATIONS);
204
205
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(blocks_open_reading, MetricUnit::BLOCKS);
206
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(blocks_open_writing, MetricUnit::BLOCKS);
207
208
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_memory_total_byte, MetricUnit::BYTES);
209
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_sql_total_count, MetricUnit::NOUNIT);
210
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_partition_total_count, MetricUnit::NOUNIT);
211
212
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(upload_total_byte, MetricUnit::BYTES);
213
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(upload_rowset_count, MetricUnit::ROWSETS);
214
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(upload_fail_count, MetricUnit::ROWSETS);
215
216
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_file_reader_total, MetricUnit::FILESYSTEM);
217
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_reader_total, MetricUnit::FILESYSTEM);
218
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(hdfs_file_reader_total, MetricUnit::FILESYSTEM);
219
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(broker_file_reader_total, MetricUnit::FILESYSTEM);
220
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_file_writer_total, MetricUnit::FILESYSTEM);
221
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_writer_total, MetricUnit::FILESYSTEM);
222
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_created_total, MetricUnit::FILESYSTEM);
223
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_created_total, MetricUnit::FILESYSTEM);
224
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_bytes_read_total, MetricUnit::FILESYSTEM);
225
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_bytes_read_total, MetricUnit::FILESYSTEM);
226
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_bytes_written_total, MetricUnit::FILESYSTEM);
227
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_bytes_written_total, MetricUnit::FILESYSTEM);
228
229
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(local_file_open_reading, MetricUnit::FILESYSTEM);
230
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(s3_file_open_reading, MetricUnit::FILESYSTEM);
231
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(hdfs_file_open_reading, MetricUnit::FILESYSTEM);
232
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(broker_file_open_reading, MetricUnit::FILESYSTEM);
233
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(local_file_open_writing, MetricUnit::FILESYSTEM);
234
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(s3_file_open_writing, MetricUnit::FILESYSTEM);
235
236
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_total, MetricUnit::OPERATIONS);
237
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_cache, MetricUnit::OPERATIONS);
238
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_remote, MetricUnit::OPERATIONS);
239
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_peer, MetricUnit::OPERATIONS);
240
241
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(udf_close_bthread_count, MetricUnit::OPERATIONS);
242
243
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_ctx_cnt, MetricUnit::NOUNIT);
244
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_ctx_cnt, MetricUnit::NOUNIT);
245
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_cnt, MetricUnit::NOUNIT);
246
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_task_cnt, MetricUnit::NOUNIT);
247
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(pipeline_task_queue_size, MetricUnit::NOUNIT);
248
249
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_num, MetricUnit::NOUNIT);
250
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_ready_num, MetricUnit::NOUNIT);
251
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_wait_ready_ms,
252
                                     MetricUnit::MILLISECONDS);
253
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_timeout_num, MetricUnit::NOUNIT);
254
255
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(get_remote_tablet_slow_time_ms, MetricUnit::MILLISECONDS);
256
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(get_remote_tablet_slow_cnt, MetricUnit::NOUNIT);
257
258
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_load_costs_ms, MetricUnit::MILLISECONDS);
259
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_load_cnt, MetricUnit::NOUNIT);
260
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_search_costs_ms, MetricUnit::MILLISECONDS);
261
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_search_cnt, MetricUnit::NOUNIT);
262
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_fetch_page_costs_ms, MetricUnit::MILLISECONDS);
263
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_fetch_page_cnt, MetricUnit::NOUNIT);
264
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_search_costs_ms, MetricUnit::MILLISECONDS);
265
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_search_cnt, MetricUnit::NOUNIT);
266
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_cache_hit_cnt, MetricUnit::NOUNIT);
267
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_cache_miss_cnt, MetricUnit::NOUNIT);
268
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_in_memory_cnt, MetricUnit::NOUNIT);
269
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_in_memory_rows_cnt, MetricUnit::ROWS);
270
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_construction, MetricUnit::NOUNIT);
271
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_build_index_threads, MetricUnit::NOUNIT);
272
273
const std::string DorisMetrics::_s_registry_name = "doris_be";
274
const std::string DorisMetrics::_s_hook_name = "doris_metrics";
275
276
8
DorisMetrics::DorisMetrics() : _metric_registry(_s_registry_name) {
277
8
    _server_metric_entity = _metric_registry.register_entity("server");
278
279
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, fragment_requests_total);
280
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, fragment_request_duration_us);
281
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes);
282
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_from_local);
283
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_from_remote);
284
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_rows);
285
286
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_requests_success_total);
287
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_requests_fail_total);
288
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_duration_us);
289
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_write_bytes);
290
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_write_rows);
291
292
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, compaction_producer_callback_a_round_time);
293
294
    // engine_requests_total
295
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_tablet_requests_total);
296
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_tablet_requests_failed);
297
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, drop_tablet_requests_total);
298
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, report_all_tablets_requests_skip);
299
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, schema_change_requests_total);
300
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, schema_change_requests_failed);
301
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_rollup_requests_total);
302
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_rollup_requests_failed);
303
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_requests_total);
304
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_v2_requests_total);
305
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_v2_requests_failed);
306
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, delete_requests_total);
307
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, delete_requests_failed);
308
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, clone_requests_total);
309
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, clone_requests_failed);
310
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, finish_task_requests_total);
311
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, finish_task_requests_failed);
312
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_request_total);
313
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_request_failed);
314
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_request_total);
315
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_request_failed);
316
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, publish_task_request_total);
317
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, publish_task_failed_total);
318
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, alter_inverted_index_requests_total);
319
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, alter_inverted_index_requests_failed);
320
321
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_read_rows_total);
322
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_read_bytes_total);
323
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_write_rows_total);
324
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_write_bytes_total);
325
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_read_rows_total);
326
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_read_bytes_total);
327
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_write_rows_total);
328
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_write_bytes_total);
329
330
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_deltas_total);
331
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_bytes_total);
332
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_deltas_total);
333
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_bytes_total);
334
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, full_compaction_deltas_total);
335
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, full_compaction_bytes_total);
336
337
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_task_running_total);
338
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_task_pending_total);
339
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_task_running_total);
340
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_task_pending_total);
341
342
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_read_total);
343
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, condition_cache_search_count);
344
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, condition_cache_hit_count);
345
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_row_total);
346
347
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_begin_request_total);
348
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_commit_request_total);
349
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_rollback_request_total);
350
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_receive_bytes_total);
351
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_rows_total);
352
353
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_get_msg_latency);
354
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_get_msg_count);
355
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_consume_bytes);
356
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_consume_rows);
357
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_get_records_latency);
358
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_get_records_count);
359
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_throttle_count);
360
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_retriable_error_count);
361
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_closed_shard_count);
362
363
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, memtable_flush_total);
364
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, memtable_flush_duration_us);
365
366
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, memory_pool_bytes_total);
367
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_thread_num);
368
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_used);
369
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_limit_soft);
370
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_limit_hard);
371
372
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_cumulative_max_compaction_score);
373
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_base_max_compaction_score);
374
375
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, all_rowsets_num);
376
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, all_segments_num);
377
378
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_used_permits);
379
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_waitting_permits);
380
381
8
    HISTOGRAM_METRIC_REGISTER(_server_metric_entity, tablet_version_num_distribution);
382
383
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_per_second);
384
385
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, load_rows);
386
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, load_bytes);
387
388
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, upload_total_byte);
389
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, upload_rowset_count);
390
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, upload_fail_count);
391
392
8
    _server_metric_entity->register_hook(_s_hook_name, std::bind(&DorisMetrics::_update, this));
393
394
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_memory_total_byte);
395
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_sql_total_count);
396
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_partition_total_count);
397
398
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_file_reader_total);
399
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_reader_total);
400
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, hdfs_file_reader_total);
401
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, broker_file_reader_total);
402
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_file_writer_total);
403
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_writer_total);
404
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, file_created_total);
405
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_created_total);
406
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_bytes_read_total);
407
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_bytes_read_total);
408
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_bytes_written_total);
409
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_bytes_written_total);
410
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, local_file_open_reading);
411
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, s3_file_open_reading);
412
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, hdfs_file_open_reading);
413
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, broker_file_open_reading);
414
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, local_file_open_writing);
415
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, s3_file_open_writing);
416
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_total);
417
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_cache);
418
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_remote);
419
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_peer);
420
421
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, udf_close_bthread_count);
422
423
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_ctx_cnt);
424
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_ctx_cnt);
425
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_cnt);
426
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_task_cnt);
427
428
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_num);
429
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_ready_num);
430
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_wait_ready_ms);
431
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_timeout_num);
432
433
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, get_remote_tablet_slow_time_ms);
434
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, get_remote_tablet_slow_cnt);
435
436
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, pipeline_task_queue_size);
437
438
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_load_costs_ms);
439
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_load_cnt);
440
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_search_costs_ms);
441
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_search_cnt);
442
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_fetch_page_costs_ms);
443
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_fetch_page_cnt);
444
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_search_costs_ms);
445
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_search_cnt);
446
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_cache_hit_cnt);
447
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_cache_miss_cnt);
448
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_in_memory_cnt);
449
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_in_memory_rows_cnt);
450
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_construction);
451
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_build_index_threads);
452
8
}
453
454
void DorisMetrics::initialize(bool init_system_metrics, const std::set<std::string>& disk_devices,
455
7
                              const std::vector<std::string>& network_interfaces) {
456
7
    if (init_system_metrics) {
457
1
        _system_metrics.reset(
458
1
                new SystemMetrics(&_metric_registry, disk_devices, network_interfaces));
459
1
    }
460
7
}
461
462
7
void DorisMetrics::init_jvm_metrics() {
463
7
    _jvm_metrics.reset(new JvmMetrics(&_metric_registry));
464
7
}
465
466
784
void DorisMetrics::_update() {
467
784
    _update_process_thread_num();
468
784
    _update_process_fd_num();
469
784
}
470
471
// get num of thread of doris_be process
472
// from /proc/self/task
473
784
void DorisMetrics::_update_process_thread_num() {
474
784
    std::error_code ec;
475
784
    std::filesystem::directory_iterator dict_iter("/proc/self/task/", ec);
476
784
    if (ec) {
477
0
        LOG(WARNING) << "failed to count thread num: " << ec.message();
478
0
        process_thread_num->set_value(0);
479
0
        return;
480
0
    }
481
784
    int64_t count =
482
2.23M
            std::count_if(dict_iter, std::filesystem::end(dict_iter), [](const auto& entry) {
483
2.23M
                std::error_code error_code;
484
2.23M
                return entry.is_directory(error_code) && !error_code;
485
2.23M
            });
486
487
784
    process_thread_num->set_value(count);
488
784
}
489
490
// get num of file descriptor of doris_be process
491
784
void DorisMetrics::_update_process_fd_num() {
492
    // fd used
493
784
    std::error_code ec;
494
784
    std::filesystem::directory_iterator dict_iter("/proc/self/fd/", ec);
495
784
    if (ec) {
496
0
        LOG(WARNING) << "failed to count fd: " << ec.message();
497
0
        process_fd_num_used->set_value(0);
498
0
        return;
499
0
    }
500
784
    int64_t count =
501
1.45M
            std::count_if(dict_iter, std::filesystem::end(dict_iter), [](const auto& entry) {
502
1.45M
                std::error_code error_code;
503
1.45M
                return entry.is_regular_file(error_code) && !error_code;
504
1.45M
            });
505
506
784
    process_fd_num_used->set_value(count);
507
508
    // fd limits
509
784
    FILE* fp = fopen("/proc/self/limits", "r");
510
784
    if (fp == nullptr) {
511
0
        char buf[64];
512
0
        LOG(WARNING) << "open /proc/self/limits failed, errno=" << errno
513
0
                     << ", message=" << strerror_r(errno, buf, 64);
514
0
        return;
515
0
    }
516
517
    // /proc/self/limits
518
    // Max open files            65536                65536                files
519
784
    int64_t values[2];
520
784
    size_t line_buf_size = 0;
521
784
    char* line_ptr = nullptr;
522
7.05k
    while (getline(&line_ptr, &line_buf_size, fp) > 0) {
523
7.05k
        memset(values, 0, sizeof(values));
524
7.05k
        int num = sscanf(line_ptr, "Max open files %" PRId64 " %" PRId64, &values[0], &values[1]);
525
7.05k
        if (num == 2) {
526
784
            process_fd_num_limit_soft->set_value(values[0]);
527
784
            process_fd_num_limit_hard->set_value(values[1]);
528
784
            break;
529
784
        }
530
7.05k
    }
531
532
784
    if (line_ptr != nullptr) {
533
784
        free(line_ptr);
534
784
    }
535
536
784
    if (ferror(fp) != 0) {
537
0
        char buf[64];
538
0
        LOG(WARNING) << "getline failed, errno=" << errno
539
                     << ", message=" << strerror_r(errno, buf, 64);
540
0
    }
541
784
    fclose(fp);
542
784
}
543
544
} // namespace doris