github-actions[bot] commented on code in PR #31386:
URL: https://github.com/apache/doris/pull/31386#discussion_r1502703036


##########
be/src/util/system_bvar_metrics.cpp:
##########
@@ -0,0 +1,1099 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/system_bvar_metrics.h"
+
+#include <ctype.h>
+// IWYU pragma: no_include <bthread/errno.h>
+#include <errno.h> // IWYU pragma: keep
+#include <glog/logging.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <functional>
+#include <ostream>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include "gutil/strings/split.h" // for string split
+#include "gutil/strtoint.h"      //  for atoi64
+#include "util/mem_info.h"
+#include "util/perf_counters.h"
+
+namespace doris {
+
+#define DECLARE_INT64_BVAR_METRIC(name, type, unit, description, group_name, 
labels, core) \
+    auto name = std::make_shared<BvarAdderMetric<int64_t>>(type, unit, #name, 
description, \
+                                                           group_name, labels, 
core);
+#define INIT_INT64_BVAR_METRIC(name, type, unit, description, group_name, 
labels, core)           \
+    name = std::make_shared<BvarAdderMetric<int64_t>>(type, unit, #name, 
description, group_name, \
+                                                      labels, core);
+
+#define INIT_DOUBLE_BVAR_METRIC(name, type, unit, description, group_name, 
labels, core)         \
+    name = std::make_shared<BvarAdderMetric<double>>(type, unit, #name, 
description, group_name, \
+                                                     labels, core);
+// /proc/stat: http://www.linuxhowtos.org/System/procstat.htm
+struct CpuBvarMetrics {
+    CpuBvarMetrics(BvarMetricEntity* entity) {
+        DECLARE_INT64_BVAR_METRIC(cpu_user, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"user"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_nice, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"nice"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_system, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"system"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_idle, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"idle"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_iowait, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"iowait"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_irq, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"irq"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_soft_irq, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT,
+                                  "", "cpu", BvarMetric::Labels({{"mode", 
"soft_irq"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_steal, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"steal"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_guest, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"guest"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_guest_nice, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT,
+                                  "", "cpu", BvarMetric::Labels({{"mode", 
"guest_nice"}}), false)
+        entity->register_metric("cpu_user", *cpu_user);
+        entity->register_metric("cpu_nice", *cpu_nice);
+        entity->register_metric("cpu_system", *cpu_system);
+        entity->register_metric("cpu_idle", *cpu_idle);
+        entity->register_metric("cpu_iowait", *cpu_iowait);
+        entity->register_metric("cpu_irq", *cpu_irq);
+        entity->register_metric("cpu_soft_irq", *cpu_soft_irq);
+        entity->register_metric("cpu_steal", *cpu_steal);
+        entity->register_metric("cpu_guest", *cpu_guest);
+        entity->register_metric("cpu_guest_nice", *cpu_guest_nice);
+
+        metrics.emplace_back(cpu_user);
+        metrics.emplace_back(cpu_nice);
+        metrics.emplace_back(cpu_system);
+        metrics.emplace_back(cpu_idle);
+        metrics.emplace_back(cpu_iowait);
+        metrics.emplace_back(cpu_irq);
+        metrics.emplace_back(cpu_soft_irq);
+        metrics.emplace_back(cpu_steal);
+        metrics.emplace_back(cpu_guest);
+        metrics.emplace_back(cpu_guest_nice);
+    }
+
+    static constexpr int cpu_num_metrics = 10;
+    std::vector<std::shared_ptr<BvarAdderMetric<int64_t>>> metrics;
+};
+
+struct MemoryBvarMetrics {
+    MemoryBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(memory_allocated_bytes, BvarMetricType::GAUGE, 
BvarMetricUnit::BYTES,
+                               "", "", BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(memory_pgpgin, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "", "",
+                               BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(memory_pgpgout, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "",
+                               "", BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(memory_pswpin, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "", "",
+                               BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(memory_pswpout, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "",
+                               "", BvarMetric::Labels(), false)
+        entity->register_metric("memory_allocated_bytes", 
*memory_allocated_bytes);
+        entity->register_metric("memory_pgpgin", *memory_pgpgin);
+        entity->register_metric("memory_pgpgout", *memory_pgpgout);
+        entity->register_metric("memory_pswpin", *memory_pswpin);
+        entity->register_metric("memory_pswpout", *memory_pswpout);
+#ifndef USE_JEMALLOC
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_allocated_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_total_thread_cache_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_central_cache_free_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_transfer_cache_free_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_thread_cache_free_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_pageheap_free_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_pageheap_unmapped_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        entity->register_metric("memory_tcmalloc_allocated_bytes",
+                                *memory_tcmalloc_allocated_bytes);
+        entity->register_metric("memory_tcmalloc_total_thread_cache_bytes",
+                                *memory_tcmalloc_total_thread_cache_bytes);
+        entity->register_metric("memory_tcmalloc_central_cache_free_bytes",
+                                *memory_tcmalloc_central_cache_free_bytes);
+        entity->register_metric("memory_tcmalloc_transfer_cache_free_bytes",
+                                *memory_tcmalloc_transfer_cache_free_bytes);
+        entity->register_metric("memory_tcmalloc_thread_cache_free_bytes",
+                                *memory_tcmalloc_thread_cache_free_bytes);
+        entity->register_metric("memory_tcmalloc_pageheap_free_bytes",
+                                *memory_tcmalloc_pageheap_free_bytes);
+        entity->register_metric("memory_tcmalloc_pageheap_unmapped_bytes",
+                                *memory_tcmalloc_pageheap_unmapped_bytes);
+#else
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_allocated_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_active_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_metadata_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_resident_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_mapped_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_retained_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_tcache_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_pactive_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_pdirty_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_pmuzzy_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_dirty_purged_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_muzzy_purged_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+
+        entity->register_metric("memory_jemalloc_allocated_bytes",
+                                *memory_jemalloc_allocated_bytes);
+        entity->register_metric("memory_jemalloc_active_bytes", 
*memory_jemalloc_active_bytes);
+        entity->register_metric("memory_jemalloc_metadata_bytes", 
*memory_jemalloc_metadata_bytes);
+        entity->register_metric("memory_jemalloc_resident_bytes", 
*memory_jemalloc_resident_bytes);
+        entity->register_metric("memory_jemalloc_mapped_bytes", 
*memory_jemalloc_mapped_bytes);
+        entity->register_metric("memory_jemalloc_retained_bytes", 
*memory_jemalloc_retained_bytes);
+        entity->register_metric("memory_jemalloc_tcache_bytes", 
*memory_jemalloc_tcache_bytes);
+        entity->register_metric("memory_jemalloc_pactive_num", 
*memory_jemalloc_pactive_num);
+        entity->register_metric("memory_jemalloc_pdirty_num", 
*memory_jemalloc_pdirty_num);
+        entity->register_metric("memory_jemalloc_pmuzzy_num", 
*memory_jemalloc_pmuzzy_num);
+        entity->register_metric("memory_jemalloc_dirty_purged_num",
+                                *memory_jemalloc_dirty_purged_num);
+        entity->register_metric("memory_jemalloc_muzzy_purged_num",
+                                *memory_jemalloc_muzzy_purged_num);
+
+#endif
+    }
+
+    // MetricEntity* entity = nullptr;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_allocated_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_pgpgin;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_pgpgout;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_pswpin;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_pswpout;
+
+#ifndef USE_JEMALLOC
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_tcmalloc_allocated_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_total_thread_cache_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_central_cache_free_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_transfer_cache_free_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_thread_cache_free_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_pageheap_free_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_pageheap_unmapped_bytes;
+#else
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_allocated_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_active_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_metadata_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_resident_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_mapped_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_retained_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_tcache_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_pactive_num;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_pdirty_num;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_pmuzzy_num;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_dirty_purged_num;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_muzzy_purged_num;
+#endif
+};
+
+struct DiskBvarMetrics {
+    DiskBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(disk_reads_completed, BvarMetricType::COUNTER,
+                               BvarMetricUnit::OPERATIONS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_bytes_read, BvarMetricType::COUNTER, 
BvarMetricUnit::BYTES, "",
+                               "", BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_read_time_ms, BvarMetricType::COUNTER,
+                               BvarMetricUnit::MILLISECONDS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_writes_completed, BvarMetricType::COUNTER,
+                               BvarMetricUnit::OPERATIONS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_bytes_written, BvarMetricType::COUNTER, 
BvarMetricUnit::BYTES,
+                               "", "", BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(disk_write_time_ms, BvarMetricType::COUNTER,
+                               BvarMetricUnit::MILLISECONDS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_io_time_ms, BvarMetricType::COUNTER,
+                               BvarMetricUnit::MILLISECONDS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_io_time_weigthed, BvarMetricType::COUNTER,
+                               BvarMetricUnit::MILLISECONDS, "", "", 
BvarMetric::Labels(), false)
+        entity->register_metric("disk_reads_completed", *disk_reads_completed);
+        entity->register_metric("disk_bytes_read", *disk_bytes_read);
+        entity->register_metric("disk_read_time_ms", *disk_read_time_ms);
+        entity->register_metric("disk_writes_completed", 
*disk_writes_completed);
+        entity->register_metric("disk_bytes_written", *disk_bytes_written);
+        entity->register_metric("disk_write_time_ms", *disk_write_time_ms);
+        entity->register_metric("disk_io_time_ms", *disk_io_time_ms);
+        entity->register_metric("disk_io_time_weigthed", 
*disk_io_time_weigthed);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_reads_completed;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_bytes_read;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_read_time_ms;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_writes_completed;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_bytes_written;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_write_time_ms;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_io_time_ms;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_io_time_weigthed;
+};
+
+struct NetworkBvarMetrics {
+    NetworkBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(network_receive_bytes, BvarMetricType::COUNTER,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(network_receive_packets, 
BvarMetricType::COUNTER,
+                               BvarMetricUnit::PACKETS, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(network_send_bytes, BvarMetricType::COUNTER, 
BvarMetricUnit::BYTES,
+                               "", "", BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(network_send_packets, BvarMetricType::COUNTER,
+                               BvarMetricUnit::PACKETS, "", "", 
BvarMetric::Labels(), false);
+        entity->register_metric("network_receive_bytes", 
*network_receive_bytes);
+        entity->register_metric("network_receive_packets", 
*network_receive_packets);
+        entity->register_metric("network_send_bytes", *network_send_bytes);
+        entity->register_metric("network_send_packets", *network_send_packets);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> network_receive_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> network_receive_packets;
+    std::shared_ptr<BvarAdderMetric<int64_t>> network_send_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> network_send_packets;
+};
+
+struct FileDescriptorBvarMetrics {
+    FileDescriptorBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(fd_num_limit, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "", "",
+                               BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(fd_num_used, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "", "",
+                               BvarMetric::Labels(), false);
+        entity->register_metric("fd_num_limit", *fd_num_limit);
+        entity->register_metric("fd_num_used", *fd_num_used);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> fd_num_limit;
+    std::shared_ptr<BvarAdderMetric<int64_t>> fd_num_used;
+};
+
+// metrics read from /proc/net/snmp
+struct SnmpBvarMetrics {
+    SnmpBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(snmp_tcp_in_errs, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "The number of all problematic TCP packets 
received", "",
+                               BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(snmp_tcp_retrans_segs, BvarMetricType::COUNTER,
+                               BvarMetricUnit::NOUNIT, "All TCP packets 
retransmitted", "",
+                               BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(snmp_tcp_in_segs, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "All received TCP packets", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(snmp_tcp_out_segs, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "All send TCP packets with RST mark", "", 
BvarMetric::Labels(),
+                               false)
+        entity->register_metric("snmp_tcp_in_errs", *snmp_tcp_in_errs);
+        entity->register_metric("snmp_tcp_retrans_segs", 
*snmp_tcp_retrans_segs);
+        entity->register_metric("snmp_tcp_in_segs", *snmp_tcp_in_segs);
+        entity->register_metric("snmp_tcp_out_segs", *snmp_tcp_out_segs);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> snmp_tcp_in_errs;
+    std::shared_ptr<BvarAdderMetric<int64_t>> snmp_tcp_retrans_segs;
+    std::shared_ptr<BvarAdderMetric<int64_t>> snmp_tcp_in_segs;
+    std::shared_ptr<BvarAdderMetric<int64_t>> snmp_tcp_out_segs;
+};
+
+struct LoadAverageBvarMetrics {
+    LoadAverageBvarMetrics(BvarMetricEntity* entity) {
+        INIT_DOUBLE_BVAR_METRIC(load_average_1_minutes, BvarMetricType::GAUGE,
+                                BvarMetricUnit::NOUNIT, "", "load_average",
+                                BvarMetric::Labels({{"mode", "1_minutes"}}), 
false);
+        INIT_DOUBLE_BVAR_METRIC(load_average_5_minutes, BvarMetricType::GAUGE,
+                                BvarMetricUnit::NOUNIT, "", "load_average",
+                                BvarMetric::Labels({{"mode", "5_minutes"}}), 
false);
+        INIT_DOUBLE_BVAR_METRIC(load_average_15_minutes, BvarMetricType::GAUGE,
+                                BvarMetricUnit::NOUNIT, "", "load_average",
+                                BvarMetric::Labels({{"mode", "15_minutes"}}), 
false);
+        entity->register_metric("load_average_1_minutes", 
*load_average_1_minutes);
+        entity->register_metric("load_average_5_minutes", 
*load_average_5_minutes);
+        entity->register_metric("load_average_15_minutes", 
*load_average_15_minutes);
+    }
+
+    std::shared_ptr<BvarAdderMetric<double>> load_average_1_minutes;
+    std::shared_ptr<BvarAdderMetric<double>> load_average_5_minutes;
+    std::shared_ptr<BvarAdderMetric<double>> load_average_15_minutes;
+};
+
+struct ProcBvarMetrics {
+    ProcBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(proc_interrupt, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT, "",
+                               "proc", BvarMetric::Labels({{"mode", 
"interrupt"}}), false);
+        INIT_INT64_BVAR_METRIC(proc_ctxt_switch, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "", "proc", BvarMetric::Labels({{"mode", 
"ctxt_switch"}}), false);
+        INIT_INT64_BVAR_METRIC(proc_procs_running, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "", "proc", BvarMetric::Labels({{"mode", 
"procs_running"}}), false);
+        INIT_INT64_BVAR_METRIC(proc_procs_blocked, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "", "proc", BvarMetric::Labels({{"mode", 
"procs_blocked"}}), false);
+        entity->register_metric("proc_interrupt", *proc_interrupt);
+        entity->register_metric("proc_ctxt_switch", *proc_ctxt_switch);
+        entity->register_metric("proc_procs_running", *proc_procs_running);
+        entity->register_metric("proc_procs_blocked", *proc_procs_blocked);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> proc_interrupt;
+    std::shared_ptr<BvarAdderMetric<int64_t>> proc_ctxt_switch;
+    std::shared_ptr<BvarAdderMetric<int64_t>> proc_procs_running;
+    std::shared_ptr<BvarAdderMetric<int64_t>> proc_procs_blocked;
+};
+
+const char* SystemBvarMetrics::s_hook_name_ = "system_metrics";
+
+SystemBvarMetrics::SystemBvarMetrics(BvarMetricRegistry* registry,
+                                     const std::set<std::string>& disk_devices,
+                                     const std::vector<std::string>& 
network_interfaces) {
+    DCHECK(registry != nullptr);
+    registry_ = registry;
+    server_entity_ = registry->register_entity("server");
+    DCHECK(server_entity_ != nullptr);
+    server_entity_->register_hook(s_hook_name_, 
std::bind(&SystemBvarMetrics::update, this));
+    install_cpu_metrics();
+    install_memory_metrics(server_entity_.get());
+    install_disk_metrics(disk_devices);
+    install_net_metrics(network_interfaces);
+    install_fd_metrics(server_entity_.get());
+    install_snmp_metrics(server_entity_.get());
+    install_load_avg_metrics(server_entity_.get());
+    install_proc_metrics(server_entity_.get());
+    install_max_metrics(server_entity_.get());
+}
+
+SystemBvarMetrics::~SystemBvarMetrics() {
+    DCHECK(server_entity_ != nullptr);
+    server_entity_->deregister_hook(s_hook_name_);
+    for (auto& it : cpu_metrics_) {
+        delete it.second;
+    }
+    for (auto& it : disk_metrics_) {
+        delete it.second;
+    }
+    for (auto& it : network_metrics_) {
+        delete it.second;
+    }
+}
+
+void SystemBvarMetrics::update() {
+    update_cpu_metrics();
+    update_memory_metrics();
+    update_disk_metrics();
+    update_net_metrics();
+    update_fd_metrics();
+    update_snmp_metrics();
+    update_load_avg_metrics();
+    update_proc_metrics();
+}
+
+void SystemBvarMetrics::install_max_metrics(BvarMetricEntity* entity) {
+    INIT_INT64_BVAR_METRIC(max_disk_io_util_percent, BvarMetricType::GAUGE, 
BvarMetricUnit::PERCENT,
+                           "", "", BvarMetric::Labels(), true)
+    INIT_INT64_BVAR_METRIC(max_network_send_bytes_rate, BvarMetricType::GAUGE,
+                           BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), true)
+    INIT_INT64_BVAR_METRIC(max_network_receive_bytes_rate, 
BvarMetricType::GAUGE,
+                           BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), true)
+    entity->register_metric("max_disk_io_util_percent", 
*max_disk_io_util_percent);
+    entity->register_metric("max_network_send_bytes_rate", 
*max_network_send_bytes_rate);
+    entity->register_metric("max_network_receive_bytes_rate", 
*max_network_receive_bytes_rate);
+}
+
+void SystemBvarMetrics::install_cpu_metrics() {
+    get_cpu_name();
+    for (auto cpu_name : cpu_names_) {
+        auto cpu_entity = registry_->register_entity(cpu_name, {{"device", 
cpu_name}});
+        CpuBvarMetrics* metrics = new CpuBvarMetrics(cpu_entity.get());
+        cpu_metrics_.emplace(cpu_name, metrics);
+    }
+}
+
+#ifdef BE_TEST
+const char* k_ut_stat_path;
+const char* k_ut_diskstats_path;
+const char* k_ut_net_dev_path;
+const char* k_ut_fd_path;
+const char* k_ut_net_snmp_path;
+const char* k_ut_load_avg_path;
+const char* k_ut_vmstat_path;
+#endif
+
+void SystemBvarMetrics::update_cpu_metrics() {
+#ifdef BE_TEST
+    FILE* fp = fopen(k_ut_stat_path, "r");
+#else
+    FILE* fp = fopen("/proc/stat", "r");
+#endif
+    if (fp == nullptr) {
+        char buf[64];
+        LOG(WARNING) << "open /proc/stat failed, errno=" << errno
+                     << ", message=" << strerror_r(errno, buf, 64);
+        return;
+    }
+    char* line_ptr = nullptr;
+    size_t line_buf_size = 0;
+    while (getline(&line_ptr, &line_buf_size, fp) > 0) {
+        char cpu[16];
+        int64_t values[CpuBvarMetrics::cpu_num_metrics];
+        memset(values, 0, sizeof(values));
+        int num = sscanf(line_ptr,
+                         "%15s"
+                         " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" 
PRId64 " %" PRId64
+                         " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64,
+                         cpu, &values[0], &values[1], &values[2], &values[3], 
&values[4],
+                         &values[5], &values[6], &values[7], &values[8], 
&values[9]);
+        if (num < 4) {
+            continue;
+        }
+        std::string cpu_name(cpu);
+        auto it = cpu_metrics_.find(cpu_name);
+        if (it == cpu_metrics_.end()) {
+            continue;
+        }
+
+        for (int i = 0; i < CpuBvarMetrics::cpu_num_metrics; ++i) {
+            it->second->metrics[i]->set_value(values[i]);
+        }
+    }
+
+    if (ferror(fp) != 0) {
+        char buf[64];
+        LOG(WARNING) << "getline failed, errno=" << errno
+                     << ", message=" << strerror_r(errno, buf, 64);
+    }
+
+    fclose(fp);
+}
+
+void SystemBvarMetrics::install_memory_metrics(BvarMetricEntity* entity) {
+    memory_metrics_.reset(new MemoryBvarMetrics(entity));
+}
+
+void SystemBvarMetrics::update_memory_metrics() {

Review Comment:
   warning: method 'update_memory_metrics' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/util/system_bvar_metrics.h:82:
   ```diff
   -     void update_memory_metrics();
   +     static void update_memory_metrics();
   ```
   



##########
be/src/util/system_bvar_metrics.cpp:
##########
@@ -0,0 +1,1099 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "util/system_bvar_metrics.h"
+
+#include <ctype.h>
+// IWYU pragma: no_include <bthread/errno.h>
+#include <errno.h> // IWYU pragma: keep
+#include <glog/logging.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <functional>
+#include <ostream>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include "gutil/strings/split.h" // for string split
+#include "gutil/strtoint.h"      //  for atoi64
+#include "util/mem_info.h"
+#include "util/perf_counters.h"
+
+namespace doris {
+
+#define DECLARE_INT64_BVAR_METRIC(name, type, unit, description, group_name, 
labels, core) \
+    auto name = std::make_shared<BvarAdderMetric<int64_t>>(type, unit, #name, 
description, \
+                                                           group_name, labels, 
core);
+#define INIT_INT64_BVAR_METRIC(name, type, unit, description, group_name, 
labels, core)           \
+    name = std::make_shared<BvarAdderMetric<int64_t>>(type, unit, #name, 
description, group_name, \
+                                                      labels, core);
+
+#define INIT_DOUBLE_BVAR_METRIC(name, type, unit, description, group_name, 
labels, core)         \
+    name = std::make_shared<BvarAdderMetric<double>>(type, unit, #name, 
description, group_name, \
+                                                     labels, core);
+// /proc/stat: http://www.linuxhowtos.org/System/procstat.htm
+struct CpuBvarMetrics {
+    CpuBvarMetrics(BvarMetricEntity* entity) {
+        DECLARE_INT64_BVAR_METRIC(cpu_user, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"user"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_nice, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"nice"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_system, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"system"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_idle, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"idle"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_iowait, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"iowait"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_irq, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"irq"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_soft_irq, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT,
+                                  "", "cpu", BvarMetric::Labels({{"mode", 
"soft_irq"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_steal, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"steal"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_guest, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT, "",
+                                  "cpu", BvarMetric::Labels({{"mode", 
"guest"}}), false)
+        DECLARE_INT64_BVAR_METRIC(cpu_guest_nice, BvarMetricType::COUNTER, 
BvarMetricUnit::PERCENT,
+                                  "", "cpu", BvarMetric::Labels({{"mode", 
"guest_nice"}}), false)
+        entity->register_metric("cpu_user", *cpu_user);
+        entity->register_metric("cpu_nice", *cpu_nice);
+        entity->register_metric("cpu_system", *cpu_system);
+        entity->register_metric("cpu_idle", *cpu_idle);
+        entity->register_metric("cpu_iowait", *cpu_iowait);
+        entity->register_metric("cpu_irq", *cpu_irq);
+        entity->register_metric("cpu_soft_irq", *cpu_soft_irq);
+        entity->register_metric("cpu_steal", *cpu_steal);
+        entity->register_metric("cpu_guest", *cpu_guest);
+        entity->register_metric("cpu_guest_nice", *cpu_guest_nice);
+
+        metrics.emplace_back(cpu_user);
+        metrics.emplace_back(cpu_nice);
+        metrics.emplace_back(cpu_system);
+        metrics.emplace_back(cpu_idle);
+        metrics.emplace_back(cpu_iowait);
+        metrics.emplace_back(cpu_irq);
+        metrics.emplace_back(cpu_soft_irq);
+        metrics.emplace_back(cpu_steal);
+        metrics.emplace_back(cpu_guest);
+        metrics.emplace_back(cpu_guest_nice);
+    }
+
+    static constexpr int cpu_num_metrics = 10;
+    std::vector<std::shared_ptr<BvarAdderMetric<int64_t>>> metrics;
+};
+
+struct MemoryBvarMetrics {
+    MemoryBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(memory_allocated_bytes, BvarMetricType::GAUGE, 
BvarMetricUnit::BYTES,
+                               "", "", BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(memory_pgpgin, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "", "",
+                               BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(memory_pgpgout, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "",
+                               "", BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(memory_pswpin, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "", "",
+                               BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(memory_pswpout, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "",
+                               "", BvarMetric::Labels(), false)
+        entity->register_metric("memory_allocated_bytes", 
*memory_allocated_bytes);
+        entity->register_metric("memory_pgpgin", *memory_pgpgin);
+        entity->register_metric("memory_pgpgout", *memory_pgpgout);
+        entity->register_metric("memory_pswpin", *memory_pswpin);
+        entity->register_metric("memory_pswpout", *memory_pswpout);
+#ifndef USE_JEMALLOC
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_allocated_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_total_thread_cache_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_central_cache_free_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_transfer_cache_free_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_thread_cache_free_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_pageheap_free_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_tcmalloc_pageheap_unmapped_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        entity->register_metric("memory_tcmalloc_allocated_bytes",
+                                *memory_tcmalloc_allocated_bytes);
+        entity->register_metric("memory_tcmalloc_total_thread_cache_bytes",
+                                *memory_tcmalloc_total_thread_cache_bytes);
+        entity->register_metric("memory_tcmalloc_central_cache_free_bytes",
+                                *memory_tcmalloc_central_cache_free_bytes);
+        entity->register_metric("memory_tcmalloc_transfer_cache_free_bytes",
+                                *memory_tcmalloc_transfer_cache_free_bytes);
+        entity->register_metric("memory_tcmalloc_thread_cache_free_bytes",
+                                *memory_tcmalloc_thread_cache_free_bytes);
+        entity->register_metric("memory_tcmalloc_pageheap_free_bytes",
+                                *memory_tcmalloc_pageheap_free_bytes);
+        entity->register_metric("memory_tcmalloc_pageheap_unmapped_bytes",
+                                *memory_tcmalloc_pageheap_unmapped_bytes);
+#else
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_allocated_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_active_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_metadata_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_resident_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_mapped_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_retained_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_tcache_bytes, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_pactive_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_pdirty_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_pmuzzy_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_dirty_purged_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(memory_jemalloc_muzzy_purged_num, 
BvarMetricType::GAUGE,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+
+        entity->register_metric("memory_jemalloc_allocated_bytes",
+                                *memory_jemalloc_allocated_bytes);
+        entity->register_metric("memory_jemalloc_active_bytes", 
*memory_jemalloc_active_bytes);
+        entity->register_metric("memory_jemalloc_metadata_bytes", 
*memory_jemalloc_metadata_bytes);
+        entity->register_metric("memory_jemalloc_resident_bytes", 
*memory_jemalloc_resident_bytes);
+        entity->register_metric("memory_jemalloc_mapped_bytes", 
*memory_jemalloc_mapped_bytes);
+        entity->register_metric("memory_jemalloc_retained_bytes", 
*memory_jemalloc_retained_bytes);
+        entity->register_metric("memory_jemalloc_tcache_bytes", 
*memory_jemalloc_tcache_bytes);
+        entity->register_metric("memory_jemalloc_pactive_num", 
*memory_jemalloc_pactive_num);
+        entity->register_metric("memory_jemalloc_pdirty_num", 
*memory_jemalloc_pdirty_num);
+        entity->register_metric("memory_jemalloc_pmuzzy_num", 
*memory_jemalloc_pmuzzy_num);
+        entity->register_metric("memory_jemalloc_dirty_purged_num",
+                                *memory_jemalloc_dirty_purged_num);
+        entity->register_metric("memory_jemalloc_muzzy_purged_num",
+                                *memory_jemalloc_muzzy_purged_num);
+
+#endif
+    }
+
+    // MetricEntity* entity = nullptr;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_allocated_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_pgpgin;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_pgpgout;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_pswpin;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_pswpout;
+
+#ifndef USE_JEMALLOC
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_tcmalloc_allocated_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_total_thread_cache_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_central_cache_free_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_transfer_cache_free_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_thread_cache_free_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_pageheap_free_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> 
memory_tcmalloc_pageheap_unmapped_bytes;
+#else
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_allocated_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_active_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_metadata_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_resident_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_mapped_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_retained_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_tcache_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_pactive_num;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_pdirty_num;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_pmuzzy_num;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_dirty_purged_num;
+    std::shared_ptr<BvarAdderMetric<int64_t>> memory_jemalloc_muzzy_purged_num;
+#endif
+};
+
+struct DiskBvarMetrics {
+    DiskBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(disk_reads_completed, BvarMetricType::COUNTER,
+                               BvarMetricUnit::OPERATIONS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_bytes_read, BvarMetricType::COUNTER, 
BvarMetricUnit::BYTES, "",
+                               "", BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_read_time_ms, BvarMetricType::COUNTER,
+                               BvarMetricUnit::MILLISECONDS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_writes_completed, BvarMetricType::COUNTER,
+                               BvarMetricUnit::OPERATIONS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_bytes_written, BvarMetricType::COUNTER, 
BvarMetricUnit::BYTES,
+                               "", "", BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(disk_write_time_ms, BvarMetricType::COUNTER,
+                               BvarMetricUnit::MILLISECONDS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_io_time_ms, BvarMetricType::COUNTER,
+                               BvarMetricUnit::MILLISECONDS, "", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(disk_io_time_weigthed, BvarMetricType::COUNTER,
+                               BvarMetricUnit::MILLISECONDS, "", "", 
BvarMetric::Labels(), false)
+        entity->register_metric("disk_reads_completed", *disk_reads_completed);
+        entity->register_metric("disk_bytes_read", *disk_bytes_read);
+        entity->register_metric("disk_read_time_ms", *disk_read_time_ms);
+        entity->register_metric("disk_writes_completed", 
*disk_writes_completed);
+        entity->register_metric("disk_bytes_written", *disk_bytes_written);
+        entity->register_metric("disk_write_time_ms", *disk_write_time_ms);
+        entity->register_metric("disk_io_time_ms", *disk_io_time_ms);
+        entity->register_metric("disk_io_time_weigthed", 
*disk_io_time_weigthed);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_reads_completed;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_bytes_read;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_read_time_ms;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_writes_completed;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_bytes_written;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_write_time_ms;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_io_time_ms;
+    std::shared_ptr<BvarAdderMetric<int64_t>> disk_io_time_weigthed;
+};
+
+struct NetworkBvarMetrics {
+    NetworkBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(network_receive_bytes, BvarMetricType::COUNTER,
+                               BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(network_receive_packets, 
BvarMetricType::COUNTER,
+                               BvarMetricUnit::PACKETS, "", "", 
BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(network_send_bytes, BvarMetricType::COUNTER, 
BvarMetricUnit::BYTES,
+                               "", "", BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(network_send_packets, BvarMetricType::COUNTER,
+                               BvarMetricUnit::PACKETS, "", "", 
BvarMetric::Labels(), false);
+        entity->register_metric("network_receive_bytes", 
*network_receive_bytes);
+        entity->register_metric("network_receive_packets", 
*network_receive_packets);
+        entity->register_metric("network_send_bytes", *network_send_bytes);
+        entity->register_metric("network_send_packets", *network_send_packets);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> network_receive_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> network_receive_packets;
+    std::shared_ptr<BvarAdderMetric<int64_t>> network_send_bytes;
+    std::shared_ptr<BvarAdderMetric<int64_t>> network_send_packets;
+};
+
+struct FileDescriptorBvarMetrics {
+    FileDescriptorBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(fd_num_limit, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "", "",
+                               BvarMetric::Labels(), false);
+        INIT_INT64_BVAR_METRIC(fd_num_used, BvarMetricType::GAUGE, 
BvarMetricUnit::NOUNIT, "", "",
+                               BvarMetric::Labels(), false);
+        entity->register_metric("fd_num_limit", *fd_num_limit);
+        entity->register_metric("fd_num_used", *fd_num_used);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> fd_num_limit;
+    std::shared_ptr<BvarAdderMetric<int64_t>> fd_num_used;
+};
+
+// metrics read from /proc/net/snmp
+struct SnmpBvarMetrics {
+    SnmpBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(snmp_tcp_in_errs, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "The number of all problematic TCP packets 
received", "",
+                               BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(snmp_tcp_retrans_segs, BvarMetricType::COUNTER,
+                               BvarMetricUnit::NOUNIT, "All TCP packets 
retransmitted", "",
+                               BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(snmp_tcp_in_segs, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "All received TCP packets", "", 
BvarMetric::Labels(), false)
+        INIT_INT64_BVAR_METRIC(snmp_tcp_out_segs, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "All send TCP packets with RST mark", "", 
BvarMetric::Labels(),
+                               false)
+        entity->register_metric("snmp_tcp_in_errs", *snmp_tcp_in_errs);
+        entity->register_metric("snmp_tcp_retrans_segs", 
*snmp_tcp_retrans_segs);
+        entity->register_metric("snmp_tcp_in_segs", *snmp_tcp_in_segs);
+        entity->register_metric("snmp_tcp_out_segs", *snmp_tcp_out_segs);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> snmp_tcp_in_errs;
+    std::shared_ptr<BvarAdderMetric<int64_t>> snmp_tcp_retrans_segs;
+    std::shared_ptr<BvarAdderMetric<int64_t>> snmp_tcp_in_segs;
+    std::shared_ptr<BvarAdderMetric<int64_t>> snmp_tcp_out_segs;
+};
+
+struct LoadAverageBvarMetrics {
+    LoadAverageBvarMetrics(BvarMetricEntity* entity) {
+        INIT_DOUBLE_BVAR_METRIC(load_average_1_minutes, BvarMetricType::GAUGE,
+                                BvarMetricUnit::NOUNIT, "", "load_average",
+                                BvarMetric::Labels({{"mode", "1_minutes"}}), 
false);
+        INIT_DOUBLE_BVAR_METRIC(load_average_5_minutes, BvarMetricType::GAUGE,
+                                BvarMetricUnit::NOUNIT, "", "load_average",
+                                BvarMetric::Labels({{"mode", "5_minutes"}}), 
false);
+        INIT_DOUBLE_BVAR_METRIC(load_average_15_minutes, BvarMetricType::GAUGE,
+                                BvarMetricUnit::NOUNIT, "", "load_average",
+                                BvarMetric::Labels({{"mode", "15_minutes"}}), 
false);
+        entity->register_metric("load_average_1_minutes", 
*load_average_1_minutes);
+        entity->register_metric("load_average_5_minutes", 
*load_average_5_minutes);
+        entity->register_metric("load_average_15_minutes", 
*load_average_15_minutes);
+    }
+
+    std::shared_ptr<BvarAdderMetric<double>> load_average_1_minutes;
+    std::shared_ptr<BvarAdderMetric<double>> load_average_5_minutes;
+    std::shared_ptr<BvarAdderMetric<double>> load_average_15_minutes;
+};
+
+struct ProcBvarMetrics {
+    ProcBvarMetrics(BvarMetricEntity* entity) {
+        INIT_INT64_BVAR_METRIC(proc_interrupt, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT, "",
+                               "proc", BvarMetric::Labels({{"mode", 
"interrupt"}}), false);
+        INIT_INT64_BVAR_METRIC(proc_ctxt_switch, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "", "proc", BvarMetric::Labels({{"mode", 
"ctxt_switch"}}), false);
+        INIT_INT64_BVAR_METRIC(proc_procs_running, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "", "proc", BvarMetric::Labels({{"mode", 
"procs_running"}}), false);
+        INIT_INT64_BVAR_METRIC(proc_procs_blocked, BvarMetricType::COUNTER, 
BvarMetricUnit::NOUNIT,
+                               "", "proc", BvarMetric::Labels({{"mode", 
"procs_blocked"}}), false);
+        entity->register_metric("proc_interrupt", *proc_interrupt);
+        entity->register_metric("proc_ctxt_switch", *proc_ctxt_switch);
+        entity->register_metric("proc_procs_running", *proc_procs_running);
+        entity->register_metric("proc_procs_blocked", *proc_procs_blocked);
+    }
+
+    std::shared_ptr<BvarAdderMetric<int64_t>> proc_interrupt;
+    std::shared_ptr<BvarAdderMetric<int64_t>> proc_ctxt_switch;
+    std::shared_ptr<BvarAdderMetric<int64_t>> proc_procs_running;
+    std::shared_ptr<BvarAdderMetric<int64_t>> proc_procs_blocked;
+};
+
+const char* SystemBvarMetrics::s_hook_name_ = "system_metrics";
+
+SystemBvarMetrics::SystemBvarMetrics(BvarMetricRegistry* registry,
+                                     const std::set<std::string>& disk_devices,
+                                     const std::vector<std::string>& 
network_interfaces) {
+    DCHECK(registry != nullptr);
+    registry_ = registry;
+    server_entity_ = registry->register_entity("server");
+    DCHECK(server_entity_ != nullptr);
+    server_entity_->register_hook(s_hook_name_, 
std::bind(&SystemBvarMetrics::update, this));
+    install_cpu_metrics();
+    install_memory_metrics(server_entity_.get());
+    install_disk_metrics(disk_devices);
+    install_net_metrics(network_interfaces);
+    install_fd_metrics(server_entity_.get());
+    install_snmp_metrics(server_entity_.get());
+    install_load_avg_metrics(server_entity_.get());
+    install_proc_metrics(server_entity_.get());
+    install_max_metrics(server_entity_.get());
+}
+
+SystemBvarMetrics::~SystemBvarMetrics() {
+    DCHECK(server_entity_ != nullptr);
+    server_entity_->deregister_hook(s_hook_name_);
+    for (auto& it : cpu_metrics_) {
+        delete it.second;
+    }
+    for (auto& it : disk_metrics_) {
+        delete it.second;
+    }
+    for (auto& it : network_metrics_) {
+        delete it.second;
+    }
+}
+
+void SystemBvarMetrics::update() {
+    update_cpu_metrics();
+    update_memory_metrics();
+    update_disk_metrics();
+    update_net_metrics();
+    update_fd_metrics();
+    update_snmp_metrics();
+    update_load_avg_metrics();
+    update_proc_metrics();
+}
+
+void SystemBvarMetrics::install_max_metrics(BvarMetricEntity* entity) {
+    INIT_INT64_BVAR_METRIC(max_disk_io_util_percent, BvarMetricType::GAUGE, 
BvarMetricUnit::PERCENT,
+                           "", "", BvarMetric::Labels(), true)
+    INIT_INT64_BVAR_METRIC(max_network_send_bytes_rate, BvarMetricType::GAUGE,
+                           BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), true)
+    INIT_INT64_BVAR_METRIC(max_network_receive_bytes_rate, 
BvarMetricType::GAUGE,
+                           BvarMetricUnit::BYTES, "", "", 
BvarMetric::Labels(), true)
+    entity->register_metric("max_disk_io_util_percent", 
*max_disk_io_util_percent);
+    entity->register_metric("max_network_send_bytes_rate", 
*max_network_send_bytes_rate);
+    entity->register_metric("max_network_receive_bytes_rate", 
*max_network_receive_bytes_rate);
+}
+
+void SystemBvarMetrics::install_cpu_metrics() {

Review Comment:
   warning: method 'install_cpu_metrics' can be made static 
[readability-convert-member-functions-to-static]
   
   be/src/util/system_bvar_metrics.h:76:
   ```diff
   -     void install_cpu_metrics();
   +     static void install_cpu_metrics();
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to