aboutsummaryrefslogtreecommitdiffstats
path: root/configd/src/apps/sentinel/metrics.cpp
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /configd/src/apps/sentinel/metrics.cpp
Publish
Diffstat (limited to 'configd/src/apps/sentinel/metrics.cpp')
-rw-r--r--configd/src/apps/sentinel/metrics.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/configd/src/apps/sentinel/metrics.cpp b/configd/src/apps/sentinel/metrics.cpp
new file mode 100644
index 00000000000..14527221643
--- /dev/null
+++ b/configd/src/apps/sentinel/metrics.cpp
@@ -0,0 +1,51 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP(".metrics");
+
+#include "metrics.h"
+
+namespace config {
+namespace sentinel {
+
+StartMetrics::StartMetrics()
+ : currentlyRunningServices(0), totalRestartsCounter(0), totalRestartsLastPeriod(0),
+ lastLoggedTime(0),
+ totalRestartsLastSnapshot(0),
+ snapshotStart(0),
+ snapshotEnd(0)
+{
+ snapshotEnd = time(NULL);
+ lastLoggedTime = snapshotEnd - 55;
+}
+
+void
+StartMetrics::output()
+{
+ EV_VALUE("currently_running_services", currentlyRunningServices);
+ EV_VALUE("total_restarts_last_period", totalRestartsLastPeriod);
+ EV_COUNT("total_restarts_counter", totalRestartsCounter);
+}
+
+void
+StartMetrics::reset(unsigned long curTime)
+{
+ totalRestartsLastSnapshot = totalRestartsLastPeriod;
+ snapshotStart = snapshotEnd;
+ snapshotEnd = curTime;
+ totalRestartsLastPeriod = 0;
+ lastLoggedTime = curTime;
+}
+
+void
+StartMetrics::maybeLog()
+{
+ uint32_t curTime = time(NULL);
+ if (curTime > lastLoggedTime + 59) {
+ output();
+ reset(curTime);
+ }
+}
+
+} // end namespace config::sentinel
+} // end namespace config