Update the flapping detecting formula.

This commit is contained in:
Gunnar Beutner 2013-06-21 12:51:29 +02:00
parent 6f158ff793
commit 7f513a9aea
3 changed files with 28 additions and 15 deletions

View File

@ -23,6 +23,7 @@
#include "base/logger_fwd.h" #include "base/logger_fwd.h"
#include "base/timer.h" #include "base/timer.h"
#include "base/utility.h" #include "base/utility.h"
#include "base/convert.h"
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/smart_ptr/make_shared.hpp> #include <boost/smart_ptr/make_shared.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
@ -49,28 +50,40 @@ void Service::SetEnableFlapping(bool enabled)
void Service::UpdateFlappingStatus(bool stateChange) void Service::UpdateFlappingStatus(bool stateChange)
{ {
double ts, now; double ts, now;
long counter; long positive, negative;
now = Utility::GetTime(); now = Utility::GetTime();
if (m_FlappingLastChange.IsEmpty()) { if (m_FlappingLastChange.IsEmpty()) {
ts = now; ts = now;
counter = 0; positive = 0;
negative = 0;
} else { } else {
ts = m_FlappingLastChange; ts = m_FlappingLastChange;
counter = m_FlappingCounter; positive = m_FlappingPositive;
negative = m_FlappingNegative;
} }
double diff = now - ts; double diff = now - ts;
if (diff > 0) if (positive + negative > FLAPPING_INTERVAL) {
counter -= 0.5 * m_FlappingCounter / (diff / FLAPPING_INTERVAL); double pct = (positive + negative - FLAPPING_INTERVAL) / FLAPPING_INTERVAL;
positive -= pct * positive;
negative -= pct * negative;
}
if (stateChange) if (stateChange)
counter += diff; positive += diff;
else
negative += diff;
m_FlappingCounter = counter; Log(LogDebug, "icinga", "Flapping counter for '" + GetName() + "' is positive=" + Convert::ToString(positive) + ", negative=" + Convert::ToString(negative));
Touch("flapping_counter");
m_FlappingPositive = positive;
Touch("flapping_positive");
m_FlappingNegative = negative;
Touch("flapping_negative");
m_FlappingLastChange = now; m_FlappingLastChange = now;
Touch("flapping_lastchange"); Touch("flapping_lastchange");
@ -78,16 +91,14 @@ void Service::UpdateFlappingStatus(bool stateChange)
bool Service::IsFlapping(void) const bool Service::IsFlapping(void) const
{ {
double threshold = 30; double threshold = 20;
if (!m_FlappingThreshold.IsEmpty()) if (!m_FlappingThreshold.IsEmpty())
threshold = m_FlappingThreshold; threshold = m_FlappingThreshold;
if (m_FlappingCounter.IsEmpty()) if (m_FlappingNegative.IsEmpty() || m_FlappingPositive.IsEmpty())
return false; return false;
long counter = m_FlappingCounter; return (m_FlappingPositive > threshold * (m_FlappingPositive + m_FlappingNegative) / 100);
return (counter > threshold * FLAPPING_INTERVAL / 100);
} }

View File

@ -83,7 +83,8 @@ Service::Service(const Dictionary::Ptr& serializedObject)
RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications); RegisterAttribute("enable_notifications", Attribute_Replicated, &m_EnableNotifications);
RegisterAttribute("force_next_notification", Attribute_Replicated, &m_ForceNextNotification); 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_lastchange", Attribute_Replicated, &m_FlappingLastChange);
RegisterAttribute("flapping_threshold", Attribute_Config, &m_FlappingThreshold); RegisterAttribute("flapping_threshold", Attribute_Config, &m_FlappingThreshold);
RegisterAttribute("enable_flapping", Attribute_Config, &m_EnableFlapping); RegisterAttribute("enable_flapping", Attribute_Config, &m_EnableFlapping);

View File

@ -329,7 +329,8 @@ private:
/* Flapping */ /* Flapping */
Attribute<bool> m_EnableFlapping; Attribute<bool> m_EnableFlapping;
Attribute<long> m_FlappingCounter; Attribute<long> m_FlappingPositive;
Attribute<long> m_FlappingNegative;
Attribute<double> m_FlappingLastChange; Attribute<double> m_FlappingLastChange;
Attribute<double> m_FlappingThreshold; Attribute<double> m_FlappingThreshold;
}; };