mirror of https://github.com/Icinga/icinga2.git
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:
parent
851135d3a1
commit
2c37a00daf
|
@ -171,61 +171,63 @@ 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) {
|
||||
ObjectLock olock(perfdata);
|
||||
for (const Value& val : perfdata) {
|
||||
PerfdataValue::Ptr pdv;
|
||||
|
||||
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;
|
||||
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());
|
||||
}
|
||||
|
||||
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();
|
||||
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());
|
||||
}
|
||||
if (service)
|
||||
fields->Set(String("state"), FormatInteger(service->GetState()));
|
||||
else
|
||||
fields->Set(String("state"), FormatInteger(host->GetState()));
|
||||
|
||||
if (GetEnableSendMetadata()) {
|
||||
Host::Ptr host;
|
||||
Service::Ptr service;
|
||||
boost::tie(host, service) = GetHostService(checkable);
|
||||
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 (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, 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);
|
||||
|
|
Loading…
Reference in New Issue