diff --git a/src/admin/mod.rs b/src/admin/mod.rs index 44a8a4a3..3cb7ad43 100644 --- a/src/admin/mod.rs +++ b/src/admin/mod.rs @@ -170,7 +170,11 @@ mod handlers { let delta = match (current.unwrap().get(&key), previous.map(|p| p.get(&key))) { (Some(current), Some(Some(previous))) => { - current.wrapping_sub(previous).unwrap() + if snapshots.len() < 61 { + current.clone() + } else { + current.wrapping_sub(previous).unwrap() + } } (Some(current), Some(None)) | (Some(current), None) => current.clone(), _ => { @@ -262,7 +266,11 @@ mod handlers { let delta = match (current.unwrap().get(&key), previous.map(|p| p.get(&key))) { (Some(current), Some(Some(previous))) => { - current.wrapping_sub(previous).unwrap() + if snapshots.len() < 61 { + current.clone() + } else { + current.wrapping_sub(previous).unwrap() + } } (Some(current), Some(None)) | (Some(current), None) => current.clone(), _ => { @@ -345,7 +353,11 @@ mod handlers { let delta = match (current.unwrap().get(&key), previous.map(|p| p.get(&key))) { (Some(current), Some(Some(previous))) => { - current.wrapping_sub(previous).unwrap() + if snapshots.len() < 61 { + current.clone() + } else { + current.wrapping_sub(previous).unwrap() + } } (Some(current), Some(None)) | (Some(current), None) => current.clone(), _ => { diff --git a/src/main.rs b/src/main.rs index 41f4d7d8..abd8ac36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,7 +149,9 @@ fn main() { let mut snapshots = SNAPSHOTS.write().await; - if snapshots.len() == 60 { + // we maintain 1 minute of history, which requires 61 secondly + // snapshots + if snapshots.len() == 61 { let _ = snapshots.pop_front(); }