Coverage Report

Created: 2026-11-02 13:31

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_3ARG(query_cache_stale_hit_total, MetricUnit::REQUESTS,
52
                                     "Query cache decisions that reused a stale entry by "
53
                                     "incremental merge.");
54
DEFINE_COUNTER_METRIC_PROTOTYPE_3ARG(query_cache_incremental_fallback_total, MetricUnit::REQUESTS,
55
                                     "Query cache decisions that could have merged incrementally "
56
                                     "but fell back to a full recompute.");
57
DEFINE_COUNTER_METRIC_PROTOTYPE_3ARG(query_cache_write_back_total, MetricUnit::REQUESTS,
58
                                     "Query cache entries handed to the cache to be written back "
59
                                     "(full or merged); admission may still turn one down.");
60
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(push_requests_success_total, MetricUnit::REQUESTS, "",
61
                                     push_requests_total, Labels({{"status", "SUCCESS"}}));
62
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(push_requests_fail_total, MetricUnit::REQUESTS, "",
63
                                     push_requests_total, Labels({{"status", "FAIL"}}));
64
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(push_request_duration_us, MetricUnit::MICROSECONDS);
65
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(push_request_write_bytes, MetricUnit::BYTES);
66
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(push_request_write_rows, MetricUnit::ROWS);
67
68
#define DEFINE_ENGINE_COUNTER_METRIC(name, type, status)                                        \
69
    DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(name, MetricUnit::REQUESTS, "", engine_requests_total, \
70
                                         Labels({{"type", #type}, {"status", #status}}));
71
72
DEFINE_ENGINE_COUNTER_METRIC(create_tablet_requests_total, create_tablet, total);
73
DEFINE_ENGINE_COUNTER_METRIC(create_tablet_requests_failed, create_tablet, failed);
74
DEFINE_ENGINE_COUNTER_METRIC(drop_tablet_requests_total, drop_tablet, total);
75
DEFINE_ENGINE_COUNTER_METRIC(report_all_tablets_requests_skip, report_all_tablets, skip)
76
DEFINE_ENGINE_COUNTER_METRIC(schema_change_requests_total, schema_change, total);
77
DEFINE_ENGINE_COUNTER_METRIC(schema_change_requests_failed, schema_change, failed);
78
DEFINE_ENGINE_COUNTER_METRIC(create_rollup_requests_total, create_rollup, total);
79
DEFINE_ENGINE_COUNTER_METRIC(create_rollup_requests_failed, create_rollup, failed);
80
DEFINE_ENGINE_COUNTER_METRIC(storage_migrate_requests_total, storage_migrate, total);
81
DEFINE_ENGINE_COUNTER_METRIC(storage_migrate_v2_requests_total, storage_migrate_v2, total);
82
DEFINE_ENGINE_COUNTER_METRIC(storage_migrate_v2_requests_failed, storage_migrate_v2, failed);
83
DEFINE_ENGINE_COUNTER_METRIC(delete_requests_total, delete, total);
84
DEFINE_ENGINE_COUNTER_METRIC(delete_requests_failed, delete, failed);
85
DEFINE_ENGINE_COUNTER_METRIC(clone_requests_total, clone, total);
86
DEFINE_ENGINE_COUNTER_METRIC(clone_requests_failed, clone, failed);
87
DEFINE_ENGINE_COUNTER_METRIC(finish_task_requests_total, finish_task, total);
88
DEFINE_ENGINE_COUNTER_METRIC(finish_task_requests_failed, finish_task, failed);
89
DEFINE_ENGINE_COUNTER_METRIC(base_compaction_request_total, base_compaction, total);
90
DEFINE_ENGINE_COUNTER_METRIC(base_compaction_request_failed, base_compaction, failed);
91
DEFINE_ENGINE_COUNTER_METRIC(cumulative_compaction_request_total, cumulative_compaction, total);
92
DEFINE_ENGINE_COUNTER_METRIC(cumulative_compaction_request_failed, cumulative_compaction, failed);
93
DEFINE_ENGINE_COUNTER_METRIC(publish_task_request_total, publish, total);
94
DEFINE_ENGINE_COUNTER_METRIC(publish_task_failed_total, publish, failed);
95
DEFINE_ENGINE_COUNTER_METRIC(alter_inverted_index_requests_total, alter_inverted_index, total);
96
DEFINE_ENGINE_COUNTER_METRIC(alter_inverted_index_requests_failed, alter_inverted_index, failed);
97
98
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(base_compaction_deltas_total, MetricUnit::ROWSETS, "",
99
                                     compaction_deltas_total, Labels({{"type", "base"}}));
100
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_deltas_total, MetricUnit::ROWSETS, "",
101
                                     compaction_deltas_total, Labels({{"type", "cumulative"}}));
102
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(full_compaction_deltas_total, MetricUnit::ROWSETS, "",
103
                                     compaction_deltas_total, Labels({{"type", "full"}}));
104
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(base_compaction_bytes_total, MetricUnit::BYTES, "",
105
                                     compaction_bytes_total, Labels({{"type", "base"}}));
106
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_bytes_total, MetricUnit::BYTES, "",
107
                                     compaction_bytes_total, Labels({{"type", "cumulative"}}));
108
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(full_compaction_bytes_total, MetricUnit::BYTES, "",
109
                                     compaction_bytes_total, Labels({{"type", "full"}}));
110
111
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(base_compaction_task_running_total, MetricUnit::ROWSETS, "",
112
                                     compaction_task_state_total, Labels({{"type", "base"}}));
113
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(base_compaction_task_pending_total, MetricUnit::ROWSETS, "",
114
                                     compaction_task_state_total, Labels({{"type", "base"}}));
115
// ATTN(changelog-rename): formerly "type"="binlog"
116
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(changelog_compaction_task_running_total, MetricUnit::ROWSETS,
117
                                     "", compaction_task_state_total,
118
                                     Labels({{"type", "changelog"}}));
119
// ATTN(changelog-rename): formerly "type"="binlog"
120
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(changelog_compaction_task_pending_total, MetricUnit::ROWSETS,
121
                                     "", compaction_task_state_total,
122
                                     Labels({{"type", "changelog"}}));
123
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_task_running_total, MetricUnit::ROWSETS,
124
                                     "", compaction_task_state_total,
125
                                     Labels({{"type", "cumulative"}}));
126
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(cumulative_compaction_task_pending_total, MetricUnit::ROWSETS,
127
                                     "", compaction_task_state_total,
128
                                     Labels({{"type", "cumulative"}}));
129
130
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(changelog_ttl_cleanup_success_total, MetricUnit::OPERATIONS,
131
                                     "", changelog_ttl_cleanup_total,
132
                                     Labels({{"result", "success"}}));
133
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(changelog_ttl_cleanup_failed_total, MetricUnit::OPERATIONS, "",
134
                                     changelog_ttl_cleanup_total, Labels({{"result", "failed"}}));
135
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(changelog_ttl_reclaimed_bytes_total, MetricUnit::BYTES);
136
137
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(segment_read_total, MetricUnit::OPERATIONS,
138
                                     "(segment_v2) total number of segments read", segment_read,
139
                                     Labels({{"type", "segment_read_total"}}));
140
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(
141
        segment_row_total, MetricUnit::ROWS,
142
        "(segment_v2) total number of rows in queried segments (before index pruning)",
143
        segment_read, Labels({{"type", "segment_row_total"}}));
144
145
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(condition_cache_search_count, MetricUnit::OPERATIONS,
146
                                     "number of condition cache lookups when digest != 0",
147
                                     condition_cache, Labels({{"type", "condition_cache_search"}}));
148
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(condition_cache_hit_count, MetricUnit::OPERATIONS,
149
                                     "number of condition cache hits", condition_cache,
150
                                     Labels({{"type", "condition_cache_hit"}}));
151
152
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_begin_request_total, MetricUnit::OPERATIONS,
153
                                     "", stream_load_txn_request, Labels({{"type", "begin"}}));
