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 | | |
247 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(udf_close_bthread_count, MetricUnit::OPERATIONS); |
248 | | |
249 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(query_ctx_cnt, MetricUnit::NOUNIT); |
250 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_ctx_cnt, MetricUnit::NOUNIT); |
251 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_cnt, MetricUnit::NOUNIT); |
252 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(scanner_task_cnt, MetricUnit::NOUNIT); |
253 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(pipeline_task_queue_size, MetricUnit::NOUNIT); |
254 | | |
255 | | DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_num, MetricUnit::NOUNIT); |
256 | | DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_ready_num, MetricUnit::NOUNIT); |
257 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_wait_ready_ms, |
258 | | MetricUnit::MILLISECONDS); |
259 | | DEFINE_GAUGE_CORE_METRIC_PROTOTYPE_2ARG(runtime_filter_consumer_timeout_num, MetricUnit::NOUNIT); |
260 | | |
261 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(get_remote_tablet_slow_time_ms, MetricUnit::MILLISECONDS); |
262 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(get_remote_tablet_slow_cnt, MetricUnit::NOUNIT); |
263 | | |
264 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_load_costs_ms, MetricUnit::MILLISECONDS); |
265 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_load_cnt, MetricUnit::NOUNIT); |
266 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_search_costs_ms, MetricUnit::MILLISECONDS); |
267 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_search_cnt, MetricUnit::NOUNIT); |
268 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_fetch_page_costs_ms, MetricUnit::MILLISECONDS); |
269 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_fetch_page_cnt, MetricUnit::NOUNIT); |
270 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_search_costs_ms, MetricUnit::MILLISECONDS); |
271 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_search_cnt, MetricUnit::NOUNIT); |
272 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_cache_hit_cnt, MetricUnit::NOUNIT); |
273 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_ivf_on_disk_cache_miss_cnt, MetricUnit::NOUNIT); |
274 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_in_memory_cnt, MetricUnit::NOUNIT); |
275 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_in_memory_rows_cnt, MetricUnit::ROWS); |
276 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_construction, MetricUnit::NOUNIT); |
277 | | DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(ann_index_build_index_threads, MetricUnit::NOUNIT); |
278 | | |
279 | | const std::string DorisMetrics::_s_registry_name = "doris_be"; |
280 | | const std::string DorisMetrics::_s_hook_name = "doris_metrics"; |
281 | | |
282 | 8 | DorisMetrics::DorisMetrics() : _metric_registry(_s_registry_name) { |
283 | 8 | _server_metric_entity = _metric_registry.register_entity("server"); |
284 | | |
285 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, fragment_requests_total); |
286 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, fragment_request_duration_us); |
287 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes); |
288 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_from_local); |
289 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_from_remote); |
290 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_scan_rows); |
291 | | |
292 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_requests_success_total); |
293 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_requests_fail_total); |
294 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_duration_us); |
295 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_write_bytes); |
296 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, push_request_write_rows); |
297 | | |
298 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, compaction_producer_callback_a_round_time); |
299 | | |
300 | | // engine_requests_total |
301 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_tablet_requests_total); |
302 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_tablet_requests_failed); |
303 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, drop_tablet_requests_total); |
304 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, report_all_tablets_requests_skip); |
305 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, schema_change_requests_total); |
306 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, schema_change_requests_failed); |
307 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_rollup_requests_total); |
308 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, create_rollup_requests_failed); |
309 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_requests_total); |
310 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_v2_requests_total); |
311 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, storage_migrate_v2_requests_failed); |
312 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, delete_requests_total); |
313 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, delete_requests_failed); |
314 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, clone_requests_total); |
315 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, clone_requests_failed); |
316 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, finish_task_requests_total); |
317 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, finish_task_requests_failed); |
318 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_request_total); |
319 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_request_failed); |
320 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_request_total); |
321 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_request_failed); |
322 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, publish_task_request_total); |
323 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, publish_task_failed_total); |
324 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, alter_inverted_index_requests_total); |
325 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, alter_inverted_index_requests_failed); |
326 | | |
327 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_read_rows_total); |
328 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_read_bytes_total); |
329 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_write_rows_total); |
330 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_compaction_write_bytes_total); |
331 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_read_rows_total); |
332 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_read_bytes_total); |
333 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_write_rows_total); |
334 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, remote_compaction_write_bytes_total); |
335 | | |
336 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_deltas_total); |
337 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_bytes_total); |
338 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_deltas_total); |
339 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_bytes_total); |
340 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, full_compaction_deltas_total); |
341 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, full_compaction_bytes_total); |
342 | | |
343 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_task_running_total); |
344 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, base_compaction_task_pending_total); |
345 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, binlog_compaction_task_running_total); |
346 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, binlog_compaction_task_pending_total); |
347 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_task_running_total); |
348 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, cumulative_compaction_task_pending_total); |
349 | | |
350 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_read_total); |
351 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, condition_cache_search_count); |
352 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, condition_cache_hit_count); |
353 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, segment_row_total); |
354 | | |
355 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_begin_request_total); |
356 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_commit_request_total); |
357 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_txn_rollback_request_total); |
358 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_receive_bytes_total); |
359 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, stream_load_rows_total); |
360 | | |
361 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_get_msg_latency); |
362 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_get_msg_count); |
363 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_consume_bytes); |
364 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_consume_rows); |
365 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_get_records_latency); |
366 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_get_records_count); |
367 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_throttle_count); |
368 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_retriable_error_count); |
369 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, routine_load_kinesis_closed_shard_count); |
370 | | |
371 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, memtable_flush_total); |
372 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, memtable_flush_duration_us); |
373 | | |
374 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, memory_pool_bytes_total); |
375 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_thread_num); |
376 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_used); |
377 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_limit_soft); |
378 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, process_fd_num_limit_hard); |
379 | | |
380 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_cumulative_max_compaction_score); |
381 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_base_max_compaction_score); |
382 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, tablet_binlog_max_compaction_score); |
383 | | |
384 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, all_rowsets_num); |
385 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, all_segments_num); |
386 | | |
387 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_used_permits); |
388 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, binlog_compaction_used_permits); |
389 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, compaction_waitting_permits); |
390 | | |
391 | 8 | HISTOGRAM_METRIC_REGISTER(_server_metric_entity, tablet_version_num_distribution); |
392 | | |
393 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, query_scan_bytes_per_second); |
394 | | |
395 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, load_rows); |
396 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, load_bytes); |
397 | | |
398 | 8 | INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, upload_total_byte); |
399 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, upload_rowset_count); |
400 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, upload_fail_count); |
401 | | |
402 | 8 | _server_metric_entity->register_hook(_s_hook_name, std::bind(&DorisMetrics::_update, this)); |
403 | | |
404 | 8 | INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_memory_total_byte); |
405 | 8 | INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_sql_total_count); |
406 | 8 | INT_UGAUGE_METRIC_REGISTER(_server_metric_entity, query_cache_partition_total_count); |
407 | | |
408 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_file_reader_total); |
409 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_reader_total); |
410 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, hdfs_file_reader_total); |
411 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, broker_file_reader_total); |
412 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_file_writer_total); |
413 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_writer_total); |
414 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, file_created_total); |
415 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_file_created_total); |
416 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_bytes_read_total); |
417 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_bytes_read_total); |
418 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, local_bytes_written_total); |
419 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, s3_bytes_written_total); |
420 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, local_file_open_reading); |
421 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, s3_file_open_reading); |
422 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, hdfs_file_open_reading); |
423 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, broker_file_open_reading); |
424 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, local_file_open_writing); |
425 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, s3_file_open_writing); |
426 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_total); |
427 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_cache); |
428 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_remote); |
429 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, num_io_bytes_read_from_peer); |
430 | | |
431 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, udf_close_bthread_count); |
432 | | |
433 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, query_ctx_cnt); |
434 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_ctx_cnt); |
435 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_cnt); |
436 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, scanner_task_cnt); |
437 | | |
438 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_num); |
439 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_ready_num); |
440 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_wait_ready_ms); |
441 | 8 | INT_GAUGE_METRIC_REGISTER(_server_metric_entity, runtime_filter_consumer_timeout_num); |
442 | | |
443 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, get_remote_tablet_slow_time_ms); |
444 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, get_remote_tablet_slow_cnt); |
445 | | |
446 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, pipeline_task_queue_size); |
447 | | |
448 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_load_costs_ms); |
449 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_load_cnt); |
450 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_search_costs_ms); |
451 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_search_cnt); |
452 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_fetch_page_costs_ms); |
453 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_fetch_page_cnt); |
454 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_search_costs_ms); |
455 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_search_cnt); |
456 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_cache_hit_cnt); |
457 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_ivf_on_disk_cache_miss_cnt); |
458 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_in_memory_cnt); |
459 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_in_memory_rows_cnt); |
460 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_construction); |
461 | 8 | INT_COUNTER_METRIC_REGISTER(_server_metric_entity, ann_index_build_index_threads); |
462 | 8 | } |
463 | | |
464 | | void DorisMetrics::initialize(bool init_system_metrics, const std::set<std::string>& disk_devices, |
465 | 7 | const std::vector<std::string>& network_interfaces) { |
466 | 7 | if (init_system_metrics) { |
467 | 2 | _system_metrics.reset( |
468 | 2 | new SystemMetrics(&_metric_registry, disk_devices, network_interfaces)); |
469 | 2 | } |
470 | 7 | } |
471 | | |
472 | 7 | void DorisMetrics::init_jvm_metrics() { |
473 | 7 | _jvm_metrics.reset(new JvmMetrics(&_metric_registry)); |
474 | 7 | } |
475 | | |
476 | 373 | void DorisMetrics::_update() { |
477 | 373 | _update_process_thread_num(); |
478 | 373 | _update_process_fd_num(); |
479 | 373 | } |
480 | | |
481 | | // get num of thread of doris_be process |
482 | | // from /proc/self/task |
483 | 373 | void DorisMetrics::_update_process_thread_num() { |
484 | 373 | std::error_code ec; |
485 | 373 | std::filesystem::directory_iterator dict_iter("/proc/self/task/", ec); |
486 | 373 | if (ec) { |
487 | 0 | LOG(WARNING) << "failed to count thread num: " << ec.message(); |
488 | 0 | process_thread_num->set_value(0); |
489 | 0 | return; |
490 | 0 | } |
491 | 373 | int64_t count = |
492 | 1.03M | std::count_if(dict_iter, std::filesystem::end(dict_iter), [](const auto& entry) { |
493 | 1.03M | std::error_code error_code; |
494 | 1.03M | return entry.is_directory(error_code) && !error_code; |
495 | 1.03M | }); |
496 | | |
497 | 373 | process_thread_num->set_value(count); |
498 | 373 | } |
499 | | |
500 | | // get num of file descriptor of doris_be process |
501 | 373 | void DorisMetrics::_update_process_fd_num() { |
502 | | // fd used |
503 | 373 | std::error_code ec; |
504 | 373 | std::filesystem::directory_iterator dict_iter("/proc/self/fd/", ec); |
505 | 373 | if (ec) { |
506 | 0 | LOG(WARNING) << "failed to count fd: " << ec.message(); |
507 | 0 | process_fd_num_used->set_value(0); |
508 | 0 | return; |
509 | 0 | } |
510 | 373 | int64_t count = |
511 | 893k | std::count_if(dict_iter, std::filesystem::end(dict_iter), [](const auto& entry) { |
512 | 893k | std::error_code error_code; |
513 | 893k | return entry.is_regular_file(error_code) && !error_code; |
514 | 893k | }); |
515 | | |
516 | 373 | process_fd_num_used->set_value(count); |
517 | | |
518 | | // fd limits |
519 | 373 | FILE* fp = fopen("/proc/self/limits", "r"); |
520 | 373 | if (fp == nullptr) { |
521 | 0 | char buf[64]; |
522 | 0 | LOG(WARNING) << "open /proc/self/limits failed, errno=" << errno |
523 | 0 | << ", message=" << strerror_r(errno, buf, 64); |
524 | 0 | return; |
525 | 0 | } |
526 | | |
527 | | // /proc/self/limits |
528 | | // Max open files 65536 65536 files |
529 | 373 | int64_t values[2]; |
530 | 373 | size_t line_buf_size = 0; |
531 | 373 | char* line_ptr = nullptr; |
532 | 3.35k | while (getline(&line_ptr, &line_buf_size, fp) > 0) { |
533 | 3.35k | memset(values, 0, sizeof(values)); |
534 | 3.35k | int num = sscanf(line_ptr, "Max open files %" PRId64 " %" PRId64, &values[0], &values[1]); |
535 | 3.35k | if (num == 2) { |
536 | 373 | process_fd_num_limit_soft->set_value(values[0]); |
537 | 373 | process_fd_num_limit_hard->set_value(values[1]); |
538 | 373 | break; |
539 | 373 | } |
540 | 3.35k | } |
541 | | |
542 | 373 | if (line_ptr != nullptr) { |
543 | 373 | free(line_ptr); |
544 | 373 | } |
545 | | |
546 | 373 | if (ferror(fp) != 0) { |
547 | 0 | char buf[64]; |
548 | 0 | LOG(WARNING) << "getline failed, errno=" << errno |
549 | | << ", message=" << strerror_r(errno, buf, 64); |
550 | 0 | } |
551 | 373 | fclose(fp); |
552 | 373 | } |
553 | | |
554 | | } // namespace doris |