]> granicus.if.org Git - icinga2/commitdiff
Implement task statistics.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 28 Jun 2012 13:43:49 +0000 (15:43 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 28 Jun 2012 13:43:49 +0000 (15:43 +0200)
base/Makefile.am
base/i2-base.h
base/ringbuffer.cpp [new file with mode: 0644]
base/ringbuffer.h [new file with mode: 0644]
components/compat/compatcomponent.cpp
icinga/checktask.cpp
icinga/checktask.h

index 5ceedd7306eac85fd6967a34a35f518b538317cb..b7bd623221062ead7cfab5eab0fe47c3eb88c491 100644 (file)
@@ -26,6 +26,8 @@ libbase_la_SOURCES =  \
        objectset.h \
        objectmap.cpp \
        objectmap.h \
+       ringbuffer.cpp \
+       ringbuffer.h \
        socket.cpp \
        socket.h \
        tcpclient.cpp \
index f795e507ef44a74ef9e35f2e86ab15ed253fc976..fbd44ca178d58e3f2571dbc3810579a91d9ddd25 100644 (file)
@@ -154,6 +154,7 @@ using boost::system_time;
 #include "event.h"
 #include "variant.h"
 #include "dictionary.h"
+#include "ringbuffer.h"
 #include "timer.h"
 #include "fifo.h"
 #include "socket.h"
diff --git a/base/ringbuffer.cpp b/base/ringbuffer.cpp
new file mode 100644 (file)
index 0000000..88a0948
--- /dev/null
@@ -0,0 +1,49 @@
+#include "i2-base.h"
+
+using namespace icinga;
+
+Ringbuffer::Ringbuffer(int slots)
+       : m_Slots(slots, 0), m_Offset(0)
+{ }
+
+int Ringbuffer::GetLength(void) const
+{
+       return m_Slots.size();
+}
+
+void Ringbuffer::InsertValue(long tv, int num)
+{
+       int offsetTarget = tv % m_Slots.size();
+
+       /* walk towards the target offset, resetting slots to 0 */
+       while (m_Offset != offsetTarget) {
+               m_Offset++;
+
+               if (m_Offset >= m_Slots.size())
+                       m_Offset = 0;
+
+               m_Slots[m_Offset] = 0;
+       }
+
+       m_Slots[m_Offset] += num;
+}
+
+int Ringbuffer::GetValues(long span) const
+{
+       if (span > m_Slots.size())
+               span = m_Slots.size();
+
+       int off = m_Offset;
+       int sum = 0;
+       while (span > 0) {
+               sum += m_Slots[off];
+
+               if (off == 0)
+                       off = m_Slots.size();
+
+               off--;
+               span--;
+       }
+
+       return sum;
+}
diff --git a/base/ringbuffer.h b/base/ringbuffer.h
new file mode 100644 (file)
index 0000000..a74f784
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef RINGBUFFER_H
+#define RINGBUFFER_H
+
+namespace icinga
+{
+
+class Ringbuffer
+{
+public:
+       Ringbuffer(int slots);
+
+       int GetLength(void) const;
+       void InsertValue(long tv, int num);
+       int GetValues(long span) const;
+
+private:
+       vector<int> m_Slots;
+       int m_Offset;
+};
+
+}
+
+#endif /* RINGBUFFER_H */
index 191d89768953956dd05d0b76472acf977e0e90d5..cb1328a79f54ee101bbf83797f4b15fb2d5df36a 100644 (file)
@@ -117,7 +117,7 @@ void CompatComponent::DumpServiceStatus(ofstream& fp, Service service)
           << "\t" << "current_state=" << service.GetState() << endl
           << "\t" << "state_type=" << service.GetStateType() << endl
           << "\t" << "plugin_output=" << plugin_output << endl
-          << "\t" << "last_check=" << schedule_start << endl
+          << "\t" << "last_check=" << schedule_end << endl
           << "\t" << "next_check=" << service.GetNextCheck() << endl
           << "\t" << "current_attempt=" << service.GetCurrentCheckAttempt() << endl
           << "\t" << "max_attempts=" << service.GetMaxCheckAttempts() << endl
@@ -174,6 +174,7 @@ void CompatComponent::StatusTimerHandler(void)
                 << "\t" << "check_host_freshness=0" << endl
                 << "\t" << "enable_flap_detection=1" << endl
                 << "\t" << "enable_failure_prediction=0" << endl
+                << "\t" << "active_scheduled_service_check_stats=" << CheckTask::GetTaskStatistics(60) << "," << CheckTask::GetTaskStatistics(5 * 60) << "," << CheckTask::GetTaskStatistics(15 * 60) << endl
                 << endl;
 
        ofstream objectfp;
index e94f7ed008eae795b218a2ba89a0cc4c40300c98..be78472ac011219c86734cb027e3edfd04c96948 100644 (file)
@@ -5,6 +5,7 @@ using namespace icinga;
 map<string, CheckTaskType> CheckTask::m_Types;
 vector<CheckTask::Ptr> CheckTask::m_FinishedTasks;
 mutex CheckTask::m_FinishedTasksMutex;
+Ringbuffer CheckTask::m_TaskStatistics(15 * 60);
 
 CheckTask::CheckTask(const Service& service)
        : m_Service(service)
@@ -67,4 +68,11 @@ void CheckTask::FinishTask(const CheckTask::Ptr& task)
 {
        mutex::scoped_lock lock(m_FinishedTasksMutex);
        m_FinishedTasks.push_back(task);
+       m_TaskStatistics.InsertValue(task->GetResult().GetScheduleEnd(), 1);
+}
+
+int CheckTask::GetTaskStatistics(time_t timespan)
+{
+       mutex::scoped_lock lock(m_FinishedTasksMutex);
+       return m_TaskStatistics.GetValues(timespan);
 }
index 92f4f04601145867b86fbde3c61751dee20bdbc3..e3a6799a8b381f78fa16170cb4c68960e4914f30 100644 (file)
@@ -25,9 +25,12 @@ public:
        static void Enqueue(const CheckTask::Ptr& task);
        static void FlushQueue(void);
 
+       static int GetTaskHistogramSlots(void);
        static void FinishTask(const CheckTask::Ptr& task);
        static vector<CheckTask::Ptr> GetFinishedTasks(void);
 
+       static int GetTaskStatistics(time_t timespan);
+
 protected:
        CheckTask(const Service& service);
 
@@ -39,6 +42,7 @@ private:
 
        static vector<CheckTask::Ptr> m_FinishedTasks;
        static mutex m_FinishedTasksMutex;
+       static Ringbuffer m_TaskStatistics;
 };
 
 struct CheckTaskType