diff options
author | Harald Musum <musum@verizonmedia.com> | 2019-06-11 19:22:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-11 19:22:59 +0200 |
commit | f4c68c2c2428bd5ce2379cffbafa27063e6d8762 (patch) | |
tree | 2eac31fb1b92b694d015d060706e9050e2e0d8af | |
parent | 97f82e3fe82e21693cb788e6c406ccede1253fb4 (diff) | |
parent | 11a1dff80b3d199748e5fbb5c80cb54296b68fda (diff) |
Merge pull request #9748 from vespa-engine/hmusum/declare-and-update-jvm-heap-metrics-for-node-admin
Declare and update jvm heap metrics for node admin
3 files changed, 24 insertions, 2 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdmin.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdmin.java index ca9083e9d27..00ec985ba0c 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdmin.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdmin.java @@ -9,7 +9,7 @@ import java.util.Set; /** * NodeAdmin manages the life cycle of NodeAgents. - * @author dybis + * @author Haakon Dybdahl */ public interface NodeAdmin { @@ -19,6 +19,9 @@ public interface NodeAdmin { /** Gather node agent and its docker container metrics and forward them to the {@code MetricReceiverWrapper} */ void updateNodeAgentMetrics(); + /** Gather node admin metrics and forward them to the {@code MetricReceiverWrapper} */ + void updateNodeAdminMetrics(); + /** * Attempts to freeze/unfreeze all NodeAgents and itself. To freeze a NodeAgent means that * they will not pick up any changes from NodeRepository. @@ -29,7 +32,7 @@ public interface NodeAdmin { boolean setFrozen(boolean frozen); /** - * Returns whether the NodeAdmin itself is currently frozen, meaning it will not pick up any changes + * Returns whether NodeAdmin itself is currently frozen, meaning it will not pick up any changes * from NodeRepository. */ boolean isFrozen(); diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java index 5b5d13ca346..0d520241ac8 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java @@ -43,6 +43,9 @@ public class NodeAdminImpl implements NodeAdmin { private final Map<String, NodeAgentWithScheduler> nodeAgentWithSchedulerByHostname = new ConcurrentHashMap<>(); private final GaugeWrapper numberOfContainersInLoadImageState; + private final GaugeWrapper jvmHeapUsed; + private final GaugeWrapper jvmHeapFree; + private final GaugeWrapper jvmHeapTotal; private final CounterWrapper numberOfUnhandledExceptionsInNodeAgent; public NodeAdminImpl(NodeAgentFactory nodeAgentFactory, MetricReceiverWrapper metricReceiver, Clock clock) { @@ -70,6 +73,10 @@ public class NodeAdminImpl implements NodeAdmin { Dimensions dimensions = new Dimensions.Builder().add("role", "docker").build(); this.numberOfContainersInLoadImageState = metricReceiver.declareGauge(MetricReceiverWrapper.APPLICATION_DOCKER, dimensions, "nodes.image.loading"); this.numberOfUnhandledExceptionsInNodeAgent = metricReceiver.declareCounter(MetricReceiverWrapper.APPLICATION_DOCKER, dimensions, "nodes.unhandled_exceptions"); + + this.jvmHeapUsed = metricReceiver.declareGauge(MetricReceiverWrapper.APPLICATION_HOST, new Dimensions.Builder().build(), "mem.heap.used"); + this.jvmHeapFree = metricReceiver.declareGauge(MetricReceiverWrapper.APPLICATION_HOST, new Dimensions.Builder().build(), "mem.heap.free"); + this.jvmHeapTotal = metricReceiver.declareGauge(MetricReceiverWrapper.APPLICATION_HOST, new Dimensions.Builder().build(), "mem.heap.total"); } @Override @@ -113,6 +120,17 @@ public class NodeAdminImpl implements NodeAdmin { } @Override + public void updateNodeAdminMetrics() { + Runtime runtime = Runtime.getRuntime(); + long freeMemory = runtime.freeMemory(); + long totalMemory = runtime.totalMemory(); + long usedMemory = totalMemory - freeMemory; + jvmHeapFree.sample(freeMemory); + jvmHeapUsed.sample(usedMemory); + jvmHeapTotal.sample(totalMemory); + } + + @Override public boolean setFrozen(boolean wantFrozen) { if (wantFrozen != previousWantFrozen) { if (wantFrozen) { diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminStateUpdater.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminStateUpdater.java index 41c4544c533..2cd15a3ebe4 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminStateUpdater.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminStateUpdater.java @@ -81,6 +81,7 @@ public class NodeAdminStateUpdater { try { if (suspendedStates.contains(currentState)) return; nodeAdmin.updateNodeAgentMetrics(); + nodeAdmin.updateNodeAdminMetrics(); } catch (Throwable e) { log.log(Level.WARNING, "Metric fetcher scheduler failed", e); } |