mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 05:04:30 +02:00
Moved task stats to the CIB.
Refactored CheckResult class into a message-based class.
This commit is contained in:
parent
b54ebc56dc
commit
3ec746bd2f
@ -174,7 +174,8 @@ void CompatComponent::StatusTimerHandler(void)
|
|||||||
<< "\t" << "check_host_freshness=0" << endl
|
<< "\t" << "check_host_freshness=0" << endl
|
||||||
<< "\t" << "enable_flap_detection=1" << endl
|
<< "\t" << "enable_flap_detection=1" << endl
|
||||||
<< "\t" << "enable_failure_prediction=0" << 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
|
<< "\t" << "active_scheduled_service_check_stats=" << CIB::GetTaskStatistics(60) << "," << CIB::GetTaskStatistics(5 * 60) << "," << CIB::GetTaskStatistics(15 * 60) << endl
|
||||||
|
<< "\t" << "}" << endl
|
||||||
<< endl;
|
<< endl;
|
||||||
|
|
||||||
ofstream objectfp;
|
ofstream objectfp;
|
||||||
|
@ -2,99 +2,86 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
CheckResult::CheckResult(void)
|
|
||||||
: m_Data(boost::make_shared<Dictionary>())
|
|
||||||
{ }
|
|
||||||
|
|
||||||
CheckResult::CheckResult(const Dictionary::Ptr& dictionary)
|
|
||||||
: m_Data(dictionary)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
Dictionary::Ptr CheckResult::GetDictionary(void) const
|
|
||||||
{
|
|
||||||
return m_Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CheckResult::SetScheduleStart(time_t ts)
|
void CheckResult::SetScheduleStart(time_t ts)
|
||||||
{
|
{
|
||||||
m_Data->SetProperty("schedule_start", static_cast<long>(ts));
|
SetProperty("schedule_start", static_cast<long>(ts));
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t CheckResult::GetScheduleStart(void) const
|
time_t CheckResult::GetScheduleStart(void) const
|
||||||
{
|
{
|
||||||
long value = 0;
|
long value = 0;
|
||||||
m_Data->GetProperty("schedule_start", &value);
|
GetProperty("schedule_start", &value);
|
||||||
return static_cast<time_t>(value);
|
return static_cast<time_t>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckResult::SetScheduleEnd(time_t ts)
|
void CheckResult::SetScheduleEnd(time_t ts)
|
||||||
{
|
{
|
||||||
m_Data->SetProperty("schedule_end", static_cast<long>(ts));
|
SetProperty("schedule_end", static_cast<long>(ts));
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t CheckResult::GetScheduleEnd(void) const
|
time_t CheckResult::GetScheduleEnd(void) const
|
||||||
{
|
{
|
||||||
long value = 0;
|
long value = 0;
|
||||||
m_Data->GetProperty("schedule_end", &value);
|
GetProperty("schedule_end", &value);
|
||||||
return static_cast<time_t>(value);
|
return static_cast<time_t>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckResult::SetExecutionStart(time_t ts)
|
void CheckResult::SetExecutionStart(time_t ts)
|
||||||
{
|
{
|
||||||
m_Data->SetProperty("execution_start", static_cast<long>(ts));
|
SetProperty("execution_start", static_cast<long>(ts));
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t CheckResult::GetExecutionStart(void) const
|
time_t CheckResult::GetExecutionStart(void) const
|
||||||
{
|
{
|
||||||
long value = 0;
|
long value = 0;
|
||||||
m_Data->GetProperty("execution_start", &value);
|
GetProperty("execution_start", &value);
|
||||||
return static_cast<time_t>(value);
|
return static_cast<time_t>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckResult::SetExecutionEnd(time_t ts)
|
void CheckResult::SetExecutionEnd(time_t ts)
|
||||||
{
|
{
|
||||||
m_Data->SetProperty("execution_end", static_cast<long>(ts));
|
SetProperty("execution_end", static_cast<long>(ts));
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t CheckResult::GetExecutionEnd(void) const
|
time_t CheckResult::GetExecutionEnd(void) const
|
||||||
{
|
{
|
||||||
long value = 0;
|
long value = 0;
|
||||||
m_Data->GetProperty("execution_end", &value);
|
GetProperty("execution_end", &value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckResult::SetState(ServiceState state)
|
void CheckResult::SetState(ServiceState state)
|
||||||
{
|
{
|
||||||
m_Data->SetProperty("state", static_cast<long>(state));
|
SetProperty("state", static_cast<long>(state));
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceState CheckResult::GetState(void) const
|
ServiceState CheckResult::GetState(void) const
|
||||||
{
|
{
|
||||||
long value = StateUnknown;
|
long value = StateUnknown;
|
||||||
m_Data->GetProperty("state", &value);
|
GetProperty("state", &value);
|
||||||
return static_cast<ServiceState>(value);
|
return static_cast<ServiceState>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckResult::SetOutput(string output)
|
void CheckResult::SetOutput(string output)
|
||||||
{
|
{
|
||||||
m_Data->SetProperty("output", output);
|
SetProperty("output", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
string CheckResult::GetOutput(void) const
|
string CheckResult::GetOutput(void) const
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
m_Data->GetProperty("output", &value);
|
GetProperty("output", &value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckResult::SetPerformanceData(const Dictionary::Ptr& pd)
|
void CheckResult::SetPerformanceData(const Dictionary::Ptr& pd)
|
||||||
{
|
{
|
||||||
m_Data->SetProperty("performance_data", pd);
|
SetProperty("performance_data", pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr CheckResult::GetPerformanceData(void) const
|
Dictionary::Ptr CheckResult::GetPerformanceData(void) const
|
||||||
{
|
{
|
||||||
Dictionary::Ptr value;
|
Dictionary::Ptr value;
|
||||||
m_Data->GetProperty("performance_data", &value);
|
GetProperty("performance_data", &value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,11 @@
|
|||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
|
|
||||||
struct CheckResult
|
class CheckResult : public MessagePart
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CheckResult(void);
|
CheckResult(void) : MessagePart() { }
|
||||||
CheckResult(const Dictionary::Ptr& dictionary);
|
CheckResult(const MessagePart& message) : MessagePart(message) { }
|
||||||
|
|
||||||
Dictionary::Ptr GetDictionary(void) const;
|
|
||||||
|
|
||||||
void SetScheduleStart(time_t ts);
|
void SetScheduleStart(time_t ts);
|
||||||
time_t GetScheduleStart(void) const;
|
time_t GetScheduleStart(void) const;
|
||||||
@ -32,9 +30,6 @@ public:
|
|||||||
|
|
||||||
void SetPerformanceData(const Dictionary::Ptr& pd);
|
void SetPerformanceData(const Dictionary::Ptr& pd);
|
||||||
Dictionary::Ptr GetPerformanceData(void) const;
|
Dictionary::Ptr GetPerformanceData(void) const;
|
||||||
|
|
||||||
private:
|
|
||||||
Dictionary::Ptr m_Data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ using namespace icinga;
|
|||||||
map<string, CheckTaskType> CheckTask::m_Types;
|
map<string, CheckTaskType> CheckTask::m_Types;
|
||||||
vector<CheckTask::Ptr> CheckTask::m_FinishedTasks;
|
vector<CheckTask::Ptr> CheckTask::m_FinishedTasks;
|
||||||
mutex CheckTask::m_FinishedTasksMutex;
|
mutex CheckTask::m_FinishedTasksMutex;
|
||||||
Ringbuffer CheckTask::m_TaskStatistics(15 * 60);
|
|
||||||
|
|
||||||
CheckTask::CheckTask(const Service& service)
|
CheckTask::CheckTask(const Service& service)
|
||||||
: m_Service(service)
|
: m_Service(service)
|
||||||
@ -68,11 +67,5 @@ void CheckTask::FinishTask(const CheckTask::Ptr& task)
|
|||||||
{
|
{
|
||||||
mutex::scoped_lock lock(m_FinishedTasksMutex);
|
mutex::scoped_lock lock(m_FinishedTasksMutex);
|
||||||
m_FinishedTasks.push_back(task);
|
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);
|
|
||||||
}
|
|
||||||
|
@ -29,8 +29,6 @@ public:
|
|||||||
static void FinishTask(const CheckTask::Ptr& task);
|
static void FinishTask(const CheckTask::Ptr& task);
|
||||||
static vector<CheckTask::Ptr> GetFinishedTasks(void);
|
static vector<CheckTask::Ptr> GetFinishedTasks(void);
|
||||||
|
|
||||||
static int GetTaskStatistics(time_t timespan);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CheckTask(const Service& service);
|
CheckTask(const Service& service);
|
||||||
|
|
||||||
@ -42,7 +40,6 @@ private:
|
|||||||
|
|
||||||
static vector<CheckTask::Ptr> m_FinishedTasks;
|
static vector<CheckTask::Ptr> m_FinishedTasks;
|
||||||
static mutex m_FinishedTasksMutex;
|
static mutex m_FinishedTasksMutex;
|
||||||
static Ringbuffer m_TaskStatistics;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CheckTaskType
|
struct CheckTaskType
|
||||||
|
@ -4,6 +4,7 @@ using namespace icinga;
|
|||||||
|
|
||||||
int CIB::m_Types;
|
int CIB::m_Types;
|
||||||
VirtualEndpoint::Ptr CIB::m_Endpoint;
|
VirtualEndpoint::Ptr CIB::m_Endpoint;
|
||||||
|
Ringbuffer CIB::m_TaskStatistics(15 * 60);
|
||||||
|
|
||||||
void CIB::RequireInformation(InformationType types)
|
void CIB::RequireInformation(InformationType types)
|
||||||
{
|
{
|
||||||
@ -63,5 +64,13 @@ void CIB::ServiceStatusRequestHandler(const Endpoint::Ptr& sender, const Request
|
|||||||
Dictionary::Ptr cr;
|
Dictionary::Ptr cr;
|
||||||
if (params.GetProperty("result", &cr))
|
if (params.GetProperty("result", &cr))
|
||||||
service.SetLastCheckResult(cr);
|
service.SetLastCheckResult(cr);
|
||||||
|
|
||||||
|
time_t now;
|
||||||
|
time(&now);
|
||||||
|
m_TaskStatistics.InsertValue(now, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CIB::GetTaskStatistics(long timespan)
|
||||||
|
{
|
||||||
|
return m_TaskStatistics.GetValues(timespan);
|
||||||
|
}
|
||||||
|
@ -18,10 +18,14 @@ public:
|
|||||||
|
|
||||||
static void Start(void);
|
static void Start(void);
|
||||||
|
|
||||||
|
static int GetTaskStatistics(long timespan);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int m_Types;
|
static int m_Types;
|
||||||
static VirtualEndpoint::Ptr m_Endpoint;
|
static VirtualEndpoint::Ptr m_Endpoint;
|
||||||
|
|
||||||
|
static Ringbuffer m_TaskStatistics;
|
||||||
|
|
||||||
static void ServiceStatusRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
static void ServiceStatusRequestHandler(const Endpoint::Ptr& sender, const RequestMessage& request);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -51,26 +51,21 @@ void JsonRpcClient::SendMessage(const MessagePart& message)
|
|||||||
void JsonRpcClient::DataAvailableHandler(void)
|
void JsonRpcClient::DataAvailableHandler(void)
|
||||||
{
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
string jsonString;
|
||||||
|
MessagePart message;
|
||||||
|
|
||||||
|
{
|
||||||
|
mutex::scoped_lock lock(GetMutex());
|
||||||
|
|
||||||
|
if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
string jsonString;
|
|
||||||
MessagePart message;
|
|
||||||
|
|
||||||
{
|
|
||||||
mutex::scoped_lock lock(GetMutex());
|
|
||||||
|
|
||||||
if (!Netstring::ReadStringFromFIFO(GetRecvQueue(), &jsonString))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cerr << jsonString << std::endl;
|
|
||||||
|
|
||||||
message = MessagePart(jsonString);
|
message = MessagePart(jsonString);
|
||||||
OnNewMessage(GetSelf(), message);
|
OnNewMessage(GetSelf(), message);
|
||||||
} catch (const std::exception& ex) {
|
} catch (const std::exception& ex) {
|
||||||
Application::Log(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.what()));
|
Application::Log(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + string(ex.what()));
|
||||||
Close();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user