Implement HA functionality for Perfdata feature

This commit is contained in:
Michael Friedrich 2018-10-24 14:07:36 +02:00
parent 97c1296e99
commit 028946a1cc
3 changed files with 32 additions and 8 deletions

View File

@ -38,6 +38,20 @@ REGISTER_TYPE(PerfdataWriter);
REGISTER_STATSFUNCTION(PerfdataWriter, &PerfdataWriter::StatsFunc); REGISTER_STATSFUNCTION(PerfdataWriter, &PerfdataWriter::StatsFunc);
void PerfdataWriter::OnConfigLoaded()
{
ObjectImpl<PerfdataWriter>::OnConfigLoaded();
if (!GetEnableHa()) {
Log(LogDebug, "PerfdataWriter")
<< "HA functionality disabled. Won't pause connection: " << GetName();
SetHAMode(HARunEverywhere);
} else {
SetHAMode(HARunOnce);
}
}
void PerfdataWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&) void PerfdataWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
{ {
DictionaryData nodes; DictionaryData nodes;
@ -49,12 +63,12 @@ void PerfdataWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
status->Set("perfdatawriter", new Dictionary(std::move(nodes))); status->Set("perfdatawriter", new Dictionary(std::move(nodes)));
} }
void PerfdataWriter::Start(bool runtimeCreated) void PerfdataWriter::Resume()
{ {
ObjectImpl<PerfdataWriter>::Start(runtimeCreated); ObjectImpl<PerfdataWriter>::Resume();
Log(LogInformation, "PerfdataWriter") Log(LogInformation, "PerfdataWriter")
<< "'" << GetName() << "' started."; << "'" << GetName() << "' resumed.";
Checkable::OnNewCheckResult.connect(std::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2)); Checkable::OnNewCheckResult.connect(std::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
@ -67,12 +81,12 @@ void PerfdataWriter::Start(bool runtimeCreated)
RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath()); RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath());
} }
void PerfdataWriter::Stop(bool runtimeRemoved) void PerfdataWriter::Pause()
{ {
Log(LogInformation, "PerfdataWriter") Log(LogInformation, "PerfdataWriter")
<< "'" << GetName() << "' stopped."; << "'" << GetName() << "' paused.";
ObjectImpl<PerfdataWriter>::Stop(runtimeRemoved); ObjectImpl<PerfdataWriter>::Pause();
} }
Value PerfdataWriter::EscapeMacroMetric(const Value& value) Value PerfdataWriter::EscapeMacroMetric(const Value& value)
@ -85,6 +99,9 @@ Value PerfdataWriter::EscapeMacroMetric(const Value& value)
void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr) void PerfdataWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{ {
if (IsPaused())
return;
CONTEXT("Writing performance data for object '" + checkable->GetName() + "'"); CONTEXT("Writing performance data for object '" + checkable->GetName() + "'");
if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata()) if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
@ -154,6 +171,9 @@ void PerfdataWriter::RotateFile(std::ofstream& output, const String& temp_path,
void PerfdataWriter::RotationTimerHandler() void PerfdataWriter::RotationTimerHandler()
{ {
if (IsPaused())
return;
RotateFile(m_ServiceOutputFile, GetServiceTempPath(), GetServicePerfdataPath()); RotateFile(m_ServiceOutputFile, GetServiceTempPath(), GetServicePerfdataPath());
RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath()); RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath());
} }

View File

@ -46,8 +46,9 @@ public:
void ValidateServiceFormatTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override; void ValidateServiceFormatTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
protected: protected:
void Start(bool runtimeCreated) override; void OnConfigLoaded() override;
void Stop(bool runtimeRemoved) override; void Resume() override;
void Pause() override;
private: private:
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr); void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);

View File

@ -70,6 +70,9 @@ class PerfdataWriter : ConfigObject
[config] double rotation_interval { [config] double rotation_interval {
default {{{ return 30; }}} default {{{ return 30; }}}
}; };
[config] bool enable_ha {
default {{{ return true; }}}
};
}; };
} }