154
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_commit_request_total, MetricUnit::OPERATIONS,
155
                                     "", stream_load_txn_request, Labels({{"type", "commit"}}));
156
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_txn_rollback_request_total, MetricUnit::OPERATIONS,
157
                                     "", stream_load_txn_request, Labels({{"type", "rollback"}}));
158
159
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_receive_bytes_total, MetricUnit::BYTES, "", stream_load,
160
                                     Labels({{"type", "receive_bytes"}}));
161
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(stream_load_rows_total, MetricUnit::ROWS, "", stream_load,
162
                                     Labels({{"type", "load_rows"}}));
163
164
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(compaction_producer_callback_a_round_time,
165
                                     MetricUnit::ROWSETS);
166
167
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_read_rows_total, MetricUnit::ROWS, "",
168
                                     compaction_rows_total, Labels({{"type", "read"}}));
169
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_read_bytes_total, MetricUnit::BYTES, "",
170
                                     compaction_bytes_total, Labels({{"type", "read"}}));
171
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_write_rows_total, MetricUnit::ROWS, "",
172
                                     compaction_rows_total, Labels({{"type", "write"}}));
173
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(local_compaction_write_bytes_total, MetricUnit::BYTES, "",
174
                                     compaction_bytes_total, Labels({{"type", "write"}}));
