Coverage Report

Created: 2026-07-12 08:23

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(binlog_compaction_task_running_total, MetricUnit::ROWSETS, "",
107
                                     compaction_task_state_total, Labels({{"type", "binlog"}}));
108
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(binlog_compaction_task_pending_total, MetricUnit::ROWSETS, "",
109
                                     compaction_task_state_total, Labels({{"type", "binlog"}}));
110
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_task_running_total, MetricUnit::ROWSETS,
111
                                     "", compaction_task_state_total,
112
                                     Labels({{"type", "cumulative"}}));
113
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_task_pending_total, MetricUnit::ROWSETS,
114
                                     "", compaction_task_state_total,
115
                                     Labels({{"type", "cumulative"}}));
116
117
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(segment_read_total, MetricUnit::OPERATIONS,
118
                                     "(segment_v2) total number of segments read", segment_read,
119
                                     Labels({{"type", "segment_read_total"}}));
120
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(
121
        segment_row_total, MetricUnit::ROWS,
122
        "(segment_v2) total number of rows in queried segments (before index pruning)",
123
        segment_read, Labels({{"type", "segment_row_total"}}));
124
125
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(condition_cache_search_count, MetricUnit::OPERATIONS,
126
                                     "number of condition cache lookups when digest != 0",
127
                                     condition_cache, Labels({{"type", "condition_cache_search"}}));
128
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(condition_cache_hit_count, MetricUnit::OPERATIONS,
129
                                     "number of condition cache hits", condition_cache,
130
                                     Labels({{"type", "condition_cache_hit"}}));
131
132
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_begin_request_total, MetricUnit::OPERATIONS,
133
                                     "", stream_load_txn_request, Labels({{"type", "begin"}}));
134
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_commit_request_total, MetricUnit::OPERATIONS,
135
                                     "", stream_load_txn_request, Labels({{"type", "commit"}}));
136
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_rollback_request_total, MetricUnit::OPERATIONS,
137
                                     "", stream_load_txn_request, Labels({{"type", "rollback"}}));
138
139
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_receive_bytes_total, MetricUnit::BYTES, "", stream_load,
140
                                     Labels({{"type", "receive_bytes"}}));
141
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_rows_total, MetricUnit::ROWS, "", stream_load,
142
                                     Labels({{"type", "load_rows"}}));
143
144
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(compaction_producer_callback_a_round_time,
145
                                     MetricUnit::ROWSETS);
146
147
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_read_rows_total, MetricUnit::ROWS, "",
148
                                     compaction_rows_total, Labels({{"type", "read"}}));
149
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_read_bytes_total, MetricUnit::BYTES, "",
150
                                     compaction_bytes_total, Labels({{"type", "read"}}));
151
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_write_rows_total, MetricUnit::ROWS, "",
152
                                     compaction_rows_total, Labels({{"type", "write"}}));
153
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_write_bytes_total, MetricUnit::BYTES, "",
154
                                     compaction_bytes_total, Labels({{"type", "write"}}));
155
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_read_rows_total, MetricUnit::ROWS, "",
156
                                     compaction_rows_total, Labels({{"type", "read"}}));
157
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_read_bytes_total, MetricUnit::BYTES, "",
158
                                     compaction_bytes_total, Labels({{"type", "read"}}));
159
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_write_rows_total, MetricUnit::ROWS, "",
160
                                     compaction_rows_total, Labels({{"type", "write"}}));
161
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_write_bytes_total, MetricUnit::BYTES, "",
162
                                     compaction_bytes_total, Labels({{"type", "write"}}));
163
164
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(load_rows, MetricUnit::ROWS);
165
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(load_bytes, MetricUnit::BYTES);
166
167
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_get_msg_latency, MetricUnit::MILLISECONDS);
168
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_get_msg_count, MetricUnit::NOUNIT);
169
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_consume_rows, MetricUnit::ROWS);
170
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_consume_bytes, MetricUnit::BYTES);
171
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_get_records_latency,
172
                                     MetricUnit::MILLISECONDS);
