mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
GraphiteWriter: Improve Pause/Shutdown/Reload handling for metrics
This commit is contained in:
parent
388999a86f
commit
d79390083d
@ -102,12 +102,26 @@ void GraphiteWriter::Resume()
|
|||||||
Checkable::OnNewCheckResult.connect(std::bind(&GraphiteWriter::CheckResultHandler, this, _1, _2));
|
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()
|
void GraphiteWriter::Pause()
|
||||||
{
|
{
|
||||||
|
m_ReconnectTimer.reset();
|
||||||
|
|
||||||
|
try {
|
||||||
|
ReconnectInternal();
|
||||||
|
} catch (const std::exception&) {
|
||||||
Log(LogInformation, "GraphiteWriter")
|
Log(LogInformation, "GraphiteWriter")
|
||||||
<< "'" << GetName() << "' paused.";
|
<< "'" << GetName() << "' paused. Unable to connect, not flushing buffers. Data may be lost on reload.";
|
||||||
|
|
||||||
|
ObjectImpl<GraphiteWriter>::Pause();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_WorkQueue.Join();
|
m_WorkQueue.Join();
|
||||||
|
DisconnectInternal();
|
||||||
|
|
||||||
|
Log(LogInformation, "GraphiteWriter")
|
||||||
|
<< "'" << GetName() << "' paused.";
|
||||||
|
|
||||||
ObjectImpl<GraphiteWriter>::Pause();
|
ObjectImpl<GraphiteWriter>::Pause();
|
||||||
}
|
}
|
||||||
@ -140,6 +154,11 @@ void GraphiteWriter::Reconnect()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReconnectInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphiteWriter::ReconnectInternal()
|
||||||
|
{
|
||||||
double startTime = Utility::GetTime();
|
double startTime = Utility::GetTime();
|
||||||
|
|
||||||
CONTEXT("Reconnecting to Graphite '" + GetName() + "'");
|
CONTEXT("Reconnecting to Graphite '" + GetName() + "'");
|
||||||
@ -172,6 +191,9 @@ void GraphiteWriter::Reconnect()
|
|||||||
|
|
||||||
void GraphiteWriter::ReconnectTimerHandler()
|
void GraphiteWriter::ReconnectTimerHandler()
|
||||||
{
|
{
|
||||||
|
if (IsPaused())
|
||||||
|
return;
|
||||||
|
|
||||||
m_WorkQueue.Enqueue(std::bind(&GraphiteWriter::Reconnect, this), PriorityNormal);
|
m_WorkQueue.Enqueue(std::bind(&GraphiteWriter::Reconnect, this), PriorityNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +201,11 @@ void GraphiteWriter::Disconnect()
|
|||||||
{
|
{
|
||||||
AssertOnWorkQueue();
|
AssertOnWorkQueue();
|
||||||
|
|
||||||
|
DisconnectInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphiteWriter::DisconnectInternal()
|
||||||
|
{
|
||||||
if (!GetConnected())
|
if (!GetConnected())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -201,6 +228,10 @@ void GraphiteWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable,
|
|||||||
|
|
||||||
CONTEXT("Processing check result for '" + checkable->GetName() + "'");
|
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())
|
if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
|
||||||
return;
|
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);
|
msgbuf << prefix << "." << name << " " << Convert::ToString(value) << " " << static_cast<long>(ts);
|
||||||
|
|
||||||
Log(LogDebug, "GraphiteWriter")
|
Log(LogDebug, "GraphiteWriter")
|
||||||
<< "Add to metric list:'" << msgbuf.str() << "'.";
|
<< "Add to metric list: '" << msgbuf.str() << "'.";
|
||||||
|
|
||||||
// do not send \n to debug log
|
// do not send \n to debug log
|
||||||
msgbuf << "\n";
|
msgbuf << "\n";
|
||||||
|
@ -71,7 +71,9 @@ private:
|
|||||||
void ReconnectTimerHandler();
|
void ReconnectTimerHandler();
|
||||||
|
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
|
void DisconnectInternal();
|
||||||
void Reconnect();
|
void Reconnect();
|
||||||
|
void ReconnectInternal();
|
||||||
|
|
||||||
void AssertOnWorkQueue();
|
void AssertOnWorkQueue();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user