175
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_read_rows_total, MetricUnit::ROWS, "",
176
                                     compaction_rows_total, Labels({{"type", "read"}}));
177
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_read_bytes_total, MetricUnit::BYTES, "",
178
                                     compaction_bytes_total, Labels({{"type", "read"}}));
179
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_write_rows_total, MetricUnit::ROWS, "",
180
                                     compaction_rows_total, Labels({{"type", "write"}}));
181
DEFINE_COUNTER_METRIC_PROTOTYPE_5ARG(remote_compaction_write_bytes_total, MetricUnit::BYTES, "",
182
                                     compaction_bytes_total, Labels({{"type", "write"}}));
183
184
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(load_rows, MetricUnit::ROWS);
185
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(load_bytes, MetricUnit::BYTES);
186
187
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_get_msg_latency, MetricUnit::MILLISECONDS);
188
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_get_msg_count, MetricUnit::NOUNIT);
189
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_consume_rows, MetricUnit::ROWS);
190
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_consume_bytes, MetricUnit::BYTES);
191
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_get_records_latency,
192
                                     MetricUnit::MILLISECONDS);
193
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_get_records_count, MetricUnit::NOUNIT);
194
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_throttle_count, MetricUnit::NOUNIT);
195
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_retriable_error_count,
196
                                     MetricUnit::NOUNIT);
197
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(routine_load_kinesis_closed_shard_count, MetricUnit::NOUNIT);
198
199
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(memtable_flush_total, MetricUnit::OPERATIONS);
200
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(memtable_flush_duration_us, MetricUnit::MICROSECONDS);
201
202
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(memory_pool_bytes_total, MetricUnit::BYTES);
203
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(process_thread_num, MetricUnit::NOUNIT);
204
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(process_fd_num_used, MetricUnit::NOUNIT);
205
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(process_fd_num_limit_soft, MetricUnit::NOUNIT);
206
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(process_fd_num_limit_hard, MetricUnit::NOUNIT);
207
208
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_cumulative_max_compaction_score, MetricUnit::NOUNIT);
209
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_size_based_max_compaction_score, MetricUnit::NOUNIT);
210
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_time_series_max_compaction_score, MetricUnit::NOUNIT);
211
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_base_max_compaction_score, MetricUnit::NOUNIT);
212
// ATTN(changelog-rename): formerly "tablet_binlog_max_compaction_score"
213
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(tablet_changelog_max_compaction_score, MetricUnit::NOUNIT);
214
215
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(all_rowsets_num, MetricUnit::NOUNIT);
216
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(all_segments_num, MetricUnit::NOUNIT);
217
218
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(compaction_used_permits, MetricUnit::NOUNIT);
219
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(compaction_waitting_permits, MetricUnit::NOUNIT);
220
221
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(changelog_ttl_last_success_timestamp_seconds,
222
                                   MetricUnit::SECONDS);
