From eb0a19062eba79a39a57b9de1486c279e06eca4f Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Thu, 22 Oct 2015 10:55:26 -0600 Subject: [PATCH] When MongoDB freezes or restarts, do not report negative diffs Fixes #253 --- plugins/mongodb/mongostat.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/mongodb/mongostat.go b/plugins/mongodb/mongostat.go index b3c990b1a..585512d88 100644 --- a/plugins/mongodb/mongostat.go +++ b/plugins/mongodb/mongostat.go @@ -367,7 +367,11 @@ func computeLockDiffs(prevLocks, curLocks map[string]LockUsage) []LockUsage { } func diff(newVal, oldVal, sampleTime int64) int64 { - return (newVal - oldVal) / sampleTime + d := newVal - oldVal + if d <= 0 { + d = newVal + } + return d / sampleTime } // NewStatLine constructs a StatLine object from two ServerStatus objects.