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

Method SendPerfdata

lib/perfdata/graphitewriter.cpp:326–371  ·  view source on GitHub ↗

* Parse performance data from check result and call SendMetric() * * @param checkable Host/service object * @param prefix Metric prefix string * @param cr Check result including performance data */

Source from the content-addressed store, hash-verified

324 * @param cr Check result including performance data
325 */
326void GraphiteWriter::SendPerfdata(const Checkable::Ptr& checkable, const String& prefix, const CheckResult::Ptr& cr)
327{
328 AssertOnWorkQueue();
329
330 Array::Ptr perfdata = cr->GetPerformanceData();
331
332 if (!perfdata)
333 return;
334
335 CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();
336
337 ObjectLock olock(perfdata);
338 for (const Value& val : perfdata) {
339 PerfdataValue::Ptr pdv;
340
341 if (val.IsObjectType<PerfdataValue>())
342 pdv = val;
343 else {
344 try {
345 pdv = PerfdataValue::Parse(val);
346 } catch (const std::exception&) {
347 Log(LogWarning, "GraphiteWriter")
348 << "Ignoring invalid perfdata for checkable '"
349 << checkable->GetName() << "' and command '"
350 << checkCommand->GetName() << "' with value: " << val;
351 continue;
352 }
353 }
354
355 String escapedKey = EscapeMetricLabel(pdv->GetLabel());
356 double ts = cr->GetExecutionEnd();
357
358 SendMetric(checkable, prefix, escapedKey + ".value", pdv->GetValue(), ts);
359
360 if (GetEnableSendThresholds()) {
361 if (!pdv->GetCrit().IsEmpty())
362 SendMetric(checkable, prefix, escapedKey + ".crit", pdv->GetCrit(), ts);
363 if (!pdv->GetWarn().IsEmpty())
364 SendMetric(checkable, prefix, escapedKey + ".warn", pdv->GetWarn(), ts);
365 if (!pdv->GetMin().IsEmpty())
366 SendMetric(checkable, prefix, escapedKey + ".min", pdv->GetMin(), ts);
367 if (!pdv->GetMax().IsEmpty())
368 SendMetric(checkable, prefix, escapedKey + ".max", pdv->GetMax(), ts);
369 }
370 }
371}
372
373/**
374 * Computes metric data and sends to Graphite

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