mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +02:00
Improve logging of OpenTsdbWriter
This commit is contained in:
parent
acf62d487e
commit
424929e66a
@ -3,6 +3,7 @@
|
|||||||
#include "perfdata/opentsdbwriter.hpp"
|
#include "perfdata/opentsdbwriter.hpp"
|
||||||
#include "perfdata/opentsdbwriter-ti.cpp"
|
#include "perfdata/opentsdbwriter-ti.cpp"
|
||||||
#include "icinga/service.hpp"
|
#include "icinga/service.hpp"
|
||||||
|
#include "icinga/checkcommand.hpp"
|
||||||
#include "icinga/macroprocessor.hpp"
|
#include "icinga/macroprocessor.hpp"
|
||||||
#include "icinga/icingaapplication.hpp"
|
#include "icinga/icingaapplication.hpp"
|
||||||
#include "icinga/compatutility.hpp"
|
#include "icinga/compatutility.hpp"
|
||||||
@ -134,18 +135,18 @@ void OpenTsdbWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
|
|||||||
String escaped_serviceName = EscapeMetric(serviceName);
|
String escaped_serviceName = EscapeMetric(serviceName);
|
||||||
metric = "icinga.service." + escaped_serviceName;
|
metric = "icinga.service." + escaped_serviceName;
|
||||||
|
|
||||||
SendMetric(metric + ".state", tags, service->GetState(), ts);
|
SendMetric(checkable, metric + ".state", tags, service->GetState(), ts);
|
||||||
} else {
|
} else {
|
||||||
metric = "icinga.host";
|
metric = "icinga.host";
|
||||||
SendMetric(metric + ".state", tags, host->GetState(), ts);
|
SendMetric(checkable, metric + ".state", tags, host->GetState(), ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
SendMetric(metric + ".state_type", tags, checkable->GetStateType(), ts);
|
SendMetric(checkable, metric + ".state_type", tags, checkable->GetStateType(), ts);
|
||||||
SendMetric(metric + ".reachable", tags, checkable->IsReachable(), ts);
|
SendMetric(checkable, metric + ".reachable", tags, checkable->IsReachable(), ts);
|
||||||
SendMetric(metric + ".downtime_depth", tags, checkable->GetDowntimeDepth(), ts);
|
SendMetric(checkable, metric + ".downtime_depth", tags, checkable->GetDowntimeDepth(), ts);
|
||||||
SendMetric(metric + ".acknowledgement", tags, checkable->GetAcknowledgement(), ts);
|
SendMetric(checkable, metric + ".acknowledgement", tags, checkable->GetAcknowledgement(), ts);
|
||||||
|
|
||||||
SendPerfdata(metric, tags, cr, ts);
|
SendPerfdata(checkable, metric, tags, cr, ts);
|
||||||
|
|
||||||
metric = "icinga.check";
|
metric = "icinga.check";
|
||||||
|
|
||||||
@ -158,19 +159,22 @@ void OpenTsdbWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
|
|||||||
tags["type"] = "host";
|
tags["type"] = "host";
|
||||||
}
|
}
|
||||||
|
|
||||||
SendMetric(metric + ".current_attempt", tags, checkable->GetCheckAttempt(), ts);
|
SendMetric(checkable, metric + ".current_attempt", tags, checkable->GetCheckAttempt(), ts);
|
||||||
SendMetric(metric + ".max_check_attempts", tags, checkable->GetMaxCheckAttempts(), ts);
|
SendMetric(checkable, metric + ".max_check_attempts", tags, checkable->GetMaxCheckAttempts(), ts);
|
||||||
SendMetric(metric + ".latency", tags, cr->CalculateLatency(), ts);
|
SendMetric(checkable, metric + ".latency", tags, cr->CalculateLatency(), ts);
|
||||||
SendMetric(metric + ".execution_time", tags, cr->CalculateExecutionTime(), ts);
|
SendMetric(checkable, metric + ".execution_time", tags, cr->CalculateExecutionTime(), ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenTsdbWriter::SendPerfdata(const String& metric, const std::map<String, String>& tags, const CheckResult::Ptr& cr, double ts)
|
void OpenTsdbWriter::SendPerfdata(const Checkable::Ptr& checkable, const String& metric,
|
||||||
|
const std::map<String, String>& tags, const CheckResult::Ptr& cr, double ts)
|
||||||
{
|
{
|
||||||
Array::Ptr perfdata = cr->GetPerformanceData();
|
Array::Ptr perfdata = cr->GetPerformanceData();
|
||||||
|
|
||||||
if (!perfdata)
|
if (!perfdata)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();
|
||||||
|
|
||||||
ObjectLock olock(perfdata);
|
ObjectLock olock(perfdata);
|
||||||
for (const Value& val : perfdata) {
|
for (const Value& val : perfdata) {
|
||||||
PerfdataValue::Ptr pdv;
|
PerfdataValue::Ptr pdv;
|
||||||
@ -182,7 +186,9 @@ void OpenTsdbWriter::SendPerfdata(const String& metric, const std::map<String, S
|
|||||||
pdv = PerfdataValue::Parse(val);
|
pdv = PerfdataValue::Parse(val);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
Log(LogWarning, "OpenTsdbWriter")
|
Log(LogWarning, "OpenTsdbWriter")
|
||||||
<< "Ignoring invalid perfdata value: " << val;
|
<< "Ignoring invalid perfdata for checkable '"
|
||||||
|
<< checkable->GetName() << "' and command '"
|
||||||
|
<< checkCommand->GetName() << "' with value: " << val;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,22 +196,24 @@ void OpenTsdbWriter::SendPerfdata(const String& metric, const std::map<String, S
|
|||||||
String escaped_key = EscapeMetric(pdv->GetLabel());
|
String escaped_key = EscapeMetric(pdv->GetLabel());
|
||||||
boost::algorithm::replace_all(escaped_key, "::", ".");
|
boost::algorithm::replace_all(escaped_key, "::", ".");
|
||||||
|
|
||||||
SendMetric(metric + "." + escaped_key, tags, pdv->GetValue(), ts);
|
SendMetric(checkable, metric + "." + escaped_key, tags, pdv->GetValue(), ts);
|
||||||
|
|
||||||
if (pdv->GetCrit())
|
if (pdv->GetCrit())
|
||||||
SendMetric(metric + "." + escaped_key + "_crit", tags, pdv->GetCrit(), ts);
|
SendMetric(checkable, metric + "." + escaped_key + "_crit", tags, pdv->GetCrit(), ts);
|
||||||
if (pdv->GetWarn())
|
if (pdv->GetWarn())
|
||||||
SendMetric(metric + "." + escaped_key + "_warn", tags, pdv->GetWarn(), ts);
|
SendMetric(checkable, metric + "." + escaped_key + "_warn", tags, pdv->GetWarn(), ts);
|
||||||
if (pdv->GetMin())
|
if (pdv->GetMin())
|
||||||
SendMetric(metric + "." + escaped_key + "_min", tags, pdv->GetMin(), ts);
|
SendMetric(checkable, metric + "." + escaped_key + "_min", tags, pdv->GetMin(), ts);
|
||||||
if (pdv->GetMax())
|
if (pdv->GetMax())
|
||||||
SendMetric(metric + "." + escaped_key + "_max", tags, pdv->GetMax(), ts);
|
SendMetric(checkable, metric + "." + escaped_key + "_max", tags, pdv->GetMax(), ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenTsdbWriter::SendMetric(const String& metric, const std::map<String, String>& tags, double value, double ts)
|
void OpenTsdbWriter::SendMetric(const Checkable::Ptr& checkable, const String& metric,
|
||||||
|
const std::map<String, String>& tags, double value, double ts)
|
||||||
{
|
{
|
||||||
String tags_string = "";
|
String tags_string = "";
|
||||||
|
|
||||||
for (const Dictionary::Pair& tag : tags) {
|
for (const Dictionary::Pair& tag : tags) {
|
||||||
tags_string += " " + tag.first + "=" + Convert::ToString(tag.second);
|
tags_string += " " + tag.first + "=" + Convert::ToString(tag.second);
|
||||||
}
|
}
|
||||||
@ -219,7 +227,7 @@ void OpenTsdbWriter::SendMetric(const String& metric, const std::map<String, Str
|
|||||||
msgbuf << "put " << metric << " " << static_cast<long>(ts) << " " << Convert::ToString(value) << " " << tags_string;
|
msgbuf << "put " << metric << " " << static_cast<long>(ts) << " " << Convert::ToString(value) << " " << tags_string;
|
||||||
|
|
||||||
Log(LogDebug, "OpenTsdbWriter")
|
Log(LogDebug, "OpenTsdbWriter")
|
||||||
<< "Add to metric list:'" << msgbuf.str() << "'.";
|
<< "Checkable '" << checkable->GetName() << "' adds to metric list: '" << msgbuf.str() << "'.";
|
||||||
|
|
||||||
/* do not send \n to debug log */
|
/* do not send \n to debug log */
|
||||||
msgbuf << "\n";
|
msgbuf << "\n";
|
||||||
|
@ -37,8 +37,10 @@ private:
|
|||||||
Timer::Ptr m_ReconnectTimer;
|
Timer::Ptr m_ReconnectTimer;
|
||||||
|
|
||||||
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
void CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr);
|
||||||
void SendMetric(const String& metric, const std::map<String, String>& tags, double value, double ts);
|
void SendMetric(const Checkable::Ptr& checkable, const String& metric,
|
||||||
void SendPerfdata(const String& metric, const std::map<String, String>& tags, const CheckResult::Ptr& cr, double ts);
|
const std::map<String, String>& tags, double value, double ts);
|
||||||
|
void SendPerfdata(const Checkable::Ptr& checkable, const String& metric,
|
||||||
|
const std::map<String, String>& tags, const CheckResult::Ptr& cr, double ts);
|
||||||
static String EscapeTag(const String& str);
|
static String EscapeTag(const String& str);
|
||||||
static String EscapeMetric(const String& str);
|
static String EscapeMetric(const String& str);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user