173
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_get_records_count, MetricUnit::NOUNIT);
174
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_throttle_count, MetricUnit::NOUNIT);
175
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_retriable_error_count,
176
                                     MetricUnit::NOUNIT);
177
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_closed_shard_count, MetricUnit::NOUNIT);
178
179
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(memtable_flush_total, MetricUnit::OPERATIONS);
180
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(memtable_flush_duration_us, MetricUnit::MICROSECONDS);
181
182
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(memory_pool_bytes_total, MetricUnit::BYTES);
183
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(process_thread_num, MetricUnit::NOUNIT);
184
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(process_fd_num_used, MetricUnit::NOUNIT);
185
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(process_fd_num_limit_soft, MetricUnit::NOUNIT);
186
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(process_fd_num_limit_hard, MetricUnit::NOUNIT);
187
188
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_cumulative_max_compaction_score, MetricUnit::NOUNIT);
189
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_base_max_compaction_score, MetricUnit::NOUNIT);
190
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_binlog_max_compaction_score, MetricUnit::NOUNIT);
191
192
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(all_rowsets_num, MetricUnit::NOUNIT);
193
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(all_segments_num, MetricUnit::NOUNIT);
194
195
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(compaction_used_permits, MetricUnit::NOUNIT);
196
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(binlog_compaction_used_permits, MetricUnit::NOUNIT);
197
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(compaction_waitting_permits, MetricUnit::NOUNIT);
198
199
DEFINE_HISTOGRAM_METRIC_PROTOTYPE_2ARG(tablet_version_num_distribution, MetricUnit::NOUNIT);
200
201
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_scan_bytes_per_second, MetricUnit::BYTES);
202
203
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(readable_blocks_total, MetricUnit::BLOCKS);
204
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(writable_blocks_total, MetricUnit::BLOCKS);
205
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(blocks_created_total, MetricUnit::OPERATIONS);
206
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(blocks_deleted_total, MetricUnit::OPERATIONS);
207
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(bytes_read_total, MetricUnit::BYTES);
208
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(bytes_written_total, MetricUnit::BYTES);
209
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(disk_sync_total, MetricUnit::OPERATIONS);
210
211
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(blocks_open_reading, MetricUnit::BLOCKS);
212
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(blocks_open_writing, MetricUnit::BLOCKS);
213
214
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_memory_total_byte, MetricUnit::BYTES);
215
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_sql_total_count, MetricUnit::NOUNIT);
216
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_partition_total_count, MetricUnit::NOUNIT);
217
218
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(upload_total_byte, MetricUnit::BYTES);
219
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(upload_rowset_count, MetricUnit::ROWSETS);
220
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(upload_fail_count, MetricUnit::ROWSETS);
221
222
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_file_reader_total, MetricUnit::FILESYSTEM);
223
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_reader_total, MetricUnit::FILESYSTEM);
224
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(hdfs_file_reader_total, MetricUnit::FILESYSTEM);
225
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(broker_file_reader_total, MetricUnit::FILESYSTEM);
226
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_file_writer_total, MetricUnit::FILESYSTEM);
227
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_writer_total, MetricUnit::FILESYSTEM);
228
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_created_total, MetricUnit::FILESYSTEM);
229
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_created_total, MetricUnit::FILESYSTEM);
230
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_bytes_read_total, MetricUnit::FILESYSTEM);
231
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_bytes_read_total, MetricUnit::FILESYSTEM);
232
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_bytes_written_total, MetricUnit::FILESYSTEM);
233
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_bytes_written_total, MetricUnit::FILESYSTEM);
234
235
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(local_file_open_reading, MetricUnit::FILESYSTEM);
236
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(s3_file_open_reading, MetricUnit::FILESYSTEM);
237
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(hdfs_file_open_reading, MetricUnit::FILESYSTEM);
238
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(broker_file_open_reading, MetricUnit::FILESYSTEM);
239
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(local_file_open_writing, MetricUnit::FILESYSTEM);
240
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(s3_file_open_writing, MetricUnit::FILESYSTEM);
241
242
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_total, MetricUnit::OPERATIONS);
243
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_cache, MetricUnit::OPERATIONS);
244
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_remote, MetricUnit::OPERATIONS);
245
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_peer, MetricUnit::OPERATIONS);
246
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(inverted_index_bytes_read_from_remote, MetricUnit::BYTES);
247
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(segment_footer_index_bytes_read_from_remote,
248
                                     MetricUnit::BYTES);
