]> granicus.if.org Git - icinga2/commitdiff
Update the flapping detecting formula.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 21 Jun 2013 10:51:29 +0000 (12:51 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 21 Jun 2013 10:51:29 +0000 (12:51 +0200)
lib/icinga/service-flapping.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index 754cb27f9214e4989fea0a5ef2db1a86cc0031fd..8ade1addd4def9f3f5d091907b8f6adae1a3e729 100644 (file)
@@ -23,6 +23,7 @@
 #include "base/logger_fwd.h"
 #include "base/timer.h"
 #include "base/utility.h"
+#include "base/convert.h"
 #include <boost/tuple/tuple.hpp>
 #include <boost/smart_ptr/make_shared.hpp>
 #include <boost/foreach.hpp>
@@ -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;
+
+       Log(LogDebug, "icinga", "Flapping counter for '" + GetName() + "' is positive=" + Convert::ToString(positive) + ", negative=" + Convert::ToString(negative));
 
-       m_FlappingCounter = counter;
-       Touch("flapping_counter");
+       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);
 
 }
index 0a0394f7e47348f25fe76dd96ad279de256fadde..8f5251653efb32275ea5b5bf4affebdb1b429cf4 100644 (file)
@@ -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);
index bc722573e064f61e221508ce48b8c0c11584e6f6..349002396d58ebe5a6e8ae42fd6bcaa741da743e 100644 (file)
@@ -329,7 +329,8 @@ private:
 
        /* Flapping */
        Attribute<bool> m_EnableFlapping;
-       Attribute<long> m_FlappingCounter;
+       Attribute<long> m_FlappingPositive;
+       Attribute<long> m_FlappingNegative;
        Attribute<double> m_FlappingLastChange;
        Attribute<double> m_FlappingThreshold;
 };