]> granicus.if.org Git - icinga2/commitdiff
GraphiteWriter: Improve Pause/Shutdown/Reload handling for metrics
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 20 Feb 2019 13:54:23 +0000 (14:54 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Wed, 20 Feb 2019 13:54:23 +0000 (14:54 +0100)
lib/perfdata/graphitewriter.cpp
lib/perfdata/graphitewriter.hpp

index 1b6461d51378fb9d504e95890bd5b220cd3c02e0..5fa4479e673570b9ad013f027a3701b4c73e5b5d 100644 (file)
@@ -102,12 +102,26 @@ void GraphiteWriter::Resume()
        Checkable::OnNewCheckResult.connect(std::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2));
 }
 
+/* Pause is equivalent to Stop, but with HA capabilities to resume at runtime. */
 void GraphiteWriter::Pause()
 {
-       Log(LogInformation, "GraphiteWriter")
-               << "'" << GetName() << "' paused.";
+       m_ReconnectTimer.reset();
+
+       try {
+               ReconnectInternal();
+       } catch (const std::exception&) {
+               Log(LogInformation, "GraphiteWriter")
+                       << "'" << GetName() << "' paused. Unable to connect, not flushing buffers. Data may be lost on reload.";
+
+               ObjectImpl<GraphiteWriter>::Pause();
+               return;
+       }
 
        m_WorkQueue.Join();
+       DisconnectInternal();
+
+       Log(LogInformation, "GraphiteWriter")
+               << "'" << GetName() << "' paused.";
 
        ObjectImpl<GraphiteWriter>::Pause();
 }
@@ -140,6 +154,11 @@ void GraphiteWriter::Reconnect()
                return;
        }
 
+       ReconnectInternal();
+}
+
+void GraphiteWriter::ReconnectInternal()
+{
        double startTime = Utility::GetTime();
 
        CONTEXT("Reconnecting to Graphite '" + GetName() + "'");
@@ -172,6 +191,9 @@ void GraphiteWriter::Reconnect()
 
 void GraphiteWriter::ReconnectTimerHandler()
 {
+       if (IsPaused())
+               return;
+
        m_WorkQueue.Enqueue(std::bind(&GraphiteWriter::Reconnect, this), PriorityNormal);
 }
 
@@ -179,6 +201,11 @@ void GraphiteWriter::Disconnect()
 {
        AssertOnWorkQueue();
 
+       DisconnectInternal();
+}
+
+void GraphiteWriter::DisconnectInternal()
+{
        if (!GetConnected())
                return;
 
@@ -201,6 +228,10 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable,
 
        CONTEXT("Processing check result for '" + checkable->GetName() + "'");
 
+       /* TODO: Deal with missing connection here. Needs refactoring
+        * into parsing the actual performance data and then putting it
+        * into a queue for re-inserting. */
+
        if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
                return;
 
@@ -293,7 +324,7 @@ void GraphiteWriter::SendMetric(const String& prefix, const String& name, double
        msgbuf << prefix << "." << name << " " << Convert::ToString(value) << " " << static_cast<long>(ts);
 
        Log(LogDebug, "GraphiteWriter")
-               << "Add to metric list:'" << msgbuf.str() << "'.";
+               << "Add to metric list: '" << msgbuf.str() << "'.";
 
        // do not send \n to debug log
        msgbuf << "\n";
index ec4c5bbfe0f736ae712d0449c5351c8679a0d9f5..2a4443e96a8318a5bc46528348141285b5e03a2b 100644 (file)
@@ -71,7 +71,9 @@ private:
        void ReconnectTimerHandler();
 
        void Disconnect();
+       void DisconnectInternal();
        void Reconnect();
+       void ReconnectInternal();
 
        void AssertOnWorkQueue();