diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 530a9fbfa..43b6389eb 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -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(Utility::GetTime()); + msgbuf << prefix << "." << name << " " << Convert::ToString(value) << " " << static_cast(ts); Log(LogDebug, "GraphiteWriter") << "Add to metric list:'" << msgbuf.str() << "'."; diff --git a/lib/perfdata/graphitewriter.hpp b/lib/perfdata/graphitewriter.hpp index 6bf25b4aa..f2bc63482 100644 --- a/lib/perfdata/graphitewriter.hpp +++ b/lib/perfdata/graphitewriter.hpp @@ -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);