InfluxDB: Always Write Out Metadata

Previously the logic would just bail out if no performance data was associated with a
check, the problem being that check metadata was skipped too.  This rearranges the code
to dump out performance metrics if they exist, then dump out metadata if requested.  This
also fixes an issue whereby metadata was being sent for every performance data in the
check result, rather than just once, so we save a bit of bandwidth as a result.

fixes #12276

Signed-off-by: Michael Friedrich <michael.friedrich@icinga.com>
This commit is contained in:
Simon Murray 2016-10-06 10:49:00 +01:00 committed by Michael Friedrich
parent 851135d3a1
commit 2c37a00daf

View File

@ -171,10 +171,7 @@ String InfluxdbWriter::FormatBoolean(const bool val)
void InfluxdbWriter::SendPerfdata(const Dictionary::Ptr& tmpl, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, double ts)
{
Array::Ptr perfdata = cr->GetPerformanceData();
if (!perfdata)
return;
if (perfdata) {
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;
@ -205,11 +202,17 @@ void InfluxdbWriter::SendPerfdata(const Dictionary::Ptr& tmpl, const Checkable::
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);
Dictionary::Ptr fields = new Dictionary();
if (service)
fields->Set(String("state"), FormatInteger(service->GetState()));
else
@ -223,9 +226,8 @@ void InfluxdbWriter::SendPerfdata(const Dictionary::Ptr& tmpl, const Checkable::
fields->Set(String("acknowledgement"), FormatInteger(checkable->GetAcknowledgement()));
fields->Set(String("latency"), cr->CalculateLatency());
fields->Set(String("execution_time"), cr->CalculateExecutionTime());
}
SendMetric(tmpl, pdv->GetLabel(), fields, ts);
SendMetric(tmpl, String(), fields, ts);
}
}
@ -294,7 +296,11 @@ void InfluxdbWriter::SendMetric(const Dictionary::Ptr& tmpl, const String& label
}
}
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);