[icinga-checkins] icinga.org: icinga2/master: Update the flapping detecting formula.
git at icinga.org
git at icinga.org
Fri Jun 21 12:51:45 CEST 2013
Module: icinga2
Branch: master
Commit: 7f513a9aea5794b9bb703a344a066a06fc3f8078
URL: https://git.icinga.org/?p=icinga2.git;a=commit;h=7f513a9aea5794b9bb703a344a066a06fc3f8078
Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date: Fri Jun 21 12:51:29 2013 +0200
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 754cb27..8ade1ad 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 <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);
}
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index 0a0394f..8f52516 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 bc72257..3490023 100644
--- a/lib/icinga/service.h
+++ b/lib/icinga/service.h
@@ -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;
};
More information about the icinga-checkins
mailing list