src/bin/proxmox-backup-proxy.rs: gather netin/netout stats

This commit is contained in:
Dietmar Maurer 2020-05-24 17:28:05 +02:00
parent 0ed9a2b3ae
commit 8f0cec2642

View File

@ -601,7 +601,8 @@ async fn run_stat_generator() {
}
async fn generate_host_stats() {
use proxmox::sys::linux::procfs::{read_meminfo, read_proc_stat};
use proxmox::sys::linux::procfs::{
read_meminfo, read_proc_stat, read_proc_net_dev};
use proxmox_backup::rrd;
match read_proc_stat() {
@ -627,4 +628,27 @@ async fn generate_host_stats() {
eprintln!("read_meminfo failed - {}", err);
}
}
match read_proc_net_dev() {
Ok(netdev) => {
use proxmox_backup::config::network::is_physical_nic;
let mut netin = 0;
let mut netout = 0;
for item in netdev {
if !is_physical_nic(&item.device) { continue; }
netin += item.receive;
netout += item.send;
}
if let Err(err) = rrd::update_value("host/netin", netin as f64, rrd::DST::Derive) {
eprintln!("rrd::update_value 'host/netin' failed - {}", err);
}
if let Err(err) = rrd::update_value("host/netout", netout as f64, rrd::DST::Derive) {
eprintln!("rrd::update_value 'host/netout' failed - {}", err);
}
}
Err(err) => {
eprintln!("read_prox_net_dev failed - {}", err);
}
}
}