Application::GetTP().Post(callback);
}
+String Utility::NaturalJoin(const std::vector<String>& tokens)
+{
+ String result;
+
+ for (int i = 0; i < tokens.size(); i++) {
+ result += tokens[i];
+
+ if (tokens.size() > i + 1) {
+ if (i < tokens.size() - 2)
+ result += ", ";
+ else if (i == tokens.size() - 2)
+ result += " and ";
+ }
+ }
+
+ return result;
+}
+
+String Utility::FormatDuration(int duration)
+{
+ std::vector<String> tokens;
+ String result;
+
+ if (duration >= 86400) {
+ int days = duration / 86400;
+ tokens.push_back(Convert::ToString(days) + (days != 1 ? " days" : " day"));
+ duration %= 86400;
+ }
+
+ if (duration >= 3600) {
+ int hours = duration / 3600;
+ tokens.push_back(Convert::ToString(hours) + (hours != 1 ? " hours" : " hour"));
+ duration %= 3600;
+ }
+
+ if (duration >= 60) {
+ int minutes = duration / 60;
+ tokens.push_back(Convert::ToString(minutes) + (minutes != 1 ? " minutes" : " minute"));
+ duration %= 60;
+ }
+
+ if (duration >= 1) {
+ int seconds = duration;
+ tokens.push_back(Convert::ToString(seconds) + (seconds != 1 ? " seconds" : " second"));
+ }
+
+ return NaturalJoin(tokens);
+}
+
String Utility::FormatDateTime(const char *format, double ts)
{
char timestamp[128];
#include <typeinfo>
#include <boost/function.hpp>
#include <boost/thread/tss.hpp>
+#include <vector>
namespace icinga
{
static void QueueAsyncCallback(const boost::function<void (void)>& callback);
+ static String NaturalJoin(const std::vector<String>& tokens);
+
+ static String FormatDuration(int duration);
static String FormatDateTime(const char *format, double ts);
static
perfdata->Set("num_services_in_downtime", ss.services_in_downtime);
perfdata->Set("num_services_acknowledged", ss.services_acknowledged);
+ double uptime = Utility::GetTime() - Application::GetStartTime();
+ perfdata->Set("uptime", uptime);
+
HostStatistics hs = CIB::CalculateHostStats();
perfdata->Set("num_hosts_up", hs.hosts_up);
perfdata->Set("num_hosts_in_downtime", hs.hosts_in_downtime);
perfdata->Set("num_hosts_acknowledged", hs.hosts_acknowledged);
- cr->SetOutput("Icinga 2 is running. Version: " + Application::GetVersion());
+ cr->SetOutput("Icinga 2 has been running for " + Utility::FormatDuration(uptime) +
+ ". Version: " + Application::GetVersion());
cr->SetPerformanceData(perfdata);
cr->SetState(ServiceOK);