@@ -435,4 +435,64 @@ void SystemMetrics::_update_fd_metrics() {
435
435
fclose (fp);
436
436
}
437
437
438
+ int64_t SystemMetrics::get_max_io_util (
439
+ const std::map<std::string, int64_t >& lst_value, int64_t interval_sec) {
440
+ int64_t max = 0 ;
441
+ for (auto & it : _disk_metrics) {
442
+ int64_t cur = it.second ->io_time_ms .value ();
443
+ const auto find = lst_value.find (it.first );
444
+ if (find == lst_value.end ()) {
445
+ continue ;
446
+ }
447
+ int64_t incr = cur - find->second ;
448
+ if (incr > max) max = incr;
449
+ }
450
+ return max / interval_sec / 10 ;
451
+ }
452
+
453
+ void SystemMetrics::get_disks_io_time (std::map<std::string, int64_t >* map) {
454
+ map->clear ();
455
+ for (auto & it : _disk_metrics) {
456
+ map->emplace (it.first , it.second ->io_time_ms .value ());
457
+ }
458
+ }
459
+
460
+ void SystemMetrics::get_network_traffic (
461
+ std::map<std::string, int64_t >* send_map,
462
+ std::map<std::string, int64_t >* rcv_map) {
463
+ send_map->clear ();
464
+ rcv_map->clear ();
465
+ for (auto & it : _net_metrics) {
466
+ if (it.first == " lo" ) { continue ; }
467
+ send_map->emplace (it.first , it.second ->send_bytes .value ());
468
+ rcv_map->emplace (it.first , it.second ->receive_bytes .value ());
469
+ }
470
+ }
471
+
472
+ void SystemMetrics::get_max_net_traffic (
473
+ const std::map<std::string, int64_t >& lst_send_map,
474
+ const std::map<std::string, int64_t >& lst_rcv_map,
475
+ int64_t interval_sec,
476
+ int64_t * send_rate, int64_t * rcv_rate) {
477
+ int64_t max_send = 0 ;
478
+ int64_t max_rcv = 0 ;
479
+ for (auto & it : _net_metrics) {
480
+ int64_t cur_send = it.second ->send_bytes .value ();
481
+ int64_t cur_rcv = it.second ->receive_bytes .value ();
482
+
483
+ const auto find_send = lst_send_map.find (it.first );
484
+ if (find_send != lst_send_map.end ()) {
485
+ int64_t incr = cur_send - find_send->second ;
486
+ if (incr > max_send) max_send = incr;
487
+ }
488
+ const auto find_rcv= lst_rcv_map.find (it.first );
489
+ if (find_rcv != lst_rcv_map.end ()) {
490
+ int64_t incr = cur_rcv - find_rcv->second ;
491
+ if (incr > max_rcv) max_rcv = incr;
492
+ }
493
+ }
494
+
495
+ *send_rate = max_send / interval_sec;
496
+ *rcv_rate = max_rcv / interval_sec;
438
497
}
498
+ } // end namespace
0 commit comments