/******************************************************************************
* Icinga 2 *
- * Copyright (C) 2012-present Icinga Development Team (http://www.icinga.org) *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
return;
}
} catch (const std::exception& ex) {
- Log(LogWarning, "perfdata", "GraphiteWriter socket on host '" + GetHost() + "' port '" + GetPort() + "' gone. Attempting to reconnect.");
+ Log(LogWarning, "perfdata", "GraphiteWriter socket on host '" + GetHost() + "' port '" + GetPort() + "' gone. Attempting to reconnect.");
}
TcpSocket::Ptr socket = make_shared<TcpSocket>();
m_Stream = make_shared<BufferedStream>(net_stream);
}
-void GraphiteWriter::CheckResultHandler(const Service::Ptr& service, const CheckResult::Ptr& cr)
+void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
- if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !service->GetEnablePerfdata())
+ if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
return;
- /* TODO: sanitize host and service names */
- String hostName = service->GetHost()->GetName();
- String serviceName = service->GetShortName();
+ Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
+ Host::Ptr host;
+ if (service)
+ host = service->GetHost();
+ else
+ host = static_pointer_cast<Host>(checkable);
+
+ String hostName = host->GetName();
SanitizeMetric(hostName);
- SanitizeMetric(serviceName);
- String prefix = "icinga." + hostName + "." + serviceName;
+ String prefix;
+
+ if (service) {
+ String serviceName = service->GetShortName();
+ SanitizeMetric(serviceName);
+ prefix = "icinga." + hostName + "." + serviceName;
- /* basic metrics */
- SendMetric(prefix, "current_attempt", service->GetCheckAttempt());
- SendMetric(prefix, "max_check_attempts", service->GetMaxCheckAttempts());
- SendMetric(prefix, "state_type", service->GetStateType());
- SendMetric(prefix, "state", service->GetState());
+ SendMetric(prefix, "state", service->GetState());
+ } else {
+ prefix = "icinga." + hostName;
+
+ SendMetric(prefix, "state", host->GetState());
+ }
+
+ SendMetric(prefix, "current_attempt", checkable->GetCheckAttempt());
+ SendMetric(prefix, "max_check_attempts", checkable->GetMaxCheckAttempts());
+ SendMetric(prefix, "state_type", checkable->GetStateType());
+ SendMetric(prefix, "reachable", checkable->IsReachable());
SendMetric(prefix, "latency", Service::CalculateLatency(cr));
SendMetric(prefix, "execution_time", Service::CalculateExecutionTime(cr));
+ SendPerfdata(prefix, cr);
+}
+void GraphiteWriter::SendPerfdata(const String& prefix, const CheckResult::Ptr& cr)
+{
Value pdv = cr->GetPerformanceData();
if (!pdv.IsObjectType<Dictionary>())