void InfluxdbWriter::SendPerfdata(const Dictionary::Ptr& tmpl, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, double ts)
{
Array::Ptr perfdata = cr->GetPerformanceData();
+ if (perfdata) {
+ ObjectLock olock(perfdata);
+ for (const Value& val : perfdata) {
+ PerfdataValue::Ptr pdv;
+
+ if (val.IsObjectType<PerfdataValue>())
+ pdv = val;
+ else {
+ try {
+ pdv = PerfdataValue::Parse(val);
+ } catch (const std::exception&) {
+ Log(LogWarning, "InfluxdbWriter")
+ << "Ignoring invalid perfdata value: " << val;
+ continue;
+ }
+ }
- if (!perfdata)
- return;
-
- ObjectLock olock(perfdata);
- for (const Value& val : perfdata) {
- PerfdataValue::Ptr pdv;
-
- if (val.IsObjectType<PerfdataValue>())
- pdv = val;
- else {
- try {
- pdv = PerfdataValue::Parse(val);
- } catch (const std::exception&) {
- Log(LogWarning, "InfluxdbWriter")
- << "Ignoring invalid perfdata value: " << val;
- continue;
+ Dictionary::Ptr fields = new Dictionary();
+ fields->Set(String("value"), pdv->GetValue());
+
+ if (GetEnableSendThresholds()) {
+ if (pdv->GetCrit())
+ fields->Set(String("crit"), pdv->GetCrit());
+ if (pdv->GetWarn())
+ fields->Set(String("warn"), pdv->GetWarn());
+ if (pdv->GetMin())
+ fields->Set(String("min"), pdv->GetMin());
+ if (pdv->GetMax())
+ fields->Set(String("max"), pdv->GetMax());
}
- }
- Dictionary::Ptr fields = new Dictionary();
- fields->Set(String("value"), pdv->GetValue());
-
- if (GetEnableSendThresholds()) {
- if (pdv->GetCrit())
- fields->Set(String("crit"), pdv->GetCrit());
- if (pdv->GetWarn())
- fields->Set(String("warn"), pdv->GetWarn());
- if (pdv->GetMin())
- fields->Set(String("min"), pdv->GetMin());
- if (pdv->GetMax())
- fields->Set(String("max"), pdv->GetMax());
+ SendMetric(tmpl, pdv->GetLabel(), fields, ts);
}
+ }
- if (GetEnableSendMetadata()) {
- Host::Ptr host;
- Service::Ptr service;
- boost::tie(host, service) = GetHostService(checkable);
-
- if (service)
- fields->Set(String("state"), FormatInteger(service->GetState()));
- else
- fields->Set(String("state"), FormatInteger(host->GetState()));
-
- fields->Set(String("current_attempt"), FormatInteger(checkable->GetCheckAttempt()));
- fields->Set(String("max_check_attempts"), FormatInteger(checkable->GetMaxCheckAttempts()));
- fields->Set(String("state_type"), FormatInteger(checkable->GetStateType()));
- fields->Set(String("reachable"), FormatBoolean(checkable->IsReachable()));
- fields->Set(String("downtime_depth"), FormatInteger(checkable->GetDowntimeDepth()));
- fields->Set(String("acknowledgement"), FormatInteger(checkable->GetAcknowledgement()));
- fields->Set(String("latency"), cr->CalculateLatency());
- fields->Set(String("execution_time"), cr->CalculateExecutionTime());
- }
+ if (GetEnableSendMetadata()) {
+ Host::Ptr host;
+ Service::Ptr service;
+ boost::tie(host, service) = GetHostService(checkable);
+
+ Dictionary::Ptr fields = new Dictionary();
- SendMetric(tmpl, pdv->GetLabel(), fields, ts);
+ if (service)
+ fields->Set(String("state"), FormatInteger(service->GetState()));
+ else
+ fields->Set(String("state"), FormatInteger(host->GetState()));
+
+ fields->Set(String("current_attempt"), FormatInteger(checkable->GetCheckAttempt()));
+ fields->Set(String("max_check_attempts"), FormatInteger(checkable->GetMaxCheckAttempts()));
+ fields->Set(String("state_type"), FormatInteger(checkable->GetStateType()));
+ fields->Set(String("reachable"), FormatBoolean(checkable->IsReachable()));
+ fields->Set(String("downtime_depth"), FormatInteger(checkable->GetDowntimeDepth()));
+ fields->Set(String("acknowledgement"), FormatInteger(checkable->GetAcknowledgement()));
+ fields->Set(String("latency"), cr->CalculateLatency());
+ fields->Set(String("execution_time"), cr->CalculateExecutionTime());
+
+ SendMetric(tmpl, String(), fields, ts);
}
}
}
}
- msgbuf << ",metric=" << EscapeKey(label) << " ";
+ // Label is may be empty in the case of metadata
+ if (!label.IsEmpty())
+ msgbuf << ",metric=" << EscapeKey(label);
+
+ msgbuf << " ";
bool first = true;
ObjectLock fieldLock(fields);