diff options
Diffstat (limited to 'container-core/src/main/java/com')
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java | 6 | ||||
-rw-r--r-- | container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java | 23 |
2 files changed, 20 insertions, 9 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java index ce9779b83d9..23c247fa438 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateHandler.java @@ -190,7 +190,7 @@ public class StateHandler extends AbstractRequestHandler { private JSONObjectWithLegibleException buildJsonForConsumer(String consumer) throws JSONException { JSONObjectWithLegibleException ret = new JSONObjectWithLegibleException(); ret.put("time", timer.currentTimeMillis()); - ret.put("status", new JSONObjectWithLegibleException().put("code", "up")); + ret.put("status", new JSONObjectWithLegibleException().put("code", getStatus().name())); ret.put(METRICS_PATH, buildJsonForSnapshot(consumer, getSnapshot())); return ret; } @@ -203,6 +203,10 @@ public class StateHandler extends AbstractRequestHandler { } } + private StateMonitor.Status getStatus() { + return monitor.status(); + } + private JSONObjectWithLegibleException buildJsonForSnapshot(String consumer, MetricSnapshot metricSnapshot) throws JSONException { if (metricSnapshot == null) { return new JSONObjectWithLegibleException(); diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java index 140257cbcef..6234a96d7a0 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/StateMonitor.java @@ -6,6 +6,7 @@ import com.yahoo.component.AbstractComponent; import com.yahoo.container.jdisc.config.HealthMonitorConfig; import com.yahoo.jdisc.Timer; import com.yahoo.jdisc.application.MetricConsumer; +import com.yahoo.log.LogLevel; import java.util.Map; import java.util.TreeSet; @@ -14,7 +15,7 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; /** - * A statemonitor keeps track of the current metrics state of a container. + * A state monitor keeps track of the current health and metrics state of a container. * It is used by jDisc to hand out metric update API endpoints to workers through {@link #newMetricConsumer}, * and to inspect the current accumulated state of metrics through {@link #snapshot}. * @@ -23,12 +24,16 @@ import java.util.logging.Logger; public class StateMonitor extends AbstractComponent { private final static Logger log = Logger.getLogger(StateMonitor.class.getName()); + + public enum Status {up, down, initializing}; + private final CopyOnWriteArrayList<StateMetricConsumer> consumers = new CopyOnWriteArrayList<>(); private final Thread thread; private final Timer timer; private final long snapshotIntervalMs; private long lastSnapshotTimeMs; private volatile MetricSnapshot snapshot; + private volatile Status status; private final TreeSet<String> valueNames = new TreeSet<>(); @Inject @@ -36,13 +41,8 @@ public class StateMonitor extends AbstractComponent { this.timer = timer; this.snapshotIntervalMs = (long)(config.snapshot_interval() * TimeUnit.SECONDS.toMillis(1)); this.lastSnapshotTimeMs = timer.currentTimeMillis(); - thread = new Thread(new Runnable() { - - @Override - public void run() { - StateMonitor.this.run(); - } - }, "StateMonitor"); + this.status = Status.valueOf(config.initialStatus()); + thread = new Thread(StateMonitor.this::run, "StateMonitor"); thread.setDaemon(true); thread.start(); } @@ -54,6 +54,13 @@ public class StateMonitor extends AbstractComponent { return consumer; } + public void status(Status status) { + log.log(LogLevel.INFO, "Changing health status code from '" + this.status + "' to '" + status.name() + "'"); + this.status = status; + } + + public Status status() { return status; } + /** Returns the last snapshot taken of the metrics in this system */ public MetricSnapshot snapshot() { return snapshot; |