223
224
DEFINE_HISTOGRAM_METRIC_PROTOTYPE_2ARG(tablet_version_num_distribution, MetricUnit::NOUNIT);
225
226
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_scan_bytes_per_second, MetricUnit::BYTES);
227
228
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(readable_blocks_total, MetricUnit::BLOCKS);
229
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(writable_blocks_total, MetricUnit::BLOCKS);
230
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(blocks_created_total, MetricUnit::OPERATIONS);
231
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(blocks_deleted_total, MetricUnit::OPERATIONS);
232
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(bytes_read_total, MetricUnit::BYTES);
233
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(bytes_written_total, MetricUnit::BYTES);
234
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(disk_sync_total, MetricUnit::OPERATIONS);
235
236
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(blocks_open_reading, MetricUnit::BLOCKS);
237
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(blocks_open_writing, MetricUnit::BLOCKS);
238
239
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_memory_total_byte, MetricUnit::BYTES);
240
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_sql_total_count, MetricUnit::NOUNIT);
241
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(query_cache_partition_total_count, MetricUnit::NOUNIT);
242
243
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(upload_total_byte, MetricUnit::BYTES);
244
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(upload_rowset_count, MetricUnit::ROWSETS);
245
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(upload_fail_count, MetricUnit::ROWSETS);
246
247
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_file_reader_total, MetricUnit::FILESYSTEM);
248
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_reader_total, MetricUnit::FILESYSTEM);
249
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(hdfs_file_reader_total, MetricUnit::FILESYSTEM);
250
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(broker_file_reader_total, MetricUnit::FILESYSTEM);
251
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_file_writer_total, MetricUnit::FILESYSTEM);
252
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_writer_total, MetricUnit::FILESYSTEM);
253
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(file_created_total, MetricUnit::FILESYSTEM);
254
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_file_created_total, MetricUnit::FILESYSTEM);
255
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_bytes_read_total, MetricUnit::FILESYSTEM);
256
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_bytes_read_total, MetricUnit::FILESYSTEM);
257
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(local_bytes_written_total, MetricUnit::FILESYSTEM);
258
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(s3_bytes_written_total, MetricUnit::FILESYSTEM);
259
260
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(local_file_open_reading, MetricUnit::FILESYSTEM);
261
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(s3_file_open_reading, MetricUnit::FILESYSTEM);
262
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(hdfs_file_open_reading, MetricUnit::FILESYSTEM);
263
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(broker_file_open_reading, MetricUnit::FILESYSTEM);
264
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(local_file_open_writing, MetricUnit::FILESYSTEM);
265
DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(s3_file_open_writing, MetricUnit::FILESYSTEM);
266
267
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_total, MetricUnit::OPERATIONS);
268
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_cache, MetricUnit::OPERATIONS);
269
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_remote, MetricUnit::OPERATIONS);
270
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(num_io_bytes_read_from_peer, MetricUnit::OPERATIONS);
271
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(inverted_index_bytes_read_from_remote, MetricUnit::BYTES);
272
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(segment_footer_index_bytes_read_from_remote,
273
                                     MetricUnit::BYTES);
274
275
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(udf_close_bthread_count, MetricUnit::OPERATIONS);
276
277
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_ctx_cnt, MetricUnit::NOUNIT);
278
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_ctx_cnt, MetricUnit::NOUNIT);
279
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_cnt, MetricUnit::NOUNIT);
280
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_task_cnt, MetricUnit::NOUNIT);
281
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(pipeline_task_queue_size, MetricUnit::NOUNIT);
282
283
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_num, MetricUnit::NOUNIT);
284
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_ready_num, MetricUnit::NOUNIT);
285
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_wait_ready_ms,
286
                                     MetricUnit::MILLISECONDS);
