}
}
- SendPerfdata(tmpl, cr, ts);
+ SendPerfdata(tmpl, checkable, cr, ts);
}
-void InfluxdbWriter::SendPerfdata(const Dictionary::Ptr& tmpl, const CheckResult::Ptr& cr, double ts)
+String InfluxdbWriter::FormatInteger(const int val)
+{
+ return Convert::ToString(val) + "i";
+}
+
+String InfluxdbWriter::FormatBoolean(const bool val)
+{
+ return val ? "true" : "false";
+}
+
+void InfluxdbWriter::SendPerfdata(const Dictionary::Ptr& tmpl, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, double ts)
{
Array::Ptr perfdata = cr->GetPerformanceData();
Dictionary::Ptr fields = new Dictionary();
fields->Set(String("value"), pdv->GetValue());
+
if (GetEnableSendThresholds()) {
if (pdv->GetCrit())
fields->Set(String("crit"), pdv->GetCrit());
fields->Set(String("max"), pdv->GetMax());
}
+ 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("latency"), cr->CalculateLatency());
+ fields->Set(String("execution_time"), cr->CalculateExecutionTime());
+ }
+
SendMetric(tmpl, pdv->GetLabel(), fields, ts);
}
}
String InfluxdbWriter::EscapeField(const String& str)
{
- // Technically everything entering here from PerfdataValue is a
- // double, but best have the safety net in place.
+ // Handle integers
+ boost::regex integer("-?\\d+i");
+ if (boost::regex_match(str.GetData(), integer)) {
+ return str;
+ }
// Handle numerics
boost::regex numeric("-?\\d+(\\.\\d+)?((e|E)[+-]?\\d+)?");
} catch (const std::exception&) {
Log(LogWarning, "InfluxdbWriter")
<< "Cannot write to TCP socket on host '" << GetHost() << "' port '" << GetPort() << "'.";
+ return;
}
HttpResponse resp(stream, req);
try {
resp.Parse(context, true);
- } catch (const std::exception) {
+ } catch (const std::exception&) {
Log(LogWarning, "InfluxdbWriter")
<< "Cannot read from TCP socket from host '" << GetHost() << "' port '" << GetPort() << "'.";
+ return;
}
if (resp.StatusCode != 204) {
Array::Ptr m_DataBuffer;
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
- void SendPerfdata(const Dictionary::Ptr& tmpl, const CheckResult::Ptr& cr, double ts);
+ void SendPerfdata(const Dictionary::Ptr& tmpl, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, double ts);
void SendMetric(const Dictionary::Ptr& tmpl, const String& label, const Dictionary::Ptr& fields, double ts);
void FlushTimeout(void);
void Flush(void);
+ static String FormatInteger(const int val);
+ static String FormatBoolean(const bool val);
+
static String EscapeKey(const String& str);
static String EscapeField(const String& str);