249
250
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(udf_close_bthread_count, MetricUnit::OPERATIONS);
251
252
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_ctx_cnt, MetricUnit::NOUNIT);
253
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_ctx_cnt, MetricUnit::NOUNIT);
254
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_cnt, MetricUnit::NOUNIT);
255
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_task_cnt, MetricUnit::NOUNIT);
256
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(pipeline_task_queue_size, MetricUnit::NOUNIT);
257
258
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_num, MetricUnit::NOUNIT);
259
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_ready_num, MetricUnit::NOUNIT);
260
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_wait_ready_ms,
261
                                     MetricUnit::MILLISECONDS);
262
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_timeout_num, MetricUnit::NOUNIT);
263
264
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(get_remote_tablet_slow_time_ms, MetricUnit::MILLISECONDS);
265
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(get_remote_tablet_slow_cnt, MetricUnit::NOUNIT);
266
267
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_load_costs_ms, MetricUnit::MILLISECONDS);
268
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_load_cnt, MetricUnit::NOUNIT);
269
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_search_costs_ms, MetricUnit::MILLISECONDS);
270
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_search_cnt, MetricUnit::NOUNIT);
271
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_fetch_page_costs_ms, MetricUnit::MILLISECONDS);
272
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_fetch_page_cnt, MetricUnit::NOUNIT);
273
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_search_costs_ms, MetricUnit::MILLISECONDS);
274
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_search_cnt, MetricUnit::NOUNIT);
275
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_cache_hit_cnt, MetricUnit::NOUNIT);
276
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_cache_miss_cnt, MetricUnit::NOUNIT);
277
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_in_memory_cnt, MetricUnit::NOUNIT);
278
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_in_memory_rows_cnt, MetricUnit::ROWS);
279
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_construction, MetricUnit::NOUNIT);
280
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_build_index_threads, MetricUnit::NOUNIT);
281
282
const std::string DorisMetrics::_s_registry_name = "doris_be";
283
const std::string DorisMetrics::_s_hook_name = "doris_metrics";
284
285
8
DorisMetrics::DorisMetrics() : _metric_registry(_s_registry_name) {
286
8
    _server_metric_entity = _metric_registry.register_entity("server");
287
288
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, fragment_requests_total);
289
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, fragment_request_duration_us);
290
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes);
291
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_from_local);
292
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_from_remote);
293
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_rows);
294
295
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_requests_success_total);
296
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_requests_fail_total);
297
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_duration_us);
298
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_write_bytes);
299
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_write_rows);
300
301
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, compaction_producer_callback_a_round_time);
302
303
    // engine_requests_total