287
DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_timeout_num, MetricUnit::NOUNIT);
288
289
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(get_remote_tablet_slow_time_ms, MetricUnit::MILLISECONDS);
290
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(get_remote_tablet_slow_cnt, MetricUnit::NOUNIT);
291
292
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_load_costs_ms, MetricUnit::MILLISECONDS);
293
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_load_cnt, MetricUnit::NOUNIT);
294
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_search_costs_ms, MetricUnit::MILLISECONDS);
295
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_search_cnt, MetricUnit::NOUNIT);
296
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_fetch_page_costs_ms, MetricUnit::MILLISECONDS);
297
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_fetch_page_cnt, MetricUnit::NOUNIT);
298
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_search_costs_ms, MetricUnit::MILLISECONDS);
299
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_search_cnt, MetricUnit::NOUNIT);
300
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_cache_hit_cnt, MetricUnit::NOUNIT);
301
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_cache_miss_cnt, MetricUnit::NOUNIT);
302
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_in_memory_cnt, MetricUnit::NOUNIT);
303
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_in_memory_rows_cnt, MetricUnit::ROWS);
304
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_construction, MetricUnit::NOUNIT);
305
DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_build_index_threads, MetricUnit::NOUNIT);
306
307
const std::string DorisMetrics::_s_registry_name = "doris_be";
308
const std::string DorisMetrics::_s_hook_name = "doris_metrics";
309
310
8
DorisMetrics::DorisMetrics() : _metric_registry(_s_registry_name) {
311
8
    _server_metric_entity = _metric_registry.register_entity("server");
312
313
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, fragment_requests_total);
314
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, fragment_request_duration_us);
315
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes);
316
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_from_local);
317
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_from_remote);
318
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_rows);
319
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_cache_stale_hit_total);
320
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_cache_incremental_fallback_total);
321
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_cache_write_back_total);
322
323
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_requests_success_total);
324
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_requests_fail_total);
325
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_duration_us);
326
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_write_bytes);
327
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_write_rows);
328
329
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, compaction_producer_callback_a_round_time);
330
331
    // engine_requests_total
332
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_tablet_requests_total);
333
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_tablet_requests_failed);
334
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, drop_tablet_requests_total);
335
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, report_all_tablets_requests_skip);
336
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, schema_change_requests_total);
337
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, schema_change_requests_failed);
338
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_rollup_requests_total);
339
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_rollup_requests_failed);
340
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_requests_total);
341
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_v2_requests_total);
342
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_v2_requests_failed);
343
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, delete_requests_total);
344
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, delete_requests_failed);
345
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, clone_requests_total);
346
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, clone_requests_failed);
347
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, finish_task_requests_total);
348
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, finish_task_requests_failed);
349
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_request_total);
350
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_request_failed);
351
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_request_total);
352
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_request_failed);
353
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, publish_task_request_total);
354
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, publish_task_failed_total);
355
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, alter_inverted_index_requests_total);
356
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, alter_inverted_index_requests_failed);
357
358
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_read_rows_total);
359
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_read_bytes_total);
360
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_write_rows_total);
361
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_write_bytes_total);
362
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_read_rows_total);
363
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_read_bytes_total);
364
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_write_rows_total);
365
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_write_bytes_total);
366
367
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_deltas_total);
368
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_bytes_total);
369
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_deltas_total);
370
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_bytes_total);
371
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, full_compaction_deltas_total);
372
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, full_compaction_bytes_total);
373
374
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_task_running_total);
375
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_task_pending_total);
376
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, changelog_compaction_task_running_total);
377
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, changelog_compaction_task_pending_total);
378
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_task_running_total);
379
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_task_pending_total);
380
381
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, changelog_ttl_cleanup_success_total);
382
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, changelog_ttl_cleanup_failed_total);
383
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, changelog_ttl_reclaimed_bytes_total);
384
385
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_read_total);
386
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, condition_cache_search_count);
387
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, condition_cache_hit_count);
388
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_row_total);
389
390
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_begin_request_total);
391
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_commit_request_total);
392
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_rollback_request_total);
393
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_receive_bytes_total);
394
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_rows_total);
395
396
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_get_msg_latency);
397
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_get_msg_count);
398
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_consume_bytes);
399
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_consume_rows);
400
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_get_records_latency);
401
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_get_records_count);
402
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_throttle_count);
403
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_retriable_error_count);
404
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_closed_shard_count);
405
406
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, memtable_flush_total);
407
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, memtable_flush_duration_us);
408
409
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, memory_pool_bytes_total);
410
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_thread_num);
411
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_used);
412
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_limit_soft);
413
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_limit_hard);
414
415
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_cumulative_max_compaction_score);
416
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_size_based_max_compaction_score);
417
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_time_series_max_compaction_score);
418
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_base_max_compaction_score);
419
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_changelog_max_compaction_score);
420
421
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, all_rowsets_num);
422
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, all_segments_num);
423
424
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_used_permits);
425
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_waitting_permits);
426
427
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, changelog_ttl_last_success_timestamp_seconds);
428
429
8
    HISTOGRAM_METRIC_REGISTER(_server_metric_entity, tablet_version_num_distribution);
