From bdeba19a00fc4fd2e0c19908e622bc118a5e5e64 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 6 Feb 2018 15:56:07 +0100 Subject: [PATCH] Add more metrics and details to built-in 'random' check This helps us with demo graphs in Graphite/InfluxDB as well as other historical views. fixes #5787 --- lib/methods/randomchecktask.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/methods/randomchecktask.cpp b/lib/methods/randomchecktask.cpp index 787a5deac..0f55745f9 100644 --- a/lib/methods/randomchecktask.cpp +++ b/lib/methods/randomchecktask.cpp @@ -24,7 +24,6 @@ #include "icinga/icingaapplication.hpp" #include "base/utility.hpp" #include "base/perfdatavalue.hpp" -#include "base/convert.hpp" #include "base/function.hpp" #include "base/logger.hpp" @@ -38,13 +37,25 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul if (resolvedMacros && !useResolvedMacros) return; - String output = "Hello from "; - output += IcingaApplication::GetInstance()->GetNodeName(); + double now = Utility::GetTime(); + double uptime = now - Application::GetStartTime(); + + String output = "Hello from " + IcingaApplication::GetInstance()->GetNodeName() + + ". Icinga 2 has been running for " + Utility::FormatDuration(uptime) + + ". Version: " + Application::GetAppVersion(); cr->SetOutput(output); + + double random = Utility::Random() % 1000; + cr->SetPerformanceData(new Array({ - new PerfdataValue("time", Convert::ToDouble(Utility::GetTime())) + new PerfdataValue("time", now), + new PerfdataValue("value", random), + new PerfdataValue("value_1m", random * 0.9), + new PerfdataValue("value_5m", random * 0.8), + new PerfdataValue("uptime", uptime), })); + cr->SetState(static_cast(Utility::Random() % 4)); service->ProcessCheckResult(cr); -- 2.40.0