]> granicus.if.org Git - icinga2/commitdiff
Implement HA functionality for Perfdata feature
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 24 Oct 2018 12:07:36 +0000 (14:07 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Wed, 24 Oct 2018 12:42:52 +0000 (14:42 +0200)
lib/perfdata/perfdatawriter.cpp
lib/perfdata/perfdatawriter.hpp
lib/perfdata/perfdatawriter.ti

index a00dc45d7871190138c3cc9c37b45d6e7a922083..c560ef256d1d58778a56e2384036959c98d32c9c 100644 (file)
@@ -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());
 }
index 10fe7a2ddc56a4af09c09f37f9e79d450f951907..56d01d382e261fb0c72711180991e13185af167c 100644 (file)
@@ -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);
index 8381c6c9e8cbcc26e7d42c8b5111081e294e16c4..d2ceb6899ba69f028448f1fef522c07108947922 100644 (file)
@@ -70,6 +70,9 @@ class PerfdataWriter : ConfigObject
        [config] double rotation_interval {
                default {{{ return 30; }}}
        };
+       [config] bool enable_ha {
+               default {{{ return true; }}}
+       };
 };
 
 }