430
431
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_per_second);
432
433
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, load_rows);
434
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, load_bytes);
435
436
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, upload_total_byte);
437
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, upload_rowset_count);
438
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, upload_fail_count);
439
440
8
    _server_metric_entity->register_hook(_s_hook_name, std::bind(&DorisMetrics::_update, this));
441
442
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_memory_total_byte);
443
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_sql_total_count);
444
8
    INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_partition_total_count);
445
446
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_file_reader_total);
447
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_reader_total);
448
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, hdfs_file_reader_total);
449
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, broker_file_reader_total);
450
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_file_writer_total);
451
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_writer_total);
452
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, file_created_total);
453
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_created_total);
454
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_bytes_read_total);
455
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_bytes_read_total);
456
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_bytes_written_total);
457
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_bytes_written_total);
458
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, local_file_open_reading);
459
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, s3_file_open_reading);
460
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, hdfs_file_open_reading);
461
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, broker_file_open_reading);
462
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, local_file_open_writing);
463
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, s3_file_open_writing);
464
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_total);
465
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_cache);
466
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_remote);
467
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_peer);
468
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, inverted_index_bytes_read_from_remote);
469
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_footer_index_bytes_read_from_remote);
470
471
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, udf_close_bthread_count);
472
473
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_ctx_cnt);
474
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_ctx_cnt);
475
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_cnt);
476
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_task_cnt);
477
478
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_num);
479
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_ready_num);
480
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_wait_ready_ms);
481
8
    INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_timeout_num);
482
483
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, get_remote_tablet_slow_time_ms);
484
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, get_remote_tablet_slow_cnt);
485
486
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, pipeline_task_queue_size);
487
488
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_load_costs_ms);
489
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_load_cnt);
490
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_search_costs_ms);
491
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_search_cnt);
492
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_fetch_page_costs_ms);
493
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_fetch_page_cnt);
494
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_search_costs_ms);
495
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_search_cnt);
496
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_cache_hit_cnt);
497
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_cache_miss_cnt);
498
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_in_memory_cnt);
499
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_in_memory_rows_cnt);
500
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_construction);
501
8
    INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_build_index_threads);
502
8
}
503
504
void DorisMetrics::initialize(bool init_system_metrics, const std::set<std::string>& disk_devices,
505
7
                              const std::vector<std::string>& network_interfaces) {
506
7
    if (init_system_metrics) {
507
6
        _system_metrics.reset(
508
6
                new SystemMetrics(&_metric_registry, disk_devices, network_interfaces));
509
6
    }
510
7
}
511
512
3
void DorisMetrics::init_jvm_metrics() {
513
3
    _jvm_metrics.reset(new JvmMetrics(&_metric_registry));
514
3
    _jvm_metrics_view.store(_jvm_metrics.get(), std::memory_order_release);
515
3
}
516
517
362
void DorisMetrics::_update() {
518
362
    _update_process_thread_num();
519
362
    _update_process_fd_num();
520
362
}
521
522
// get num of thread of doris_be process
523
// from /proc/self/task
524
362
void DorisMetrics::_update_process_thread_num() {
525
362
    std::error_code ec;
526
362
    std::filesystem::directory_iterator dict_iter("/proc/self/task/", ec);
527
362
    if (ec) {
528
0
        LOG(WARNING) << "failed to count thread num: " << ec.message();
529
0
        process_thread_num->set_value(0);
530
0
        return;
531
0
    }
532
362
    int64_t count =
533
1.09M
            std::count_if(dict_iter, std::filesystem::end(dict_iter), [](const auto& entry) {
534
1.09M
                std::error_code error_code;
535
1.09M
                return entry.is_directory(error_code) && !error_code;
536
1.09M
            });
537
538
362
    process_thread_num->set_value(count);
539
362
}
540
541
// get num of file descriptor of doris_be process
542
361
void DorisMetrics::_update_process_fd_num() {
543
    // fd used
544
361
    std::error_code ec;
545
361
    std::filesystem::directory_iterator dict_iter("/proc/self/fd/", ec);
546
361
    if (ec) {
547
0
        LOG(WARNING) << "failed to count fd: " << ec.message();
548
0
        process_fd_num_used->set_value(0);
549
0
        return;
550
0
    }
551
    // Entries under /proc/self/fd are symlinks, and every is_regular_file() call
552
    // follows the link with a stat(), which is O(fds) syscalls and can stall
553
    // /metrics for hundreds of milliseconds when there are many open fds.
554
    // Count the entries directly (readdir only) to avoid the per-entry stat.
555
361
    int64_t count = 0;
556
1.04M
    for (const auto& entry : dict_iter) {
557
1.04M
        (void)entry;
558
1.04M
        ++count;
559
1.04M
    }
560
561
361
    process_fd_num_used->set_value(count);
562
563
    // fd limits
564
361
    FILE* fp = fopen("/proc/self/limits", "r");
565
361
    if (fp == nullptr) {
566
0
        char buf[64];
567
0
        LOG(WARNING) << "open /proc/self/limits failed, errno=" << errno
568
0
                     << ", message=" << strerror_r(errno, buf, 64);
569
0
        return;
570
0
    }
571
572
    // /proc/self/limits
573
    // Max open files            65536                65536                files
574
361
    int64_t values[2];
575
361
    size_t line_buf_size = 0;
576
361
    char* line_ptr = nullptr;
577
3.24k
    while (getline(&line_ptr, &line_buf_size, fp) > 0) {
578
3.24k
        memset(values, 0, sizeof(values));
579
3.24k
        int num = sscanf(line_ptr, "Max open files %" PRId64 " %" PRId64, &values[0], &values[1]);
580
3.24k
        if (num == 2) {
581
361
            process_fd_num_limit_soft->set_value(values[0]);
582
361
            process_fd_num_limit_hard->set_value(values[1]);
583
361
            break;
584
361
        }
585
3.24k
    }
586
587
361
    if (line_ptr != nullptr) {
588
361
        free(line_ptr);
589
361
    }
590
591
361
    if (ferror(fp) != 0) {
592
0
        char buf[64];
593
0
        LOG(WARNING) << "getline failed, errno=" << errno
594
                     << ", message=" << strerror_r(errno, buf, 64);
595
0
    }
596
361
    fclose(fp);
597
361
}
598
599
} // namespace doris