diff options
author | Arne H Juul <arnej27959@users.noreply.github.com> | 2017-10-17 23:04:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-17 23:04:34 +0200 |
commit | 285906bf803d1105a4e0078ea5aed6d64316c396 (patch) | |
tree | df20601e512e77a7637b3c3fc0e7b19ca3b3a474 | |
parent | 8cab1e11d9e50598252ddc63c34048992b37f9f7 (diff) | |
parent | e48acb6ea0e79294199581770021af72323d7be5 (diff) |
Merge pull request #3781 from vespa-engine/arnej/add-uptime-metric-for-sentinel
Arnej/add uptime metric for sentinel
3 files changed, 38 insertions, 10 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/VespaMetricSet.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/VespaMetricSet.java index ccf7974d381..4995e238879 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/VespaMetricSet.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/monitoring/VespaMetricSet.java @@ -40,6 +40,7 @@ public class VespaMetricSet { Set<Metric> metrics = new LinkedHashSet<>(); metrics.add(new Metric("sentinel.restarts.count")); + metrics.add(new Metric("sentinel.uptime.last", "sentinel.uptime")); metrics.add(new Metric("sentinel.running.count")); metrics.add(new Metric("sentinel.running.last")); 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()); } diff --git a/configd/src/apps/sentinel/metrics.cpp b/configd/src/apps/sentinel/metrics.cpp index 078dfa275d9..42c61c06b50 100644 --- a/configd/src/apps/sentinel/metrics.cpp +++ b/configd/src/apps/sentinel/metrics.cpp @@ -8,7 +8,7 @@ namespace config { namespace sentinel { StartMetrics::StartMetrics() - : currentlyRunningServices(0), totalRestartsCounter(0), totalRestartsLastPeriod(0), + : currentlyRunningServices(0), totalRestartsCounter(0), totalRestartsLastPeriod(1), lastLoggedTime(0), totalRestartsLastSnapshot(0), snapshotStart(0), |