From 7f513a9aea5794b9bb703a344a066a06fc3f8078 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 21 Jun 2013 12:51:29 +0200 Subject: [PATCH] Update the flapping detecting formula. --- lib/icinga/service-flapping.cpp | 37 +++++++++++++++++++++------------ lib/icinga/service.cpp | 3 ++- lib/icinga/service.h | 3 ++- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lib/icinga/service-flapping.cpp b/lib/icinga/service-flapping.cpp index 754cb27f9..8ade1addd 100644 --- a/lib/icinga/service-flapping.cpp +++ b/lib/icinga/service-flapping.cpp @@ -23,6 +23,7 @@ #include "base/logger_fwd.h" #include "base/timer.h" #include "base/utility.h" +#include "base/convert.h" #include #include #include @@ -49,28 +50,40 @@ void Service::SetEnableFlapping(bool enabled) void Service::UpdateFlappingStatus(bool stateChange) { double ts, now; - long counter; + long positive, negative; now = Utility::GetTime(); if (m_FlappingLastChange.IsEmpty()) { ts = now; - counter = 0; + positive = 0; + negative = 0; } else { ts = m_FlappingLastChange; - counter = m_FlappingCounter; + positive = m_FlappingPositive; + negative = m_FlappingNegative; } double diff = now - ts; - if (diff > 0) - counter -= 0.5 * m_FlappingCounter / (diff / FLAPPING_INTERVAL); + if (positive + negative > FLAPPING_INTERVAL) { + double pct = (positive + negative - FLAPPING_INTERVAL) / FLAPPING_INTERVAL; + positive -= pct * positive; + negative -= pct * negative; + } if (stateChange) - counter += diff; + positive += diff; + else + negative += diff; - m_FlappingCounter = counter; - Touch("flapping_counter"); + Log(LogDebug, "icinga", "Flapping counter for '" + GetName() + "' is positive=" + Convert::ToString(positive) + ", negative=" + Convert::ToString(negative)); + + m_FlappingPositive = positive; + Touch("flapping_positive"); + + m_FlappingNegative = negative; + Touch("flapping_negative"); m_FlappingLastChange = now; Touch("flapping_lastchange"); @@ -78,16 +91,14 @@ void Service::UpdateFlappingStatus(bool stateChange) bool Service::IsFlapping(void) const { - double threshold = 30; + double threshold = 20; if (!m_FlappingThreshold.IsEmpty()) threshold = m_FlappingThreshold; - if (m_FlappingCounter.IsEmpty()) + if (m_FlappingNegative.IsEmpty() || m_FlappingPositive.IsEmpty()) return false; - long counter = m_FlappingCounter; - - return (counter > threshold * FLAPPING_INTERVAL / 100); + return (m_FlappingPositive > threshold * (m_FlappingPositive + m_FlappingNegative) / 100); } diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 0a0394f7e..8f5251653 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -83,7 +83,8 @@ Service::Service(const Dictionary::Ptr& serializedObject) RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications); RegisterAttribute("force_next_notification", Attribute_Replicated, &m_ForceNextNotification); - RegisterAttribute("flapping_counter", Attribute_Replicated, &m_FlappingCounter); + RegisterAttribute("flapping_positive", Attribute_Replicated, &m_FlappingPositive); + RegisterAttribute("flapping_negative", Attribute_Replicated, &m_FlappingNegative); RegisterAttribute("flapping_lastchange", Attribute_Replicated, &m_FlappingLastChange); RegisterAttribute("flapping_threshold", Attribute_Config, &m_FlappingThreshold); RegisterAttribute("enable_flapping", Attribute_Config, &m_EnableFlapping); diff --git a/lib/icinga/service.h b/lib/icinga/service.h index bc722573e..349002396 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -329,7 +329,8 @@ private: /* Flapping */ Attribute m_EnableFlapping; - Attribute m_FlappingCounter; + Attribute m_FlappingPositive; + Attribute m_FlappingNegative; Attribute m_FlappingLastChange; Attribute m_FlappingThreshold; };