#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>
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");
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);
}
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);