304
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_tablet_requests_total);
305
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_tablet_requests_failed);
306
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, drop_tablet_requests_total);
307
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, report_all_tablets_requests_skip);
308
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, schema_change_requests_total);
309
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, schema_change_requests_failed);
310
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_rollup_requests_total);
311
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_rollup_requests_failed);
312
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_requests_total);
313
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_v2_requests_total);
314
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_v2_requests_failed);
315
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, delete_requests_total);
316
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, delete_requests_failed);
317
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, clone_requests_total);
318
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, clone_requests_failed);
319
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, finish_task_requests_total);
320
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, finish_task_requests_failed);
321
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_request_total);
322
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_request_failed);
323
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_request_total);
324
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_request_failed);
325
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, publish_task_request_total);
326
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, publish_task_failed_total);
327
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, alter_inverted_index_requests_total);
328
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, alter_inverted_index_requests_failed);
329
330
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_read_rows_total);
331
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_read_bytes_total);
332
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_write_rows_total);
333
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_write_bytes_total);
334
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_read_rows_total);
335
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_read_bytes_total);
336
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_write_rows_total);
337
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_write_bytes_total);
338
339
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_deltas_total);
340
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_bytes_total);
341
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_deltas_total);
342
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_bytes_total);
343
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, full_compaction_deltas_total);
344
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, full_compaction_bytes_total);
345
346
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_task_running_total);
347
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_task_pending_total);
348
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, binlog_compaction_task_running_total);
349
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, binlog_compaction_task_pending_total);
350
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_task_running_total);
351
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_task_pending_total);
352
353
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_read_total);
354
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, condition_cache_search_count);
355
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, condition_cache_hit_count);
356
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_row_total);
357
358
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_begin_request_total);
359
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_commit_request_total);
360
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_rollback_request_total);
361
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_receive_bytes_total);
362
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_rows_total);
363
364
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_get_msg_latency);
365
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_get_msg_count);
366
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_consume_bytes);
367
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_consume_rows);
368
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_get_records_latency);
369
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_get_records_count);
370
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_throttle_count);
371
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_retriable_error_count);
372
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_closed_shard_count);
373
374
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, memtable_flush_total);
375
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, memtable_flush_duration_us);
376
377
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, memory_pool_bytes_total);
378
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_thread_num);
379
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_used);
380
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_limit_soft);
381
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_limit_hard);
382
383
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_cumulative_max_compaction_score);
384
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_base_max_compaction_score);
385
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_binlog_max_compaction_score);
386
387
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, all_rowsets_num);
388
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, all_segments_num);
389
390
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_used_permits);
391
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, binlog_compaction_used_permits);
392
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_waitting_permits);
393
394
8
    HISTOGRAM_METRIC_REGISTER(_server_metric_entity, tablet_version_num_distribution);
395
396
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_per_second);
397
398
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, load_rows);
399
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, load_bytes);
400
401
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, upload_total_byte);
402
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, upload_rowset_count);
403
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, upload_fail_count);
404
405
8
    _server_metric_entity->register_hook(_s_hook_name, std::bind(&DorisMetrics::_update, this));
