From bc9b9b9a3b96143586504fb742a7ecde3322fab2 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Fri, 8 Oct 2021 09:47:35 +0200 Subject: [PATCH] Add system load average metrics. --- build.gradle | 1 - gradle.properties | 2 +- .../plugins/os_base/BaseLoadExtension.java | 76 +++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseLoadExtension.java diff --git a/build.gradle b/build.gradle index 3175af8..d07ef80 100644 --- a/build.gradle +++ b/build.gradle @@ -43,5 +43,4 @@ tasks.create("packages") { dependsOn ":plugins:buildDeb" dependsOn ":plugins:buildRpm" - } diff --git a/gradle.properties b/gradle.properties index 4c9311f..93046f9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=0.1.3 +version=0.1.4 pf4jVersion=3.6.0 slf4jVersion=1.7.32 camelVersion=3.11.2 diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseLoadExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseLoadExtension.java new file mode 100644 index 0000000..545ad4b --- /dev/null +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseLoadExtension.java @@ -0,0 +1,76 @@ +package sysmon.plugins.os_base; + +import org.pf4j.Extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import oshi.hardware.HardwareAbstractionLayer; +import sysmon.shared.Measurement; +import sysmon.shared.MetricExtension; +import sysmon.shared.MetricResult; + +import java.util.HashMap; +import java.util.Map; + +@Extension +public class BaseLoadExtension implements MetricExtension { + + private static final Logger log = LoggerFactory.getLogger(BaseLoadExtension.class); + + // Extension details + private final String name = "base_load"; + private final String provides = "load"; + private final String description = "Base Load Average Metrics"; + + // Configuration / Options + private boolean enabled = true; + + private HardwareAbstractionLayer hardwareAbstractionLayer; + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public boolean isSupported() { + hardwareAbstractionLayer = BasePlugin.getHardwareAbstractionLayer(); + return hardwareAbstractionLayer != null; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getProvides() { + return provides; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public void setConfiguration(Map map) { + if (map.containsKey("enabled")) { + enabled = (boolean) map.get("enabled"); + } + } + + @Override + public MetricResult getMetrics() { + + double[] loadAvg = hardwareAbstractionLayer.getProcessor().getSystemLoadAverage(3); + HashMap fieldsMap = new HashMap() {{ + put("1min", loadAvg[0]); + put("5min", loadAvg[1]); + put("15min", loadAvg[2]); + }}; + + log.debug(fieldsMap.toString()); + return new MetricResult(name, new Measurement(new HashMap(), fieldsMap)); + } + +}