refactor SystemMonitorReportConfig

This commit is contained in:
haoran 2022-11-29 17:58:27 +00:00 committed by HaoranYi
parent 75fc87f330
commit 0ce507c20d
2 changed files with 28 additions and 35 deletions

View File

@ -387,27 +387,21 @@ fn parse_disk_stats(reader_diskstats: &mut impl BufRead) -> Result<DiskStats, St
Ok(stats) Ok(stats)
} }
pub struct SystemMonitorStatsReportConfig {
pub report_os_memory_stats: bool,
pub report_os_network_stats: bool,
pub report_os_cpu_stats: bool,
pub report_os_disk_stats: bool,
pub report_os_open_fd_stats: bool,
}
impl SystemMonitorService { impl SystemMonitorService {
pub fn new( pub fn new(exit: Arc<AtomicBool>, config: SystemMonitorStatsReportConfig) -> Self {
exit: Arc<AtomicBool>,
report_os_memory_stats: bool,
report_os_network_stats: bool,
report_os_cpu_stats: bool,
report_os_disk_stats: bool,
report_os_open_fd_stats: bool,
) -> Self {
info!("Starting SystemMonitorService"); info!("Starting SystemMonitorService");
let thread_hdl = Builder::new() let thread_hdl = Builder::new()
.name("solSystemMonitr".to_string()) .name("solSystemMonitr".to_string())
.spawn(move || { .spawn(move || {
Self::run( Self::run(exit, config);
exit,
report_os_memory_stats,
report_os_network_stats,
report_os_cpu_stats,
report_os_disk_stats,
report_os_open_fd_stats,
);
}) })
.unwrap(); .unwrap();
@ -1012,14 +1006,7 @@ impl SystemMonitorService {
) )
} }
pub fn run( pub fn run(exit: Arc<AtomicBool>, config: SystemMonitorStatsReportConfig) {
exit: Arc<AtomicBool>,
report_os_memory_stats: bool,
report_os_network_stats: bool,
report_os_cpu_stats: bool,
report_os_disk_stats: bool,
report_os_open_fd_stats: bool,
) {
let mut udp_stats = None; let mut udp_stats = None;
let mut disk_stats = None; let mut disk_stats = None;
let network_limits_timer = AtomicInterval::default(); let network_limits_timer = AtomicInterval::default();
@ -1033,7 +1020,7 @@ impl SystemMonitorService {
if exit.load(Ordering::Relaxed) { if exit.load(Ordering::Relaxed) {
break; break;
} }
if report_os_network_stats { if config.report_os_network_stats {
if network_limits_timer.should_update(SAMPLE_INTERVAL_OS_NETWORK_LIMITS_MS) { if network_limits_timer.should_update(SAMPLE_INTERVAL_OS_NETWORK_LIMITS_MS) {
Self::check_os_network_limits(); Self::check_os_network_limits();
} }
@ -1041,16 +1028,18 @@ impl SystemMonitorService {
Self::process_net_stats(&mut udp_stats); Self::process_net_stats(&mut udp_stats);
} }
} }
if report_os_memory_stats && mem_timer.should_update(SAMPLE_INTERVAL_MEM_MS) { if config.report_os_memory_stats && mem_timer.should_update(SAMPLE_INTERVAL_MEM_MS) {
Self::report_mem_stats(); Self::report_mem_stats();
} }
if report_os_cpu_stats && cpu_timer.should_update(SAMPLE_INTERVAL_CPU_MS) { if config.report_os_cpu_stats && cpu_timer.should_update(SAMPLE_INTERVAL_CPU_MS) {
Self::report_cpu_stats(); Self::report_cpu_stats();
} }
if report_os_disk_stats && disk_timer.should_update(SAMPLE_INTERVAL_DISK_MS) { if config.report_os_disk_stats && disk_timer.should_update(SAMPLE_INTERVAL_DISK_MS) {
Self::process_disk_stats(&mut disk_stats); Self::process_disk_stats(&mut disk_stats);
} }
if report_os_open_fd_stats && open_fd_timer.should_update(SAMPLE_INTERVAL_OPEN_FD_MS) { if config.report_os_open_fd_stats
&& open_fd_timer.should_update(SAMPLE_INTERVAL_OPEN_FD_MS)
{
Self::report_open_fd_stats(); Self::report_open_fd_stats();
} }
sleep(SLEEP_INTERVAL); sleep(SLEEP_INTERVAL);

View File

@ -18,7 +18,9 @@ use {
sigverify, sigverify,
snapshot_packager_service::SnapshotPackagerService, snapshot_packager_service::SnapshotPackagerService,
stats_reporter_service::StatsReporterService, stats_reporter_service::StatsReporterService,
system_monitor_service::{verify_net_stats_access, SystemMonitorService}, system_monitor_service::{
verify_net_stats_access, SystemMonitorService, SystemMonitorStatsReportConfig,
},
tower_storage::TowerStorage, tower_storage::TowerStorage,
tpu::{Tpu, TpuSockets, DEFAULT_TPU_COALESCE_MS}, tpu::{Tpu, TpuSockets, DEFAULT_TPU_COALESCE_MS},
tvu::{Tvu, TvuConfig, TvuSockets}, tvu::{Tvu, TvuConfig, TvuSockets},
@ -498,11 +500,13 @@ impl Validator {
let system_monitor_service = Some(SystemMonitorService::new( let system_monitor_service = Some(SystemMonitorService::new(
Arc::clone(&exit), Arc::clone(&exit),
!config.no_os_memory_stats_reporting, SystemMonitorStatsReportConfig {
!config.no_os_network_stats_reporting, report_os_memory_stats: !config.no_os_memory_stats_reporting,
!config.no_os_cpu_stats_reporting, report_os_network_stats: !config.no_os_network_stats_reporting,
!config.no_os_disk_stats_reporting, report_os_cpu_stats: !config.no_os_cpu_stats_reporting,
!config.no_os_open_fd_stats_reporting, report_os_disk_stats: !config.no_os_disk_stats_reporting,
report_os_open_fd_stats: !config.no_os_open_fd_stats_reporting,
},
)); ));
let (poh_timing_point_sender, poh_timing_point_receiver) = unbounded(); let (poh_timing_point_sender, poh_timing_point_receiver) = unbounded();