406
407
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_memory_total_byte);
408
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_sql_total_count);
409
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_partition_total_count);
410
411
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_file_reader_total);
412
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_reader_total);
413
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, hdfs_file_reader_total);
414
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, broker_file_reader_total);
415
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_file_writer_total);
416
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_writer_total);
417
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, file_created_total);
418
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_created_total);
419
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_bytes_read_total);
420
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_bytes_read_total);
421
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_bytes_written_total);
422
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_bytes_written_total);
423
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, local_file_open_reading);
424
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, s3_file_open_reading);
425
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, hdfs_file_open_reading);
426
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, broker_file_open_reading);
427
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, local_file_open_writing);
428
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, s3_file_open_writing);
429
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_total);
430
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_cache);
431
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_remote);
432
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_peer);
433
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, inverted_index_bytes_read_from_remote);
434
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_footer_index_bytes_read_from_remote);
435
436
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, udf_close_bthread_count);
437
438
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_ctx_cnt);
439
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_ctx_cnt);
440
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_cnt);
441
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_task_cnt);
442
443
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_num);
444
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_ready_num);
445
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_wait_ready_ms);
446
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_timeout_num);
447
448
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, get_remote_tablet_slow_time_ms);
449
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, get_remote_tablet_slow_cnt);
450
451
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, pipeline_task_queue_size);
452
453
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_load_costs_ms);
454
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_load_cnt);
455
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_search_costs_ms);
456
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_search_cnt);
457
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_fetch_page_costs_ms);
458
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_fetch_page_cnt);
459
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_search_costs_ms);
460
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_search_cnt);
461
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_cache_hit_cnt);
462
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_cache_miss_cnt);
463
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_in_memory_cnt);
464
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_in_memory_rows_cnt);
465
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_construction);
466
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_build_index_threads);
467
8
}
468
469
void DorisMetrics::initialize(bool init_system_metrics, const std::set<std::string>& disk_devices,
470
7
                              const std::vector<std::string>& network_interfaces) {
471
7
    if (init_system_metrics) {
472
5
        _system_metrics.reset(
473
5
                new SystemMetrics(&_metric_registry, disk_devices, network_interfaces));
474
5
    }
475
7
}
476
477
7
void DorisMetrics::init_jvm_metrics() {
478
7
    _jvm_metrics.reset(new JvmMetrics(&_metric_registry));
479
7
}
480
481
1.22k
void DorisMetrics::_update() {
482
1.22k
    _update_process_thread_num();
483
1.22k
    _update_process_fd_num();
484
1.22k
}
485
486
// get num of thread of doris_be process
487
// from /proc/self/task
488
1.22k
void DorisMetrics::_update_process_thread_num() {
489
1.22k
    std::error_code ec;
490
1.22k
    std::filesystem::directory_iterator dict_iter("/proc/self/task/", ec);
491
1.22k
    if (ec) {
492
0
        LOG(WARNING) << "failed to count thread num: " << ec.message();
493
0
        process_thread_num->set_value(0);
494
0
        return;
495
0
    }
496
1.22k
    int64_t count =
497
3.70M
            std::count_if(dict_iter, std::filesystem::end(dict_iter), [](const auto& entry) {
498
3.70M
                std::error_code error_code;
499
3.70M
                return entry.is_directory(error_code) && !error_code;
500
3.70M
            });
501
502
1.22k
    process_thread_num->set_value(count);
503
1.22k
}
504
505
// get num of file descriptor of doris_be process
506
1.22k
void DorisMetrics::_update_process_fd_num() {
507
    // fd used
508
1.22k
    std::error_code ec;
509
1.22k
    std::filesystem::directory_iterator dict_iter("/proc/self/fd/", ec);
510
1.22k
    if (ec) {
511
0
        LOG(WARNING) << "failed to count fd: " << ec.message();
512
0
        process_fd_num_used->set_value(0);
513
0
        return;
514
0
    }
515
1.22k
    int64_t count =
516
3.75M
            std::count_if(dict_iter, std::filesystem::end(dict_iter), [](const auto& entry) {
517
3.75M
                std::error_code error_code;
518
3.75M
                return entry.is_regular_file(error_code) && !error_code;
519
3.75M
            });
520
521
1.22k
    process_fd_num_used->set_value(count);
522
523
    // fd limits
524
1.22k
    FILE* fp = fopen("/proc/self/limits", "r");
525
1.22k
    if (fp == nullptr) {
526
0
        char buf[64];
527
0
        LOG(WARNING) << "open /proc/self/limits failed, errno=" << errno
528
0
                     << ", message=" << strerror_r(errno, buf, 64);
529
0
        return;
530
0
    }
531
532
    // /proc/self/limits
533
    // Max open files            65536                65536                files
534
1.22k
    int64_t values[2];
535
1.22k
    size_t line_buf_size = 0;
536
1.22k
    char* line_ptr = nullptr;
537
11.0k
    while (getline(&line_ptr, &line_buf_size, fp) > 0) {
538
11.0k
        memset(values, 0, sizeof(values));
539
11.0k
        int num = sscanf(line_ptr, "Max open files %" PRId64 " %" PRId64, &values[0], &values[1]);
540
11.0k
        if (num == 2) {
541
1.22k
            process_fd_num_limit_soft->set_value(values[0]);
542
1.22k
            process_fd_num_limit_hard->set_value(values[1]);
543
1.22k
            break;
544
1.22k
        }
545
11.0k
    }
546
547
1.22k
    if (line_ptr != nullptr) {
548
1.22k
        free(line_ptr);
549
1.22k
    }
550
551
1.22k
    if (ferror(fp) != 0) {
552
0
        char buf[64];
553
0
        LOG(WARNING) << "getline failed, errno=" << errno
554
                     << ", message=" << strerror_r(errno, buf, 64);
555
0
    }
556
1.22k
    fclose(fp);
557
1.22k
}
558
559
} // namespace doris