From ae8a0b6a6437e4f997db05f3cc134b927f1925ea Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 31 Jan 2020 16:49:49 +0100 Subject: [PATCH] Introduce Application::GetUptime() --- lib/base/application.cpp | 5 +++++ lib/base/application.hpp | 2 ++ lib/icinga/cib.cpp | 2 +- lib/methods/icingachecktask.cpp | 2 +- lib/methods/randomchecktask.cpp | 2 +- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 4707f0d23..9468bb9f1 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -1162,6 +1162,11 @@ void Application::SetMainTime(double ts) m_MainTime = ts; } +double Application::GetUptime() +{ + return Utility::GetTime() - m_StartTime; +} + bool Application::GetScriptDebuggerEnabled() { return m_ScriptDebuggerEnabled; diff --git a/lib/base/application.hpp b/lib/base/application.hpp index a6b78ff09..e2455e3e6 100644 --- a/lib/base/application.hpp +++ b/lib/base/application.hpp @@ -98,6 +98,8 @@ public: static double GetMainTime(); static void SetMainTime(double ts); + static double GetUptime(); + static bool GetScriptDebuggerEnabled(); static void SetScriptDebuggerEnabled(bool enabled); diff --git a/lib/icinga/cib.cpp b/lib/icinga/cib.cpp index 0cb6ef0d5..898b0e75f 100644 --- a/lib/icinga/cib.cpp +++ b/lib/icinga/cib.cpp @@ -329,7 +329,7 @@ void CIB::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata) { status->Set("num_services_handled", ss.services_handled); status->Set("num_services_problem", ss.services_problem); - double uptime = Utility::GetTime() - Application::GetStartTime(); + double uptime = Application::GetUptime(); status->Set("uptime", uptime); HostStatistics hs = CalculateHostStats(); diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index 3f46fba81..2c2c5c592 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -102,7 +102,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes perfdata->Add(new PerfdataValue("num_services_handled", ss.services_handled)); perfdata->Add(new PerfdataValue("num_services_problem", ss.services_problem)); - double uptime = Utility::GetTime() - Application::GetStartTime(); + double uptime = Application::GetUptime(); perfdata->Add(new PerfdataValue("uptime", uptime)); HostStatistics hs = CIB::CalculateHostStats(); diff --git a/lib/methods/randomchecktask.cpp b/lib/methods/randomchecktask.cpp index ddda9879b..35e10d2a6 100644 --- a/lib/methods/randomchecktask.cpp +++ b/lib/methods/randomchecktask.cpp @@ -25,7 +25,7 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes return; double now = Utility::GetTime(); - double uptime = now - Application::GetStartTime(); + double uptime = Application::GetUptime(); String output = "Hello from " + IcingaApplication::GetInstance()->GetNodeName() + ". Icinga 2 has been running for " + Utility::FormatDuration(uptime)