fix: get stats of proper devices (TODO make configurable!)

This commit is contained in:
əlemi 2022-10-02 01:49:22 +02:00
parent 024afc9345
commit 8387d3ecef
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -42,16 +42,6 @@ impl Default for DiskDeltaTracker {
}
impl DiskDeltaTracker {
pub fn delta_all(&mut self, disks: BTreeMap<String, BlockDeviceStats>) -> (u64, u64) {
let mut r_tot : u64 = 0;
let mut w_tot : u64 = 0;
for drive in disks.values() {
r_tot += drive.read_sectors as u64;
w_tot += drive.write_sectors as u64;
}
return self.delta(r_tot, w_tot);
}
pub fn delta(&mut self, r: u64, w: u64) -> (u64, u64) {
let out = (r - self.r, w - self.w);
self.r = r;
@ -149,7 +139,8 @@ async fn stats_delta(
let net_tracker = store_disk.get_mut(&session).unwrap();
let disks = sys.block_device_statistics().map_err(to_403_err)?;
(disk_r, disk_w) = net_tracker.delta_all(disks);
let disk = disks.get("sda2").ok_or(Unauthorized(Some("not found".to_string())))?;
(disk_r, disk_w) = net_tracker.delta(disk.read_sectors as u64, disk.write_sectors as u64);
}
Ok(Json(SystemInfoView {
@ -167,7 +158,7 @@ async fn stats_delta(
async fn stats_total() -> Json<SystemInfoView> {
let sys = System::new();
let (net_tx, net_rx) = match sys.network_stats(&"enp5s0".to_string()) {
let (net_tx, net_rx) = match sys.network_stats(&"eth0".to_string()) {
Ok(stats) => (stats.tx_bytes.as_u64(), stats.rx_bytes.as_u64()),
Err(_e) => (0, 0),
};