|
@@ -47,13 +47,14 @@ impl Sensor for NetSpeedSensor {
|
|
|
tx: acc.tx + elem.tx
|
|
|
});
|
|
|
|
|
|
- let output = match self.stats.as_ref() {
|
|
|
- Some(pstats) => {
|
|
|
- let rx = (stats.rx - pstats.rx) / (curr_time - self.last_time);
|
|
|
- let tx = (stats.tx - pstats.tx) / (curr_time - self.last_time);
|
|
|
+ let diff_time = curr_time - self.last_time;
|
|
|
+ let output = match (self.stats.as_ref(), diff_time) {
|
|
|
+ (_, 0) | (None, _) => "?".to_string(),
|
|
|
+ (Some(pstats), diff_time) => {
|
|
|
+ let rx = (stats.rx - pstats.rx) / diff_time;
|
|
|
+ let tx = (stats.tx - pstats.tx) / diff_time;
|
|
|
format!("{}↓ {}↑", format_bytes(rx), format_bytes(tx))
|
|
|
- },
|
|
|
- None => "?".to_string()
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
self.last_time = curr_time;
|