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)
}
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 {
pub fn new(
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 {
pub fn new(exit: Arc<AtomicBool>, config: SystemMonitorStatsReportConfig) -> Self {
info!("Starting SystemMonitorService");
let thread_hdl = Builder::new()
.name("solSystemMonitr".to_string())
.spawn(move || {
Self::run(
exit,
report_os_memory_stats,
report_os_network_stats,
report_os_cpu_stats,
report_os_disk_stats,
report_os_open_fd_stats,
);
Self::run(exit, config);
})
.unwrap();
@ -1012,14 +1006,7 @@ impl SystemMonitorService {
)
}
pub fn run(
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,
) {
pub fn run(exit: Arc<AtomicBool>, config: SystemMonitorStatsReportConfig) {
let mut udp_stats = None;
let mut disk_stats = None;
let network_limits_timer = AtomicInterval::default();
@ -1033,7 +1020,7 @@ impl SystemMonitorService {
if exit.load(Ordering::Relaxed) {
break;
}
if report_os_network_stats {
if config.report_os_network_stats {
if network_limits_timer.should_update(SAMPLE_INTERVAL_OS_NETWORK_LIMITS_MS) {
Self::check_os_network_limits();
}
@ -1041,16 +1028,18 @@ impl SystemMonitorService {
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();
}
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();
}
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);
}
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();
}
sleep(SLEEP_INTERVAL);

View File

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