mirror of
https://git.alemi.dev/server-monitor.git
synced 2024-11-23 07:54:48 +01:00
fix: get stats of proper devices (TODO make configurable!)
This commit is contained in:
parent
024afc9345
commit
8387d3ecef
1 changed files with 3 additions and 12 deletions
15
src/main.rs
15
src/main.rs
|
@ -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),
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue