summaryrefslogtreecommitdiffstats
path: root/configd
diff options
context:
space:
mode:
authorArne Juul <arnej@yahoo-inc.com>2017-12-04 14:46:13 +0000
committerArne Juul <arnej@yahoo-inc.com>2017-12-07 11:02:00 +0000
commit6a2f714b2a740a05a709e290079fd18014244462 (patch)
tree8df93c64c231305e56f5ca1ef0e750ffcc095f56 /configd
parent3509f17b3ba18a96dc1f52e7b0e23d679e020e8c (diff)
use vespalib metrics library
Diffstat (limited to 'configd')
-rw-r--r--configd/src/apps/sentinel/config-handler.cpp55
-rw-r--r--configd/src/apps/sentinel/metrics.cpp30
-rw-r--r--configd/src/apps/sentinel/metrics.h18
-rw-r--r--configd/src/apps/sentinel/service.cpp3
4 files changed, 39 insertions, 67 deletions
diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp
index e5222b0350b..03ea1da9617 100644
--- a/configd/src/apps/sentinel/config-handler.cpp
+++ b/configd/src/apps/sentinel/config-handler.cpp
@@ -395,61 +395,12 @@ 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
-fillTotalRestarts(vespalib::SimpleMetricSnapshot &snapshot,
- unsigned long totalRestarts)
-{
- snapshot.addGauge("sentinel.totalRestarts",
- "how many times sentinel restarted a service since "
- "sentinel start",
- totalRestarts);
-}
-
-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);
- fillRestarts(snapshot, _startMetrics.totalRestartsLastSnapshot);
- fillTotalRestarts(snapshot, _startMetrics.totalRestartsCounter);
- fillRunning(snapshot, _startMetrics.currentlyRunningServices);
- fillUptime(snapshot, now - _startMetrics.startedTime);
- _stateApi.myMetrics.setMetrics(snapshot.asString());
-
- vespalib::SimpleMetricSnapshot totals(_startMetrics.startedTime, now);
- fillRestarts(totals, _startMetrics.totalRestartsCounter);
- fillRunning(totals, _startMetrics.currentlyRunningServices);
- fillUptime(totals, now - _startMetrics.startedTime);
- _stateApi.myMetrics.setTotalMetrics(totals.asString());
-
+ _startMetrics.maybeLog();
+ _stateApi.myMetrics.setMetrics(_startMetrics.producer.getMetrics(""));
+ _stateApi.myMetrics.setTotalMetrics(_startMetrics.producer.getTotalMetrics(""));
}
void
diff --git a/configd/src/apps/sentinel/metrics.cpp b/configd/src/apps/sentinel/metrics.cpp
index 42c61c06b50..bc9d87d0e73 100644
--- a/configd/src/apps/sentinel/metrics.cpp
+++ b/configd/src/apps/sentinel/metrics.cpp
@@ -4,18 +4,28 @@
#include <vespa/log/log.h>
LOG_SETUP(".metrics");
+#include <vespa/vespalib/metrics/simple_metrics.h>
+
namespace config {
namespace sentinel {
+using vespalib::metrics::SimpleMetricsManager;
+using vespalib::metrics::SimpleManagerConfig;
+
StartMetrics::StartMetrics()
- : currentlyRunningServices(0), totalRestartsCounter(0), totalRestartsLastPeriod(1),
- lastLoggedTime(0),
- totalRestartsLastSnapshot(0),
- snapshotStart(0),
- snapshotEnd(0)
+ : metrics(SimpleMetricsManager::create(SimpleManagerConfig())),
+ producer(metrics),
+ currentlyRunningServices(0),
+ totalRestartsCounter(0),
+ totalRestartsLastPeriod(1),
+ startedTime(time(nullptr)),
+ lastLoggedTime(startedTime - 55),
+ sentinel_restarts(metrics->counter("sentinel.restarts")),
+ sentinel_totalRestarts(metrics->gauge("sentinel.totalRestarts")),
+ sentinel_running(metrics->gauge("sentinel.running")),
+ sentinel_uptime(metrics->gauge("sentinel.uptime"))
{
- snapshotEnd = time(nullptr);
- lastLoggedTime = snapshotEnd - 55;
+ sentinel_restarts.add();
}
void
@@ -29,9 +39,6 @@ StartMetrics::output()
void
StartMetrics::reset(unsigned long curTime)
{
- totalRestartsLastSnapshot = totalRestartsLastPeriod;
- snapshotStart = snapshotEnd;
- snapshotEnd = curTime;
totalRestartsLastPeriod = 0;
lastLoggedTime = curTime;
}
@@ -40,6 +47,9 @@ void
StartMetrics::maybeLog()
{
uint32_t curTime = time(nullptr);
+ sentinel_totalRestarts.sample(totalRestartsCounter);
+ sentinel_running.sample(currentlyRunningServices);
+ sentinel_uptime.sample(curTime - startedTime);
if (curTime > lastLoggedTime + 59) {
output();
reset(curTime);
diff --git a/configd/src/apps/sentinel/metrics.h b/configd/src/apps/sentinel/metrics.h
index dd24bb2280d..2378a055663 100644
--- a/configd/src/apps/sentinel/metrics.h
+++ b/configd/src/apps/sentinel/metrics.h
@@ -2,20 +2,29 @@
#pragma once
#include <sys/time.h>
+#include <vespa/vespalib/metrics/simple_metrics.h>
namespace config::sentinel {
+using vespalib::metrics::Counter;
+using vespalib::metrics::Gauge;
+using vespalib::metrics::MetricsManager;
+
struct StartMetrics {
+ std::shared_ptr<MetricsManager> metrics;
+ vespalib::metrics::Producer producer;
unsigned long currentlyRunningServices;
unsigned long totalRestartsCounter;
unsigned long totalRestartsLastPeriod;
- long lastLoggedTime;
- unsigned long totalRestartsLastSnapshot;
- long snapshotStart;
- long snapshotEnd;
long startedTime;
+ long lastLoggedTime;
+ Counter sentinel_restarts;
+ Gauge sentinel_totalRestarts;
+ Gauge sentinel_running;
+ Gauge sentinel_uptime;
StartMetrics();
+ ~StartMetrics() {}
void output();
void reset(unsigned long curTime);
@@ -23,4 +32,3 @@ struct StartMetrics {
};
}
-
diff --git a/configd/src/apps/sentinel/service.cpp b/configd/src/apps/sentinel/service.cpp
index 2f13a05eb4f..3c762a957ec 100644
--- a/configd/src/apps/sentinel/service.cpp
+++ b/configd/src/apps/sentinel/service.cpp
@@ -239,6 +239,7 @@ Service::start()
// ensureChildRuns(pipes[0]); // This will wait until the execl goes through
setState(RUNNING);
_metrics.currentlyRunningServices++;
+ _metrics.sentinel_running.sample(_metrics.currentlyRunningServices);
close(pipes[0]); // close reading end
using ns_log::LLParser;
@@ -314,6 +315,7 @@ Service::youExited(int status)
setState(FAILED);
}
_metrics.currentlyRunningServices--;
+ _metrics.sentinel_running.sample(_metrics.currentlyRunningServices);
if (_state == TERMINATING) {
setState(TERMINATED);
@@ -326,6 +328,7 @@ Service::youExited(int status)
setState(READY);
_metrics.totalRestartsCounter++;
_metrics.totalRestartsLastPeriod++;
+ _metrics.sentinel_restarts.add();
start();
}
}