* 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 */
| 324 | * @param cr Check result including performance data |
| 325 | */ |
| 326 | void 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 |
nothing calls this directly
no test coverage detected