carlvinhust2012 commented on code in PR #9887:
URL: https://github.com/apache/incubator-doris/pull/9887#discussion_r887519286


##########
be/src/util/system_metrics.cpp:
##########
@@ -718,4 +788,174 @@ void SystemMetrics::get_max_net_traffic(const 
std::map<std::string, int64_t>& ls
     *send_rate = max_send / interval_sec;
     *rcv_rate = max_rcv / interval_sec;
 }
+
+void SystemMetrics::_install_proc_metrics(MetricEntity* entity) {
+    _proc_metrics.reset(new ProcMetrics(entity));
+}
+
+void SystemMetrics::_update_proc_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;
+    }
+
+    uint64_t inter = 0, ctxt = 0, procs_r = 0, procs_b = 0;
+    while (getline(&_line_ptr, &_line_buf_size, fp) > 0) {
+        char* start_pos = nullptr;
+        start_pos = strstr(_line_ptr, "intr ");
+        if (start_pos) {
+            sscanf(start_pos, "intr %lu", &inter);
+            _proc_metrics->proc_interrupt->set_value(inter);
+        }
+
+        start_pos = strstr(_line_ptr, "ctxt ");
+        if (start_pos) {
+            sscanf(start_pos, "ctxt %lu", &ctxt);
+            _proc_metrics->proc_ctxt_switch->set_value(ctxt);
+        }
+
+        start_pos = strstr(_line_ptr, "procs_running ");
+        if (start_pos) {
+            sscanf(start_pos, "procs_running %lu", &procs_r);
+            _proc_metrics->proc_procs_running->set_value(procs_r);
+        }
+
+        start_pos = strstr(_line_ptr, "procs_blocked ");
+        if (start_pos) {
+            sscanf(start_pos, "procs_blocked %lu", &procs_b);
+            _proc_metrics->proc_procs_blocked->set_value(procs_b);
+        }
+    }
+
+    if (ferror(fp) != 0) {
+        char buf[64];
+        LOG(WARNING) << "getline failed, errno=" << errno
+                     << ", message=" << strerror_r(errno, buf, 64);
+    }
+
+    fclose(fp);
+}
+
+void SystemMetrics::get_metrics_from_proc_meminfo() {
+#ifdef BE_TEST
+    FILE* fp = fopen(k_ut_meminfo_path, "r");
+#else
+    FILE* fp = fopen("/proc/meminfo", "r");

Review Comment:
   after update, just use /proc/vmstat to get system memory.



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to