Implement statistics for passive service checks.

This commit is contained in:
Gunnar Beutner 2013-01-28 09:01:47 +01:00
parent 1bbd9d629e
commit 2e78899347
8 changed files with 57 additions and 11 deletions

View File

@ -322,7 +322,8 @@ void CompatComponent::StatusTimerHandler(void)
<< "\t" << "check_host_freshness=0" << "\n" << "\t" << "check_host_freshness=0" << "\n"
<< "\t" << "enable_flap_detection=1" << "\n" << "\t" << "enable_flap_detection=1" << "\n"
<< "\t" << "enable_failure_prediction=0" << "\n" << "\t" << "enable_failure_prediction=0" << "\n"
<< "\t" << "active_scheduled_service_check_stats=" << CIB::GetTaskStatistics(60) << "," << CIB::GetTaskStatistics(5 * 60) << "," << CIB::GetTaskStatistics(15 * 60) << "\n" << "\t" << "active_scheduled_service_check_stats=" << CIB::GetActiveChecksStatistics(60) << "," << CIB::GetActiveChecksStatistics(5 * 60) << "," << CIB::GetActiveChecksStatistics(15 * 60) << "\n"
<< "\t" << "passive_service_check_stats=" << CIB::GetPassiveChecksStatistics(60) << "," << CIB::GetPassiveChecksStatistics(5 * 60) << "," << CIB::GetPassiveChecksStatistics(15 * 60) << "\n"
<< "\t" << "}" << "\n" << "\t" << "}" << "\n"
<< "\n"; << "\n";

View File

@ -71,8 +71,23 @@ void ReplicationComponent::ServiceStateChangeRequestHandler(const RequestMessage
//Service::OnCheckResultReceived(service, params); //Service::OnCheckResultReceived(service, params);
//service->ApplyCheckResult(cr); //service->ApplyCheckResult(cr);
time_t now = static_cast<time_t>(Utility::GetTime()); Dictionary::Ptr cr = service->GetLastCheckResult();
CIB::UpdateTaskStatistics(now, 1); if (cr) {
Value active = cr->Get("active");
time_t ts;
Value schedule_end = cr->Get("schedule_end");
if (!schedule_end.IsEmpty())
schedule_end = static_cast<time_t>(schedule_end);
else
schedule_end = static_cast<time_t>(Utility::GetTime());
if (active.IsEmpty() || static_cast<long>(active))
CIB::UpdateActiveChecksStatistics(ts, 1);
else
CIB::UpdatePassiveChecksStatistics(ts, 1);
}
} }
void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint) void ReplicationComponent::EndpointConnectedHandler(const Endpoint::Ptr& endpoint)

View File

@ -452,6 +452,12 @@ void DynamicObject::FinishTx(void)
m_CurrentTx = 0; m_CurrentTx = 0;
} }
void DynamicObject::FlushTx(void)
{
FinishTx();
BeginTx();
}
void DynamicObject::OnAttributeChanged(const String&, const Value&) void DynamicObject::OnAttributeChanged(const String&, const Value&)
{ } { }

View File

@ -140,6 +140,7 @@ public:
static double GetCurrentTx(void); static double GetCurrentTx(void);
static void BeginTx(void); static void BeginTx(void);
static void FinishTx(void); static void FinishTx(void);
static void FlushTx(void);
protected: protected:
virtual void OnAttributeChanged(const String& name, const Value& oldValue); virtual void OnAttributeChanged(const String& name, const Value& oldValue);

View File

@ -21,14 +21,25 @@
using namespace icinga; using namespace icinga;
RingBuffer CIB::m_TaskStatistics(15 * 60); RingBuffer CIB::m_ActiveChecksStatistics(15 * 60);
RingBuffer CIB::m_PassiveChecksStatistics(15 * 60);
void CIB::UpdateTaskStatistics(long tv, int num) void CIB::UpdateActiveChecksStatistics(long tv, int num)
{ {
m_TaskStatistics.InsertValue(tv, num); m_ActiveChecksStatistics.InsertValue(tv, num);
} }
int CIB::GetTaskStatistics(long timespan) int CIB::GetActiveChecksStatistics(long timespan)
{ {
return m_TaskStatistics.GetValues(timespan); return m_ActiveChecksStatistics.GetValues(timespan);
}
void CIB::UpdatePassiveChecksStatistics(long tv, int num)
{
m_PassiveChecksStatistics.InsertValue(tv, num);
}
int CIB::GetPassiveChecksStatistics(long timespan)
{
return m_PassiveChecksStatistics.GetValues(timespan);
} }

View File

@ -32,11 +32,15 @@ namespace icinga
class I2_ICINGA_API CIB class I2_ICINGA_API CIB
{ {
public: public:
static void UpdateTaskStatistics(long tv, int num); static void UpdateActiveChecksStatistics(long tv, int num);
static int GetTaskStatistics(long timespan); static int GetActiveChecksStatistics(long timespan);
static void UpdatePassiveChecksStatistics(long tv, int num);
static int GetPassiveChecksStatistics(long timespan);
private: private:
static RingBuffer m_TaskStatistics; static RingBuffer m_ActiveChecksStatistics;
static RingBuffer m_PassiveChecksStatistics;
}; };
} }

View File

@ -130,6 +130,7 @@ void ExternalCommand::ProcessServiceCheckResult(double time, const vector<String
result->Set("schedule_end", time); result->Set("schedule_end", time);
result->Set("execution_start", time); result->Set("execution_start", time);
result->Set("execution_end", time); result->Set("execution_end", time);
result->Set("active", 0);
Logger::Write(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'"); Logger::Write(LogInformation, "icinga", "Processing passive check result for service '" + arguments[1] + "'");
service->ProcessCheckResult(result); service->ProcessCheckResult(result);

View File

@ -678,6 +678,9 @@ void Service::CheckCompletedHandler(const Dictionary::Ptr& scheduleInfo,
if (!result->Contains("execution_end")) if (!result->Contains("execution_end"))
result->Set("execution_end", scheduleInfo->Get("execution_end")); result->Set("execution_end", scheduleInfo->Get("execution_end"));
if (!result->Contains("active"))
result->Set("active", 1);
ProcessCheckResult(result); ProcessCheckResult(result);
} }
} catch (const exception& ex) { } catch (const exception& ex) {
@ -699,6 +702,10 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
{ {
ApplyCheckResult(cr); ApplyCheckResult(cr);
/* flush the current transaction so other instances see the service's
* new state when they receive the ServiceStateChange message */
DynamicObject::FlushTx();
RequestMessage rm; RequestMessage rm;
rm.SetMethod("checker::ServiceStateChange"); rm.SetMethod("checker::ServiceStateChange");