#include "perfdata/opentsdbwriter.hpp"
#include "perfdata/opentsdbwriter-ti.cpp"
#include "icinga/service.hpp"
+#include "icinga/checkcommand.hpp"
#include "icinga/macroprocessor.hpp"
#include "icinga/icingaapplication.hpp"
#include "icinga/compatutility.hpp"
String escaped_serviceName = EscapeMetric(serviceName);
metric = "icinga.service." + escaped_serviceName;
- SendMetric(metric + ".state", tags, service->GetState(), ts);
+ SendMetric(checkable, metric + ".state", tags, service->GetState(), ts);
} else {
metric = "icinga.host";
- SendMetric(metric + ".state", tags, host->GetState(), ts);
+ SendMetric(checkable, metric + ".state", tags, host->GetState(), ts);
}
- SendMetric(metric + ".state_type", tags, checkable->GetStateType(), ts);
- SendMetric(metric + ".reachable", tags, checkable->IsReachable(), ts);
- SendMetric(metric + ".downtime_depth", tags, checkable->GetDowntimeDepth(), ts);
- SendMetric(metric + ".acknowledgement", tags, checkable->GetAcknowledgement(), ts);
+ SendMetric(checkable, metric + ".state_type", tags, checkable->GetStateType(), ts);
+ SendMetric(checkable, metric + ".reachable", tags, checkable->IsReachable(), ts);
+ SendMetric(checkable, metric + ".downtime_depth", tags, checkable->GetDowntimeDepth(), ts);
+ SendMetric(checkable, metric + ".acknowledgement", tags, checkable->GetAcknowledgement(), ts);
- SendPerfdata(metric, tags, cr, ts);
+ SendPerfdata(checkable, metric, tags, cr, ts);
metric = "icinga.check";
tags["type"] = "host";
}
- SendMetric(metric + ".current_attempt", tags, checkable->GetCheckAttempt(), ts);
- SendMetric(metric + ".max_check_attempts", tags, checkable->GetMaxCheckAttempts(), ts);
- SendMetric(metric + ".latency", tags, cr->CalculateLatency(), ts);
- SendMetric(metric + ".execution_time", tags, cr->CalculateExecutionTime(), ts);
+ SendMetric(checkable, metric + ".current_attempt", tags, checkable->GetCheckAttempt(), ts);
+ SendMetric(checkable, metric + ".max_check_attempts", tags, checkable->GetMaxCheckAttempts(), ts);
+ SendMetric(checkable, metric + ".latency", tags, cr->CalculateLatency(), ts);
+ SendMetric(checkable, metric + ".execution_time", tags, cr->CalculateExecutionTime(), ts);
}
-void OpenTsdbWriter::SendPerfdata(const String& metric, const std::map<String, String>& tags, const CheckResult::Ptr& cr, double ts)
+void OpenTsdbWriter::SendPerfdata(const Checkable::Ptr& checkable, const String& metric,
+ const std::map<String, String>& tags, const CheckResult::Ptr& cr, double ts)
{
Array::Ptr perfdata = cr->GetPerformanceData();
if (!perfdata)
return;
+ CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();
+
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;
pdv = PerfdataValue::Parse(val);
} catch (const std::exception&) {
Log(LogWarning, "OpenTsdbWriter")
- << "Ignoring invalid perfdata value: " << val;
+ << "Ignoring invalid perfdata for checkable '"
+ << checkable->GetName() << "' and command '"
+ << checkCommand->GetName() << "' with value: " << val;
continue;
}
}
String escaped_key = EscapeMetric(pdv->GetLabel());
boost::algorithm::replace_all(escaped_key, "::", ".");
- SendMetric(metric + "." + escaped_key, tags, pdv->GetValue(), ts);
+ SendMetric(checkable, metric + "." + escaped_key, tags, pdv->GetValue(), ts);
if (pdv->GetCrit())
- SendMetric(metric + "." + escaped_key + "_crit", tags, pdv->GetCrit(), ts);
+ SendMetric(checkable, metric + "." + escaped_key + "_crit", tags, pdv->GetCrit(), ts);
if (pdv->GetWarn())
- SendMetric(metric + "." + escaped_key + "_warn", tags, pdv->GetWarn(), ts);
+ SendMetric(checkable, metric + "." + escaped_key + "_warn", tags, pdv->GetWarn(), ts);
if (pdv->GetMin())
- SendMetric(metric + "." + escaped_key + "_min", tags, pdv->GetMin(), ts);
+ SendMetric(checkable, metric + "." + escaped_key + "_min", tags, pdv->GetMin(), ts);
if (pdv->GetMax())
- SendMetric(metric + "." + escaped_key + "_max", tags, pdv->GetMax(), ts);
+ SendMetric(checkable, metric + "." + escaped_key + "_max", tags, pdv->GetMax(), ts);
}
}
-void OpenTsdbWriter::SendMetric(const String& metric, const std::map<String, String>& tags, double value, double ts)
+void OpenTsdbWriter::SendMetric(const Checkable::Ptr& checkable, const String& metric,
+ const std::map<String, String>& tags, double value, double ts)
{
String tags_string = "";
+
for (const Dictionary::Pair& tag : tags) {
tags_string += " " + tag.first + "=" + Convert::ToString(tag.second);
}
msgbuf << "put " << metric << " " << static_cast<long>(ts) << " " << Convert::ToString(value) << " " << tags_string;
Log(LogDebug, "OpenTsdbWriter")
- << "Add to metric list:'" << msgbuf.str() << "'.";
+ << "Checkable '" << checkable->GetName() << "' adds to metric list: '" << msgbuf.str() << "'.";
/* do not send \n to debug log */
msgbuf << "\n";