Add timestamp support for Graphite

fixes #8374
This commit is contained in:
Gunnar Beutner 2015-02-06 08:51:33 +01:00
parent c9362dc247
commit 20d999e275
2 changed files with 22 additions and 20 deletions

View File

@ -116,27 +116,29 @@ void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
String prefix;
double ts = cr->GetExecutionEnd();
if (service) {
prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr, NULL, &GraphiteWriter::EscapeMacroMetric);
SendMetric(prefix, "state", service->GetState());
SendMetric(prefix, "state", service->GetState(), ts);
} else {
prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr, NULL, &GraphiteWriter::EscapeMacroMetric);
SendMetric(prefix, "state", host->GetState());
SendMetric(prefix, "state", host->GetState(), ts);
}
SendMetric(prefix, "current_attempt", checkable->GetCheckAttempt());
SendMetric(prefix, "max_check_attempts", checkable->GetMaxCheckAttempts());
SendMetric(prefix, "state_type", checkable->GetStateType());
SendMetric(prefix, "reachable", checkable->IsReachable());
SendMetric(prefix, "downtime_depth", checkable->GetDowntimeDepth());
SendMetric(prefix, "latency", Service::CalculateLatency(cr));
SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr));
SendPerfdata(prefix, cr);
SendMetric(prefix, "current_attempt", checkable->GetCheckAttempt(), ts);
SendMetric(prefix, "max_check_attempts", checkable->GetMaxCheckAttempts(), ts);
SendMetric(prefix, "state_type", checkable->GetStateType(), ts);
SendMetric(prefix, "reachable", checkable->IsReachable(), ts);
SendMetric(prefix, "downtime_depth", checkable->GetDowntimeDepth(), ts);
SendMetric(prefix, "latency", Service::CalculateLatency(cr), ts);
SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr), ts);
SendPerfdata(prefix, cr, ts);
}
void GraphiteWriter::SendPerfdata(const String& prefix, const CheckResult::Ptr& cr)
void GraphiteWriter::SendPerfdata(const String& prefix, const CheckResult::Ptr& cr, double ts)
{
Array::Ptr perfdata = cr->GetPerformanceData();
@ -162,23 +164,23 @@ void GraphiteWriter::SendPerfdata(const String& prefix, const CheckResult::Ptr&
String escaped_key = EscapeMetric(pdv->GetLabel());
boost::algorithm::replace_all(escaped_key, "::", ".");
SendMetric(prefix, escaped_key, pdv->GetValue());
SendMetric(prefix, escaped_key, pdv->GetValue(), ts);
if (pdv->GetCrit())
SendMetric(prefix, escaped_key + "_crit", pdv->GetCrit());
SendMetric(prefix, escaped_key + "_crit", pdv->GetCrit(), ts);
if (pdv->GetWarn())
SendMetric(prefix, escaped_key + "_warn", pdv->GetWarn());
SendMetric(prefix, escaped_key + "_warn", pdv->GetWarn(), ts);
if (pdv->GetMin())
SendMetric(prefix, escaped_key + "_min", pdv->GetMin());
SendMetric(prefix, escaped_key + "_min", pdv->GetMin(), ts);
if (pdv->GetMax())
SendMetric(prefix, escaped_key + "_max", pdv->GetMax());
SendMetric(prefix, escaped_key + "_max", pdv->GetMax(), ts);
}
}
void GraphiteWriter::SendMetric(const String& prefix, const String& name, double value)
void GraphiteWriter::SendMetric(const String& prefix, const String& name, double value, double ts)
{
std::ostringstream msgbuf;
msgbuf << prefix << "." << name << " " << Convert::ToString(value) << " " << static_cast<long>(Utility::GetTime());
msgbuf << prefix << "." << name << " " << Convert::ToString(value) << " " << static_cast<long>(ts);
Log(LogDebug, "GraphiteWriter")
<< "Add to metric list:'" << msgbuf.str() << "'.";

View File

@ -52,8 +52,8 @@ private:
Timer::Ptr m_ReconnectTimer;
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
void SendMetric(const String& prefix, const String& name, double value);
void SendPerfdata(const String& prefix, const CheckResult::Ptr& cr);
void SendMetric(const String& prefix, const String& name, double value, double ts);
void SendPerfdata(const String& prefix, const CheckResult::Ptr& cr, double ts);
static String EscapeMetric(const String& str);
static Value EscapeMacroMetric(const Value& value);