summaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2017-10-16 13:52:52 +0000
committerArne Juul <arnej@yahoo-inc.com>2017-10-16 13:54:05 +0000
commitd13b5f42562d5978ebb0f85be43aa88eb69307c2 (patch)
tree47eea4449c1c04d723359bd136deb136b3385693 /configd
parent6d7617977d008a2a2e41f4e97766d3f4c7b1c12b (diff)
add "uptime" metric
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/config-handler.cpp45
1 files changed, 36 insertions, 9 deletions
diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp
index 1075bc4d7ce..0527982c99f 100644
--- a/configd/src/apps/sentinel/config-handler.cpp
+++ b/configd/src/apps/sentinel/config-handler.cpp
@@ -395,21 +395,48 @@ ConfigHandler::handleCommand(CommandConnection *c)
}
}
+namespace {
+
+void
+fillRestarts(vespalib::SimpleMetricSnapshot &snapshot, unsigned long restarts)
+{
+ snapshot.addCount("sentinel.restarts",
+ "how many times sentinel restarted a service",
+ restarts);
+}
+
+void
+fillRunning(vespalib::SimpleMetricSnapshot &snapshot, unsigned long running)
+{
+ snapshot.addGauge("sentinel.running",
+ "how many services the sentinel has running currently",
+ running);
+}
+
+void
+fillUptime(vespalib::SimpleMetricSnapshot &snapshot, long uptime)
+{
+ snapshot.addGauge("sentinel.uptime",
+ "how many seconds has the sentinel been running",
+ uptime);
+}
+
+} // namespace <unnamed>
+
void
ConfigHandler::updateMetrics()
{
+ time_t now = time(nullptr);
vespalib::SimpleMetricSnapshot snapshot(_startMetrics.snapshotStart, _startMetrics.snapshotEnd);
- snapshot.addCount("sentinel.restarts", "how many times sentinel restarted a service",
- _startMetrics.totalRestartsLastSnapshot);
- snapshot.addGauge("sentinel.running", "how many services the sentinel has running currently",
- _startMetrics.currentlyRunningServices);
+ fillRestarts(snapshot, _startMetrics.totalRestartsLastSnapshot);
+ fillRunning(snapshot, _startMetrics.currentlyRunningServices);
+ fillUptime(snapshot, now - _startMetrics.startedTime);
_stateApi.myMetrics.setMetrics(snapshot.asString());
- vespalib::SimpleMetricSnapshot totals(_startMetrics.startedTime, time(nullptr));
- totals.addCount("sentinel.restarts", "how many times sentinel restarted a service",
- _startMetrics.totalRestartsCounter);
- totals.addGauge("sentinel.running", "how many services the sentinel has running currently",
- _startMetrics.currentlyRunningServices);
+ vespalib::SimpleMetricSnapshot totals(_startMetrics.startedTime, now);
+ fillRestarts(totals, _startMetrics.totalRestartsCounter);
+ fillRunning(totals, _startMetrics.currentlyRunningServices);
+ fillUptime(totals, now - _startMetrics.startedTime);
_stateApi.myMetrics.setTotalMetrics(totals.asString());
}