]> granicus.if.org Git - icinga2/commitdiff
Add more metrics and details to built-in 'random' check 6078/head
authorMichael Friedrich <michael.friedrich@icinga.com>
Tue, 6 Feb 2018 14:56:07 +0000 (15:56 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 6 Feb 2018 15:01:07 +0000 (16:01 +0100)
This helps us with demo graphs in Graphite/InfluxDB as well
as other historical views.

fixes #5787

lib/methods/randomchecktask.cpp

index 787a5deaccba90c6a9e9a188f1538b6a9457f905..0f55745f9a8e81d5fb95a1d56b1aade953ff33b9 100644 (file)
@@ -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<ServiceState>(Utility::Random() % 4));
 
        service->ProcessCheckResult(cr);