diff options
Diffstat (limited to 'container-core/src/main')
4 files changed, 121 insertions, 0 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/CoredumpGatherer.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/CoredumpGatherer.java new file mode 100644 index 00000000000..915cced842b --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/CoredumpGatherer.java @@ -0,0 +1,48 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.jdisc.state; + +import com.yahoo.vespa.defaults.Defaults; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; +import java.time.Instant; +import java.util.Set; + +/** + * @author olaa + */ +public class CoredumpGatherer { + + private static final Path COREDUMP_PATH = Path.of(Defaults.getDefaults().underVespaHome("var/crash/processing")); + + protected static JSONObject gatherCoredumpMetrics() { + int coredumps = getNumberOfCoredumps(); + JSONObject packet = new JSONObject(); + + try { + packet.put("status_code", coredumps == 0 ? 0 : 1); + packet.put("status_msg", coredumps == 0 ? "OK" : String.format("Found %d coredumps", coredumps)); + packet.put("timestamp", Instant.now().getEpochSecond()); + packet.put("application", "system-coredumps-processing"); + + } catch (JSONException e) {} + return packet; + } + + private static int getNumberOfCoredumps() { + try { + return (int) Files.walk(COREDUMP_PATH) + .filter(Files::isRegularFile) + .count(); + } catch (NoSuchFileException e) { + return 0; + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } +} diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/HostLifeGatherer.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/HostLifeGatherer.java new file mode 100644 index 00000000000..91d1c468d8a --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/HostLifeGatherer.java @@ -0,0 +1,50 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.jdisc.state; + +import com.yahoo.vespa.defaults.Defaults; +import org.json.JSONException; +import org.json.JSONObject; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import java.time.Instant; + +/** + * @author olaa + */ +public class HostLifeGatherer { + + private static final Path UPTIME_PATH = Path.of(Defaults.getDefaults().underVespaHome("/proc")); + + protected static JSONObject getHostLifePacket() { + long upTime; + int statusCode = 0; + String statusMessage = "OK"; + + try { + upTime = Files.getLastModifiedTime(UPTIME_PATH).toInstant().getEpochSecond(); + } catch (IOException e) { + upTime = 0; + statusCode = 1; + statusMessage = "Unable to read proc folder"; + } + + + JSONObject jsonObject = new JSONObject(); + try { + jsonObject.put("status_code", statusCode); + jsonObject.put("status_msg", statusMessage); + jsonObject.put("timestamp", Instant.now().getEpochSecond()); + jsonObject.put("application", "host_life"); + JSONObject metrics = new JSONObject(); + metrics.put("uptime", upTime); + metrics.put("alive", 1); + jsonObject.put("metrics", metrics); + + } catch (JSONException e) {} + + return jsonObject; + } +} diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricGatherer.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricGatherer.java new file mode 100644 index 00000000000..97fba188593 --- /dev/null +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricGatherer.java @@ -0,0 +1,22 @@ +// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.jdisc.state; + +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author olaa + * Gathers metrics regarding currently processing coredumps and host life + */ +public class MetricGatherer { + + static List<JSONObject> getAdditionalMetrics() { + List<JSONObject> packetList = new ArrayList<>(); + packetList.add(CoredumpGatherer.gatherCoredumpMetrics()); + if (System.getProperty("os.name").contains("nux")) + packetList.add(HostLifeGatherer.getHostLifePacket()); + return packetList; + } +} diff --git a/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricsPacketsHandler.java b/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricsPacketsHandler.java index d7760ac9c91..d1036db5c6f 100644 --- a/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricsPacketsHandler.java +++ b/container-core/src/main/java/com/yahoo/container/jdisc/state/MetricsPacketsHandler.java @@ -107,6 +107,7 @@ public class MetricsPacketsHandler extends AbstractRequestHandler { jsonArray.put(getStatusPacket()); getPacketsForSnapshot(getSnapshot(), applicationName, timer.currentTimeMillis()) .forEach(jsonArray::put); + MetricGatherer.getAdditionalMetrics().forEach(jsonArray::put); root.put("metrics", jsonArray); return jsonToString(root) .getBytes(StandardCharsets.UTF_8); |