Fix slow queries sensor value calculation

This commit is contained in:
Daniel 2023-05-08 13:08:12 +02:00
parent 7958dfd41d
commit a2b2021360

View file

@ -31,13 +31,15 @@ func reportRequestDuration(started time.Time, resolver *Resolver) {
// getSlowQueriesSensorValue returns the current avg query time recorded by the // getSlowQueriesSensorValue returns the current avg query time recorded by the
// slow queries sensor. // slow queries sensor.
func getSlowQueriesSensorValue() (avgQueryTime time.Duration) { func getSlowQueriesSensorValue() (avgQueryTime time.Duration) {
return time.Duration( // Get values and check them.
slowQueriesSensorSum.Load() / slowQueriesSensorCnt.Load(), sum := slowQueriesSensorSum.Load()
) cnt := slowQueriesSensorCnt.Load()
} if cnt < 1 {
cnt = 1
}
// getAndResetSlowQueriesSensorValue returns the current avg query time return time.Duration(sum / cnt)
// recorded by the slow queries sensor and reset the sensor values. }
// resetSlowQueriesSensorValue reset the slow queries sensor values. // resetSlowQueriesSensorValue reset the slow queries sensor values.
func resetSlowQueriesSensorValue() { func resetSlowQueriesSensorValue() {