pub fn init_sys_info_poll() {
    struct FiveAvg {
        idx: usize,
        data: [u64; 5],
    }

    impl FiveAvg {
        pub fn new() -> Self {
            Self {
                idx: 0,
                data: [0; 5],
            }
        }

        pub fn push(&mut self, val: u64) {
            self.data[self.idx] = val;
            self.idx += 1;
            if self.idx >= self.data.len() {
                self.idx = 0;
            }
        }

        pub fn avg(&self) -> u64 {
            let mut tot = 0;
            for f in self.data.iter() {
                tot += f;
            }
            tot / self.data.len() as u64
        }
    }

    SYS_INFO.call_once(|| {
        metric_task(async move {
            let mut system = sysinfo::System::new_with_specifics(
                sysinfo::RefreshKind::new()
                    .with_networks()
                    .with_networks_list(),
            );

            let pid = sysinfo::get_current_pid().unwrap();
            let mut tx_avg = FiveAvg::new();
            let mut rx_avg = FiveAvg::new();

            loop {
                system.refresh_process(pid);
                system.get_networks_mut().refresh();

                let proc = system.get_process(pid).unwrap();

                let mem = proc.memory();
                USED_MEM_KB.store(mem, Ordering::Relaxed);

                let cpu = (proc.cpu_usage() * 1000.0) as usize;
                PROC_CPU_USAGE_PCT_1000.store(cpu, Ordering::Relaxed);

                let mut tx = 0;
                let mut rx = 0;
                for (_n, network) in system.get_networks().iter() {
                    tx += network.get_transmitted();
                    rx += network.get_received();
                }
                tx_avg.push(tx);
                rx_avg.push(rx);
                TX_BYTES_PER_SEC.store(tx_avg.avg(), Ordering::Relaxed);
                RX_BYTES_PER_SEC.store(rx_avg.avg(), Ordering::Relaxed);

                tokio::time::delay_for(std::time::Duration::from_secs(1)).await;
            }

            // this is needed for type-ing the block, but will never return
            #[allow(unreachable_code)]
            <Result<(), ()>>::Ok(())
        });
    });
}
/// Initialize polling of system usage info
Initialize polling of system usage info
Initialize polling of system usage info
pub fn init_sys_info_poll() {
    struct FiveAvg {
        idx: usize,
        data: [u64; 5],
    }
    impl FiveAvg {
        pub fn new() -> Self {
            Self {
                idx: 0,
                data: [0; 5],
            }
        }
        pub fn push(&mut self, val: u64) {
            self.data[self.idx] = val;
            self.idx += 1;
            if self.idx >= self.data.len() {
                self.idx = 0;
            }
        }
        pub fn avg(&self) -> u64 {
            let mut tot = 0;
            for f in self.data.iter() {
                tot += f;
            }
            tot / self.data.len() as u64
        }
    }
    SYS_INFO.call_once(|| {
        metric_task(async move {
            let mut system = sysinfo::System::new_with_specifics(
                sysinfo::RefreshKind::new()
                    .with_networks()
                    .with_networks_list(),
            );
            let pid = sysinfo::get_current_pid().unwrap();
            let mut tx_avg = FiveAvg::new();
            let mut rx_avg = FiveAvg::new();
            loop {
                system.refresh_process(pid);
                system.get_networks_mut().refresh();
                let proc = system.get_process(pid).unwrap();
                let mem = proc.memory();
                USED_MEM_KB.store(mem, Ordering::Relaxed);
                let cpu = (proc.cpu_usage() * 1000.0) as usize;
                PROC_CPU_USAGE_PCT_1000.store(cpu, Ordering::Relaxed);
                let mut tx = 0;
                let mut rx = 0;
                for (_n, network) in system.get_networks().iter() {
                    tx += network.get_transmitted();
                    rx += network.get_received();
                }
                tx_avg.push(tx);
                rx_avg.push(rx);
                TX_BYTES_PER_SEC.store(tx_avg.avg(), Ordering::Relaxed);
                RX_BYTES_PER_SEC.store(rx_avg.avg(), Ordering::Relaxed);
                tokio::time::delay_for(std::time::Duration::from_secs(1)).await;
            }
            // this is needed for type-ing the block, but will never return
            #[allow(unreachable_code)]
            <Result<(), ()>>::Ok(())
        });
    });
}
pub fn init_sys_info_poll ( ) { struct FiveAvg { idx : usize , data : [ u64 ; 5 ] , } impl FiveAvg { pub fn new ( ) -> Self { Self { idx : 0 , data : [ 0 ; 5 ] , } } pub fn push ( & mut self , val : u64 ) { self . data [ self . idx ] = val ; self . idx += 1 ; if self . idx >= self . data . len ( ) { self . idx = 0 ; } } pub fn avg ( & self ) -> u64 { let mut tot = 0 ; for f in self . data . iter ( ) { tot += f ; } tot / self . data . len ( ) as u64 } } SYS_INFO . call_once ( | | { metric_task ( async move { let mut system = sysinfo :: System :: new_with_specifics ( sysinfo :: RefreshKind :: new ( ) . with_networks ( ) . with_networks_list ( ) , ) ; let pid = sysinfo :: get_current_pid ( ) . unwrap ( ) ; let mut tx_avg = FiveAvg :: new ( ) ; let mut rx_avg = FiveAvg :: new ( ) ; loop { system . refresh_process ( pid ) ; system . get_networks_mut ( ) . refresh ( ) ; let proc = system . get_process ( pid ) . unwrap ( ) ; let mem = proc . memory ( ) ; USED_MEM_KB . store ( mem , Ordering :: Relaxed ) ; let cpu = ( proc . cpu_usage ( ) * 1000.0 ) as usize ; PROC_CPU_USAGE_PCT_1000 . store ( cpu , Ordering :: Relaxed ) ; let mut tx = 0 ; let mut rx = 0 ; for ( _n , network ) in system . get_networks ( ) . iter ( ) { tx += network . get_transmitted ( ) ; rx += network . get_received ( ) ; } tx_avg . push ( tx ) ; rx_avg . push ( rx ) ; TX_BYTES_PER_SEC . store ( tx_avg . avg ( ) , Ordering :: Relaxed ) ; RX_BYTES_PER_SEC . store ( rx_avg . avg ( ) , Ordering :: Relaxed ) ; tokio :: time :: delay_for ( std :: time :: Duration :: from_secs ( 1 ) ) . await ; } // this is needed for type-ing the block, but will never return # [ allow ( unreachable_code ) ] < Result < ( ) , ( ) > > :: Ok ( ( ) ) } ) ; } ) ; }
Initialize polling of system usage info
Initialize polling of system usage info