mirror of https://github.com/Icinga/icinga2.git
Implement HA functionality for Perfdata feature
This commit is contained in:
parent
97c1296e99
commit
028946a1cc
|
@ -38,6 +38,20 @@ REGISTER_TYPE(PerfdataWriter);
|
|||
|
||||
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&)
|
||||
{
|
||||
DictionaryData nodes;
|
||||
|
@ -49,12 +63,12 @@ void PerfdataWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&)
|
|||
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")
|
||||
<< "'" << GetName() << "' started.";
|
||||
<< "'" << GetName() << "' resumed.";
|
||||
|
||||
Checkable::OnNewCheckResult.connect(std::bind(&PerfdataWriter::CheckResultHandler, this, _1, _2));
|
||||
|
||||
|
@ -67,12 +81,12 @@ void PerfdataWriter::Start(bool runtimeCreated)
|
|||
RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath());
|
||||
}
|
||||
|
||||
void PerfdataWriter::Stop(bool runtimeRemoved)
|
||||
void PerfdataWriter::Pause()
|
||||
{
|
||||
Log(LogInformation, "PerfdataWriter")
|
||||
<< "'" << GetName() << "' stopped.";
|
||||
<< "'" << GetName() << "' paused.";
|
||||
|
||||
ObjectImpl<PerfdataWriter>::Stop(runtimeRemoved);
|
||||
ObjectImpl<PerfdataWriter>::Pause();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (IsPaused())
|
||||
return;
|
||||
|
||||
CONTEXT("Writing performance data for object '" + checkable->GetName() + "'");
|
||||
|
||||
if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
|
||||
|
@ -154,6 +171,9 @@ void PerfdataWriter::RotateFile(std::ofstream& output, const String& temp_path,
|
|||
|
||||
void PerfdataWriter::RotationTimerHandler()
|
||||
{
|
||||
if (IsPaused())
|
||||
return;
|
||||
|
||||
RotateFile(m_ServiceOutputFile, GetServiceTempPath(), GetServicePerfdataPath());
|
||||
RotateFile(m_HostOutputFile, GetHostTempPath(), GetHostPerfdataPath());
|
||||
}
|
||||
|
|
|
@ -46,8 +46,9 @@ public:
|
|||
void ValidateServiceFormatTemplate(const Lazy<String>& lvalue, const ValidationUtils& utils) override;
|
||||
|
||||
protected:
|
||||
void Start(bool runtimeCreated) override;
|
||||
void Stop(bool runtimeRemoved) override;
|
||||
void OnConfigLoaded() override;
|
||||
void Resume() override;
|
||||
void Pause() override;
|
||||
|
||||
private:
|
||||
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
||||
|
|
|
@ -70,6 +70,9 @@ class PerfdataWriter : ConfigObject
|
|||
[config] double rotation_interval {
|
||||
default {{{ return 30; }}}
|
||||
};
|
||||
[config] bool enable_ha {
|
||||
default {{{ return true; }}}
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue