MCPcopy Create free account
hub / github.com/Icinga/icinga2 / SendPerfdata

Method SendPerfdata

lib/perfdata/opentsdbwriter.cpp:310–364  ·  view source on GitHub ↗

* Parse and send performance data metrics to OpenTSDB * * @param checkable Host/service object * @param metric Full metric name * @param tags Tag key pairs * @param cr Check result containing performance data * @param ts Timestamp when the check result was received */

Source from the content-addressed store, hash-verified

308 * @param ts Timestamp when the check result was received
309 */
310void OpenTsdbWriter::SendPerfdata(const Checkable::Ptr& checkable, const String& metric,
311 const std::map<String, String>& tags, const CheckResult::Ptr& cr, double ts)
312{
313 Array::Ptr perfdata = cr->GetPerformanceData();
314
315 if (!perfdata)
316 return;
317
318 CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();
319
320 ObjectLock olock(perfdata);
321 for (const Value& val : perfdata) {
322 PerfdataValue::Ptr pdv;
323
324 if (val.IsObjectType<PerfdataValue>())
325 pdv = val;
326 else {
327 try {
328 pdv = PerfdataValue::Parse(val);
329 } catch (const std::exception&) {
330 Log(LogWarning, "OpenTsdbWriter")
331 << "Ignoring invalid perfdata for checkable '"
332 << checkable->GetName() << "' and command '"
333 << checkCommand->GetName() << "' with value: " << val;
334 continue;
335 }
336 }
337
338 String metric_name;
339 std::map<String, String> tags_new = tags;
340
341 // Do not break original functionality where perfdata labels form
342 // part of the metric name
343 if (!GetEnableGenericMetrics()) {
344 String escaped_key = EscapeMetric(pdv->GetLabel());
345 boost::algorithm::replace_all(escaped_key, "::", ".");
346 metric_name = metric + "." + escaped_key;
347 } else {
348 String escaped_key = EscapeTag(pdv->GetLabel());
349 metric_name = metric;
350 tags_new["label"] = escaped_key;
351 }
352
353 SendMetric(checkable, metric_name, tags_new, pdv->GetValue(), ts);
354
355 if (!pdv->GetCrit().IsEmpty())
356 SendMetric(checkable, metric_name + "_crit", tags_new, pdv->GetCrit(), ts);
357 if (!pdv->GetWarn().IsEmpty())
358 SendMetric(checkable, metric_name + "_warn", tags_new, pdv->GetWarn(), ts);
359 if (!pdv->GetMin().IsEmpty())
360 SendMetric(checkable, metric_name + "_min", tags_new, pdv->GetMin(), ts);
361 if (!pdv->GetMax().IsEmpty())
362 SendMetric(checkable, metric_name + "_max", tags_new, pdv->GetMax(), ts);
363 }
364}
365
366/**
367 * Send given metric to OpenTSDB

Callers

nothing calls this directly

Calls 5

LogClass · 0.85
GetCheckCommandMethod · 0.80
GetNameMethod · 0.45
GetValueMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected