]> granicus.if.org Git - icinga2/commitdiff
Implement HA functionality for Graphite feature
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 24 Oct 2018 11:29:27 +0000 (13:29 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Wed, 24 Oct 2018 11:44:52 +0000 (13:44 +0200)
lib/perfdata/graphitewriter.cpp
lib/perfdata/graphitewriter.hpp
lib/perfdata/graphitewriter.ti

index d58e2c53ba1fccb01b514e2ee13b65df5793128b..a01f6c48bf6329e79f525c087270b4930ab03aca 100644 (file)
@@ -49,6 +49,15 @@ void GraphiteWriter::OnConfigLoaded()
        ObjectImpl<GraphiteWriter>::OnConfigLoaded();
 
        m_WorkQueue.SetName("GraphiteWriter, " + GetName());
+
+       if (!GetEnableHa()) {
+               Log(LogDebug, "GraphiteWriter")
+                       << "HA functionality disabled. Won't pause connection: " << GetName();
+
+               SetHAMode(HARunEverywhere);
+       } else {
+               SetHAMode(HARunOnce);
+       }
 }
 
 void GraphiteWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata)
@@ -72,12 +81,12 @@ void GraphiteWriter::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&
        status->Set("graphitewriter", new Dictionary(std::move(nodes)));
 }
 
-void GraphiteWriter::Start(bool runtimeCreated)
+void GraphiteWriter::Resume()
 {
-       ObjectImpl<GraphiteWriter>::Start(runtimeCreated);
+       ObjectImpl<GraphiteWriter>::Resume();
 
        Log(LogInformation, "GraphiteWriter")
-               << "'" << GetName() << "' started.";
+               << "'" << GetName() << "' resumed.";
 
        /* Register exception handler for WQ tasks. */
        m_WorkQueue.SetExceptionCallback(std::bind(&GraphiteWriter::ExceptionHandler, this, _1));
@@ -93,14 +102,14 @@ void GraphiteWriter::Start(bool runtimeCreated)
        Checkable::OnNewCheckResult.connect(std::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2));
 }
 
-void GraphiteWriter::Stop(bool runtimeRemoved)
+void GraphiteWriter::Pause()
 {
        Log(LogInformation, "GraphiteWriter")
-               << "'" << GetName() << "' stopped.";
+               << "'" << GetName() << "' paused.";
 
        m_WorkQueue.Join();
 
-       ObjectImpl<GraphiteWriter>::Stop(runtimeRemoved);
+       ObjectImpl<GraphiteWriter>::Pause();
 }
 
 void GraphiteWriter::AssertOnWorkQueue()
@@ -126,6 +135,11 @@ void GraphiteWriter::Reconnect()
 {
        AssertOnWorkQueue();
 
+       if (IsPaused()) {
+               SetConnected(false);
+               return;
+       }
+
        double startTime = Utility::GetTime();
 
        CONTEXT("Reconnecting to Graphite '" + GetName() + "'");
@@ -175,6 +189,9 @@ void GraphiteWriter::Disconnect()
 
 void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
 {
+       if (IsPaused())
+               return;
+
        m_WorkQueue.Enqueue(std::bind(&GraphiteWriter::CheckResultHandlerInternal, this, checkable, cr));
 }
 
index 48a2f4203b82f403f01092de1f7d935caaaf7d6f..6934d13b35d86d3c0209b6470b512a190f14e54b 100644 (file)
@@ -49,8 +49,8 @@ public:
 
 protected:
        void OnConfigLoaded() override;
-       void Start(bool runtimeCreated) override;
-       void Stop(bool runtimeRemoved) override;
+       void Resume() override;
+       void Pause() override;
 
 private:
        Stream::Ptr m_Stream;
index dfe62a14b38d339c1445e48ff094f2e5a648d646..b28ba87a954351d113b4120c367adb03b1c9cb24 100644 (file)
@@ -47,6 +47,9 @@ class GraphiteWriter : ConfigObject
        [no_user_modify] bool should_connect {
                default {{{ return true; }}}
        };
+       [config] bool enable_ha {
+               default {{{ return true; }}}
+       };
 };
 
 }