From 0973c974accd563a85c425377b2ae67cee6d4cee Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Fri, 28 May 2021 15:52:33 +0200 Subject: [PATCH] Work on base/common metrics. --- build.gradle | 1 + client/build.gradle | 4 + plugins/build.gradle | 5 + plugins/os-aix/build.gradle | 3 - .../plugins/os_aix/AixDiskExtension.java | 91 ----------- .../sysmon/plugins/os_aix/AixDiskStat.java | 53 ------- .../plugins/os_aix/AixMemoryExtension.java | 68 -------- .../sysmon/plugins/os_aix/AixMemoryStat.java | 60 ------- .../plugins/os_aix/AixProcessorExtension.java | 4 +- .../os-aix/src/test/groovy/AixDiskTest.groovy | 26 ---- .../src/test/groovy/AixMemoryTest.groovy | 29 ---- plugins/os-aix/src/test/resources/iostat.txt | 3 - .../os-aix/src/test/resources/mpstat-v.txt | 15 -- plugins/os-aix/src/test/resources/svmon.txt | 6 - .../os-aix/src/test/resources/vmstat-Iwt.txt | 7 - plugins/os-base/README.md | 36 +++++ plugins/os-base/build.gradle | 2 + plugins/os-base/gradle.properties | 7 + .../plugins/os_base/BaseDiskExtension.java | 87 +++++++++++ .../plugins/os_base/BaseMemoryExtension.java | 72 +++++++++ .../plugins/os_base/BaseNetworkExtension.java | 89 +++++++++++ .../sysmon/plugins/os_base/BasePlugin.java | 17 ++ .../os_base/BaseProcessorExtension.java | 111 +++++++++++++ .../src/test/resources/free.txt | 0 .../src/test/resources/meminfo.txt | 0 .../src/test/resources/proc_diskstats1.txt | 0 .../src/test/resources/proc_diskstats2.txt | 0 .../src/test/resources/proc_net_dev1.txt | 0 .../src/test/resources/proc_net_dev2.txt | 0 .../src/test/resources/proc_net_sockstat.txt | 6 + .../src/test/resources/proc_stats1.txt | 0 .../src/test/resources/proc_stats2.txt | 0 plugins/os-linux/README.md | 12 +- plugins/os-linux/gradle.properties | 2 +- .../plugins/os_linux/LinuxDiskExtension.java | 88 ----------- .../plugins/os_linux/LinuxDiskProcLine.java | 146 ------------------ .../plugins/os_linux/LinuxDiskStat.java | 39 ----- .../os_linux/LinuxMemoryExtension.java | 67 -------- .../plugins/os_linux/LinuxMemoryStat.java | 63 -------- .../plugins/os_linux/LinuxNetworkDevStat.java | 105 ------------- .../os_linux/LinuxNetworkExtension.java | 16 +- .../os_linux/LinuxProcessorExtension.java | 95 ------------ .../os_linux/LinuxProcessorProcLine.java | 95 ------------ .../plugins/os_linux/LinuxProcessorStat.java | 60 ------- .../src/test/groovy/LinuxDiskTest.groovy | 43 ------ .../src/test/groovy/LinuxMemoryTest.groovy | 28 ---- .../src/test/groovy/LinuxNetworkTest.groovy | 41 ----- .../src/test/groovy/LinuxProcessorTest.groovy | 48 ------ 48 files changed, 451 insertions(+), 1299 deletions(-) delete mode 100644 plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixDiskExtension.java delete mode 100644 plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixDiskStat.java delete mode 100644 plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixMemoryExtension.java delete mode 100644 plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixMemoryStat.java delete mode 100644 plugins/os-aix/src/test/groovy/AixDiskTest.groovy delete mode 100644 plugins/os-aix/src/test/groovy/AixMemoryTest.groovy delete mode 100644 plugins/os-aix/src/test/resources/iostat.txt delete mode 100644 plugins/os-aix/src/test/resources/mpstat-v.txt delete mode 100644 plugins/os-aix/src/test/resources/svmon.txt delete mode 100644 plugins/os-aix/src/test/resources/vmstat-Iwt.txt create mode 100644 plugins/os-base/README.md create mode 100644 plugins/os-base/build.gradle create mode 100644 plugins/os-base/gradle.properties create mode 100644 plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseDiskExtension.java create mode 100644 plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseMemoryExtension.java create mode 100644 plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseNetworkExtension.java create mode 100644 plugins/os-base/src/main/java/sysmon/plugins/os_base/BasePlugin.java create mode 100644 plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessorExtension.java rename plugins/{os-linux => os-base}/src/test/resources/free.txt (100%) rename plugins/{os-linux => os-base}/src/test/resources/meminfo.txt (100%) rename plugins/{os-linux => os-base}/src/test/resources/proc_diskstats1.txt (100%) rename plugins/{os-linux => os-base}/src/test/resources/proc_diskstats2.txt (100%) rename plugins/{os-linux => os-base}/src/test/resources/proc_net_dev1.txt (100%) rename plugins/{os-linux => os-base}/src/test/resources/proc_net_dev2.txt (100%) create mode 100644 plugins/os-base/src/test/resources/proc_net_sockstat.txt rename plugins/{os-linux => os-base}/src/test/resources/proc_stats1.txt (100%) rename plugins/{os-linux => os-base}/src/test/resources/proc_stats2.txt (100%) delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskExtension.java delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskProcLine.java delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskStat.java delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxMemoryExtension.java delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxMemoryStat.java delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevStat.java delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorExtension.java delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorProcLine.java delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorStat.java delete mode 100644 plugins/os-linux/src/test/groovy/LinuxDiskTest.groovy delete mode 100644 plugins/os-linux/src/test/groovy/LinuxMemoryTest.groovy delete mode 100644 plugins/os-linux/src/test/groovy/LinuxProcessorTest.groovy diff --git a/build.gradle b/build.gradle index 33063c7..77fdee7 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,7 @@ subprojects { implementation "org.slf4j:slf4j-api:${slf4jVersion}" implementation "org.slf4j:slf4j-simple:${slf4jVersion}" + } repositories { diff --git a/client/build.gradle b/client/build.gradle index 19f4750..131cc96 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -19,6 +19,10 @@ dependencies { implementation "info.picocli:picocli:${picocliVersion}" implementation 'org.tomlj:tomlj:1.0.0' + implementation(group: 'com.github.oshi', name: 'oshi-core', version: "5.7.3") { + exclude(group: "org.slf4j") + } + implementation group: 'org.apache.camel', name: 'camel-core', version: camelVersion implementation group: 'org.apache.camel', name: 'camel-main', version: camelVersion implementation group: 'org.apache.camel', name: 'camel-http', version: camelVersion diff --git a/plugins/build.gradle b/plugins/build.gradle index 2611a36..e135ccd 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -20,6 +20,11 @@ subprojects { exclude(group: "org.slf4j") } annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") + + implementation(group: 'com.github.oshi', name: 'oshi-core', version: "5.7.3") { + exclude(group: "org.slf4j") + } + } /* diff --git a/plugins/os-aix/build.gradle b/plugins/os-aix/build.gradle index a76f366..0c41fcb 100644 --- a/plugins/os-aix/build.gradle +++ b/plugins/os-aix/build.gradle @@ -1,6 +1,3 @@ dependencies { - implementation(group: 'com.github.oshi', name: 'oshi-core', version: "5.7.3") { - exclude(group: "org.slf4j") - } } diff --git a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixDiskExtension.java b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixDiskExtension.java deleted file mode 100644 index a986d93..0000000 --- a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixDiskExtension.java +++ /dev/null @@ -1,91 +0,0 @@ -package sysmon.plugins.os_aix; - -import org.pf4j.Extension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import oshi.SystemInfo; -import oshi.hardware.HardwareAbstractionLayer; -import sysmon.shared.Measurement; -import sysmon.shared.MetricExtension; -import sysmon.shared.MetricResult; -import sysmon.shared.PluginHelper; - -import java.util.List; -import java.util.Map; - - -@Extension -public class AixDiskExtension implements MetricExtension { - - private static final Logger log = LoggerFactory.getLogger(AixProcessorExtension.class); - - private final SystemInfo systemInfo; - private final HardwareAbstractionLayer hardwareAbstractionLayer; - - @Override - public boolean isSupported() { - - if(!System.getProperty("os.name").toLowerCase().contains("aix")) { - log.warn("Requires AIX."); - return false; - } - - if(!PluginHelper.canExecute("iostat")) { - log.warn("Requires the 'iostat' command."); - return false; - } - - return true; - } - - - public AixDiskExtension() { - systemInfo = new SystemInfo(); - hardwareAbstractionLayer = systemInfo.getHardware(); - log.warn(systemInfo.getOperatingSystem().toString()); - } - - - @Override - public String getName() { - return "aix-disk"; - } - - @Override - public String getProvides() { - return "disk"; - } - - @Override - public String getDescription() { - return "AIX Disk Metrics"; - } - - @Override - public MetricResult getMetrics() { - - long writeBytes = hardwareAbstractionLayer.getDiskStores().get(0).getWriteBytes(); - log.warn(String.format("Disk 0 - Write Bytes: %d", writeBytes)); - - long readBytes = hardwareAbstractionLayer.getDiskStores().get(0).getReadBytes(); - log.warn(String.format("Disk 0 - Read Bytes: %d", readBytes)); - - long memAvailable = hardwareAbstractionLayer.getMemory().getAvailable(); - log.warn(String.format("Memory - Available: %d", memAvailable)); - - List iostat = PluginHelper.executeCommand("iostat -d 1 1"); - AixDiskStat diskStat = processCommandOutput(iostat); - - Map tagsMap = diskStat.getTags(); - Map fieldsMap = diskStat.getFields(); - - return new MetricResult("disk", new Measurement(tagsMap, fieldsMap)); - } - - - protected AixDiskStat processCommandOutput(List inputLines) { - return new AixDiskStat(inputLines); - } - - -} diff --git a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixDiskStat.java b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixDiskStat.java deleted file mode 100644 index 00b7e6a..0000000 --- a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixDiskStat.java +++ /dev/null @@ -1,53 +0,0 @@ -package sysmon.plugins.os_aix; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class AixDiskStat { - - // Disks: % tm_act Kbps tps Kb_read Kb_wrtn - // hdisk0 1.0 752.0 81.0 740 12 - private final Pattern pattern = Pattern.compile("^(hdisk\\d+)\\s+(\\d+\\.?\\d*)\\s+\\s+(\\d+\\.?\\d*)\\s+\\s+(\\d+\\.?\\d*)\\s+(\\d+)\\s+(\\d+)"); - - //private String device; - //private Float tmAct = 0.0f; // Indicates the percentage of time the physical disk/tape was active (bandwidth utilization for the drive). - private float kbps = 0.0f; // Indicates the amount of data transferred (read or written) to the drive in KB per second. - private float tps = 0.0f; // Indicates the number of transfers per second that were issued to the physical disk/tape. A transfer is an I/O request to the physical disk/tape. Multiple logical requests can be combined into a single I/O request to the disk. A transfer is of indeterminate size. - private long kbRead = 0L; // The total number of KB read. - private long kbWritten = 0L; // The total number of KB written. - - - AixDiskStat(List lines) { - - for (String line : lines) { - if (line.startsWith("hdisk")) { - Matcher matcher = pattern.matcher(line); - if (matcher.find() && matcher.groupCount() == 6) { - //device = matcher.group(1); - //tmAct = Float.parseFloat(matcher.group(2)); - kbps += Float.parseFloat(matcher.group(3)); - tps += Float.parseFloat(matcher.group(4)); - kbRead += Long.parseLong(matcher.group(5)); - kbWritten += Long.parseLong(matcher.group(6)); - } - } - } - - } - - public Map getTags() { - return new HashMap<>(); - } - - public Map getFields() { - Map fields = new HashMap<>(); - fields.put("reads", kbRead * 1024); // from Kb to bytes - fields.put("writes", kbWritten * 1024); // from Kb to bytes - fields.put("kbps", (int) kbps); - fields.put("tps", (int) tps); - return fields; - } -} diff --git a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixMemoryExtension.java b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixMemoryExtension.java deleted file mode 100644 index 89ad1fb..0000000 --- a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixMemoryExtension.java +++ /dev/null @@ -1,68 +0,0 @@ -package sysmon.plugins.os_aix; - -import org.pf4j.Extension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sysmon.shared.Measurement; -import sysmon.shared.MetricExtension; -import sysmon.shared.MetricResult; -import sysmon.shared.PluginHelper; - -import java.util.List; -import java.util.Map; - -@Extension -public class AixMemoryExtension implements MetricExtension { - - private static final Logger log = LoggerFactory.getLogger(AixMemoryExtension.class); - - @Override - public boolean isSupported() { - - if(!System.getProperty("os.name").toLowerCase().contains("aix")) { - log.warn("Requires AIX."); - return false; - } - - if(!PluginHelper.canExecute("svmon")) { - log.warn("Requires the 'svmon' command."); - return false; - } - - return true; - } - - @Override - public String getName() { - return "aix-memory"; - } - - @Override - public String getProvides() { - return "memory"; - } - - @Override - public String getDescription() { - return "AIX Memory Metrics"; - } - - @Override - public MetricResult getMetrics() { - - //List svmon = PluginHelper.executeCommand("svmon -G -O unit=KB"); - List svmon = PluginHelper.executeCommand("svmon -G -O summary=longreal,unit=KB"); - AixMemoryStat memoryStat = processCommandOutput(svmon); - - Map tagsMap = memoryStat.getTags(); - Map fieldsMap = memoryStat.getFields(); - - return new MetricResult("memory", new Measurement(tagsMap, fieldsMap)); - } - - protected AixMemoryStat processCommandOutput(List inputLines) { - return new AixMemoryStat(inputLines); - } - - -} diff --git a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixMemoryStat.java b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixMemoryStat.java deleted file mode 100644 index 6935545..0000000 --- a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixMemoryStat.java +++ /dev/null @@ -1,60 +0,0 @@ -package sysmon.plugins.os_aix; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class AixMemoryStat { - - private final Pattern pattern = Pattern.compile("^\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)"); - - private long total; - private long used; - private long free; - private long pin; - private long virtual; - private long available; - private long paged; - - AixMemoryStat(List lines) { - for (String line : lines) { - Matcher matcher = pattern.matcher(line); - if (matcher.find() && matcher.groupCount() == 7) { - total = Long.parseLong(matcher.group(1)); - used = Long.parseLong(matcher.group(2)); - free = Long.parseLong(matcher.group(3)); - pin = Long.parseLong(matcher.group(4)); - virtual = Long.parseLong(matcher.group(5)); - available = Long.parseLong(matcher.group(6)); - paged = Long.parseLong(matcher.group(7)); - break; - } - } - } - - - public Map getTags() { - return new HashMap<>(); - } - - - public Map getFields() { - - float usage = ((float) (total - available) / total ) * 100; - //BigDecimal usage = new BigDecimal(tmp).setScale(2, RoundingMode.HALF_UP); - - Map fields = new HashMap<>(); - fields.put("total", total); - fields.put("used", used); - fields.put("free", free); - fields.put("pin", pin); - fields.put("virtual", virtual); - fields.put("available", available); - fields.put("paged", paged); - fields.put("usage", usage); - return fields; - } - -} diff --git a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorExtension.java b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorExtension.java index b0fd8c4..426e72b 100644 --- a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorExtension.java +++ b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorExtension.java @@ -40,7 +40,7 @@ public class AixProcessorExtension implements MetricExtension { @Override public String getProvides() { - return "processor"; + return "processor-lpar"; } @Override @@ -57,7 +57,7 @@ public class AixProcessorExtension implements MetricExtension { Map tagsMap = processorStat.getTags(); Map fieldsMap = processorStat.getFields(); - return new MetricResult("processor", new Measurement(tagsMap, fieldsMap)); + return new MetricResult("processor_lpar", new Measurement(tagsMap, fieldsMap)); } diff --git a/plugins/os-aix/src/test/groovy/AixDiskTest.groovy b/plugins/os-aix/src/test/groovy/AixDiskTest.groovy deleted file mode 100644 index 074f8ad..0000000 --- a/plugins/os-aix/src/test/groovy/AixDiskTest.groovy +++ /dev/null @@ -1,26 +0,0 @@ -import sysmon.plugins.os_aix.AixDiskExtension -import sysmon.plugins.os_aix.AixDiskStat -import spock.lang.Specification - -class AixDiskTest extends Specification { - - void "test AIX iostat output processing"() { - - setup: - def testFile = new File(getClass().getResource('/iostat.txt').toURI()) - List lines = testFile.readLines("UTF-8") - - when: - AixDiskExtension extension = new AixDiskExtension() - AixDiskStat stats = extension.processCommandOutput(lines) - - then: - //stats.getTags().get("device") == "hdisk0" - stats.getFields().get("reads") == 757760L - stats.getFields().get("writes") == 12288L - stats.getFields().get("kbps") == 752L - stats.getFields().get("tps") == 81L - - } - -} diff --git a/plugins/os-aix/src/test/groovy/AixMemoryTest.groovy b/plugins/os-aix/src/test/groovy/AixMemoryTest.groovy deleted file mode 100644 index 8256b80..0000000 --- a/plugins/os-aix/src/test/groovy/AixMemoryTest.groovy +++ /dev/null @@ -1,29 +0,0 @@ -import sysmon.plugins.os_aix.AixMemoryExtension -import sysmon.plugins.os_aix.AixMemoryStat -import spock.lang.Specification - -class AixMemoryTest extends Specification { - - void "test AIX svmon output processing"() { - - setup: - def testFile = new File(getClass().getResource('/svmon.txt').toURI()) - List lines = testFile.readLines("UTF-8") - - when: - AixMemoryExtension extension = new AixMemoryExtension() - AixMemoryStat stats = extension.processCommandOutput(lines) - - then: - stats.getFields().get("total") == 4194304L - stats.getFields().get("used") == 4065060L - stats.getFields().get("free") == 129244L - stats.getFields().get("pin") == 1878240L - stats.getFields().get("virtual") == 2784988L - stats.getFields().get("available") == 1058012L - stats.getFields().get("paged") == 524288L - stats.getFields().get("usage") == 74.775024f - - } - -} diff --git a/plugins/os-aix/src/test/resources/iostat.txt b/plugins/os-aix/src/test/resources/iostat.txt deleted file mode 100644 index 9b0b3b0..0000000 --- a/plugins/os-aix/src/test/resources/iostat.txt +++ /dev/null @@ -1,3 +0,0 @@ -Disks: % tm_act Kbps tps Kb_read Kb_wrtn -cd0 0.0 0.0 0.0 0 0 -hdisk0 1.0 752.0 81.0 740 12 diff --git a/plugins/os-aix/src/test/resources/mpstat-v.txt b/plugins/os-aix/src/test/resources/mpstat-v.txt deleted file mode 100644 index 7922964..0000000 --- a/plugins/os-aix/src/test/resources/mpstat-v.txt +++ /dev/null @@ -1,15 +0,0 @@ - -System configuration: lcpu=8 ent=0.5 mode=Uncapped - - -vcpu lcpu us sy wa id pbusy pc VTB(ms) ----- ---- ---- ---- ----- ----- ----- ----- ------- -0 33.51 5.62 0.11 60.77 0.00[ 39.1%] 0.00[ 0.1%] 1784440 - 0 13.38 3.96 0.05 4.81 0.00[ 17.3%] 0.00[ 22.2%] - - 1 8.41 0.72 0.04 7.59 0.00[ 9.1%] 0.00[ 16.8%] - - 2 5.19 0.35 0.01 6.45 0.00[ 5.5%] 0.00[ 12.0%] - - 3 4.42 0.28 0.01 8.42 0.00[ 4.7%] 0.00[ 13.1%] - - 4 0.57 0.07 0.00 7.47 0.00[ 0.6%] 0.00[ 8.1%] - - 5 0.51 0.06 0.00 9.28 0.00[ 0.6%] 0.00[ 9.8%] - - 6 0.49 0.07 0.00 7.49 0.00[ 0.6%] 0.00[ 8.1%] - - 7 0.54 0.10 0.00 9.26 0.00[ 0.6%] 0.00[ 9.9%] - diff --git a/plugins/os-aix/src/test/resources/svmon.txt b/plugins/os-aix/src/test/resources/svmon.txt deleted file mode 100644 index 8774006..0000000 --- a/plugins/os-aix/src/test/resources/svmon.txt +++ /dev/null @@ -1,6 +0,0 @@ -Unit: KB ------------------------------------------------------------------------- - Memory ------------------------------------------------------------------------- - Size Inuse Free Pin Virtual Available Pgsp - 4194304 4065060 129244 1878240 2784988 1058012 524288 diff --git a/plugins/os-aix/src/test/resources/vmstat-Iwt.txt b/plugins/os-aix/src/test/resources/vmstat-Iwt.txt deleted file mode 100644 index e294e51..0000000 --- a/plugins/os-aix/src/test/resources/vmstat-Iwt.txt +++ /dev/null @@ -1,7 +0,0 @@ - -System configuration: lcpu=8 mem=4096MB ent=0.50 - - kthr memory page faults cpu time ------------ --------------------- ------------------------------------ ------------------ ----------------------- -------- - r b p avm fre fi fo pi po fr sr in sy cs us sy id wa pc ec hr mi se - 2 1 0 633739 130144 0 13 0 0 2 2 7 969 529 0 0 99 0 0.00 0.1 07:53:28 diff --git a/plugins/os-base/README.md b/plugins/os-base/README.md new file mode 100644 index 0000000..6a0bd86 --- /dev/null +++ b/plugins/os-base/README.md @@ -0,0 +1,36 @@ +# Base Plugin + +## Processor Extension + +Reports the following metrics seen: + +- **user** - CPU time spend on user processes. +- **system** -CPU time spend on system processes. +- **iowait** - CPU time spend on waiting (for i/o). +- **idle** - CPU time spend on idle (doing nothing). +- **busy** - CPU time not spend on idle (working). + + +## Memory Extension + +Reports the following metrics, from the *free* command: + +- **total** - The total amount of (installed) memory (in KB). +- **used** - Used memory (calculated as total - free - buffers - cache) (in KB). +- **free** - Unused memory (MemFree and SwapFree in /proc/meminfo) (in KB). +- **shared** - Memory used (mostly) by tmpfs (Shmem in /proc/meminfo) (in KB). +- **buffers** - Sum of buffers and cache (in KB). +- **available** - Estimation of how much memory is available for starting new applications, without swapping (in KB). +- **usage** - Percentage of memory used out of the total amount of memory. + + +## Disk Extension + + +Only reports first device found. Improvements on the TODO. + +Metrics reported are: + +- **device** - Name of device. +- **reads** - The total number of KB read. +- **writes** - The total number of KB written. diff --git a/plugins/os-base/build.gradle b/plugins/os-base/build.gradle new file mode 100644 index 0000000..d18c3d3 --- /dev/null +++ b/plugins/os-base/build.gradle @@ -0,0 +1,2 @@ +plugins { +} \ No newline at end of file diff --git a/plugins/os-base/gradle.properties b/plugins/os-base/gradle.properties new file mode 100644 index 0000000..3aaf9bc --- /dev/null +++ b/plugins/os-base/gradle.properties @@ -0,0 +1,7 @@ +pluginId=sysmon-base +pluginClass=sysmon.plugins.os_base.BasePlugin +pluginVersion=0.0.1 +pluginProvider=System Monitor +pluginDependencies= +pluginDescription=Base OS metrics where supported. + diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseDiskExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseDiskExtension.java new file mode 100644 index 0000000..477b8e5 --- /dev/null +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseDiskExtension.java @@ -0,0 +1,87 @@ +package sysmon.plugins.os_base; + +import org.pf4j.Extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import oshi.SystemInfo; +import oshi.hardware.HWDiskStore; +import oshi.hardware.HardwareAbstractionLayer; +import sysmon.shared.Measurement; +import sysmon.shared.MetricExtension; +import sysmon.shared.MetricResult; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Extension +public class BaseDiskExtension implements MetricExtension { + + private static final Logger log = LoggerFactory.getLogger(BaseDiskExtension.class); + + private SystemInfo systemInfo; + private HardwareAbstractionLayer hardwareAbstractionLayer; + + + @Override + public boolean isSupported() { + + try { + systemInfo = new SystemInfo(); + hardwareAbstractionLayer = systemInfo.getHardware(); + return true; + } catch (UnsupportedOperationException e) { + log.warn(e.getMessage()); + } + + return false; + } + + @Override + public String getName() { + return "base-disk"; + } + + @Override + public String getProvides() { + return "disk"; + } + + @Override + public String getDescription() { + return "Base Disk Metrics"; + } + + + @Override + public MetricResult getMetrics() { + + long writeBytes = 0L; + long readBytes = 0L; + long transferTime = 0L; + long queueLength = 0L; + + Map tagsMap = new HashMap<>(); + Map fieldsMap = new HashMap<>(); + + List diskStores = hardwareAbstractionLayer.getDiskStores(); + for(HWDiskStore store : diskStores) { + String name = store.getName(); + if (name.matches("hdisk[0-9]+") || name.matches("/dev/[sv]d[a-z]{1}") || name.matches("/dev/nvme[0-9]n[0-9]")) { + log.debug("Using device: " + name); + writeBytes += store.getWriteBytes(); + readBytes += store.getReadBytes(); + transferTime += store.getTransferTime(); + queueLength = store.getCurrentQueueLength(); + } + } + + fieldsMap.put("reads", readBytes); + fieldsMap.put("writes", writeBytes); + fieldsMap.put("iotime", transferTime); + fieldsMap.put("queue", queueLength); + + return new MetricResult("disk", new Measurement(tagsMap, fieldsMap)); + } + +} \ No newline at end of file diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseMemoryExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseMemoryExtension.java new file mode 100644 index 0000000..4af172a --- /dev/null +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseMemoryExtension.java @@ -0,0 +1,72 @@ +package sysmon.plugins.os_base; + +import org.pf4j.Extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import oshi.SystemInfo; +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 BaseMemoryExtension implements MetricExtension { + + private static final Logger log = LoggerFactory.getLogger(BaseMemoryExtension.class); + + private SystemInfo systemInfo; + private HardwareAbstractionLayer hardwareAbstractionLayer; + + @Override + public boolean isSupported() { + + try { + systemInfo = new SystemInfo(); + hardwareAbstractionLayer = systemInfo.getHardware(); + return true; + } catch (UnsupportedOperationException e) { + log.warn(e.getMessage()); + } + + return false; + } + + @Override + public String getName() { + return "base-memory"; + } + + @Override + public String getProvides() { + return "memory"; + } + + @Override + public String getDescription() { + return "Base Memory Metrics"; + } + + @Override + public MetricResult getMetrics() { + + Map tagsMap = new HashMap<>(); + Map fieldsMap = new HashMap<>(); + + long total = hardwareAbstractionLayer.getMemory().getTotal(); + long available = hardwareAbstractionLayer.getMemory().getAvailable(); + float usage = ((float) (total - available) / total ) * 100; + + fieldsMap.put("available", available); + fieldsMap.put("total", total); + fieldsMap.put("usage", usage); + fieldsMap.put("paged", hardwareAbstractionLayer.getMemory().getPageSize()); + fieldsMap.put("virtual", hardwareAbstractionLayer.getMemory().getVirtualMemory().getVirtualInUse()); + + return new MetricResult("memory", new Measurement(tagsMap, fieldsMap)); + } + + +} diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseNetworkExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseNetworkExtension.java new file mode 100644 index 0000000..74e67a4 --- /dev/null +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseNetworkExtension.java @@ -0,0 +1,89 @@ +package sysmon.plugins.os_base; + +import org.pf4j.Extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import oshi.SystemInfo; +import oshi.hardware.HardwareAbstractionLayer; +import oshi.hardware.NetworkIF; +import sysmon.shared.Measurement; +import sysmon.shared.MetricExtension; +import sysmon.shared.MetricResult; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Extension +public class BaseNetworkExtension implements MetricExtension { + + private static final Logger log = LoggerFactory.getLogger(BaseNetworkExtension.class); + + private SystemInfo systemInfo; + private HardwareAbstractionLayer hardwareAbstractionLayer; + + @Override + public boolean isSupported() { + + try { + systemInfo = new SystemInfo(); + hardwareAbstractionLayer = systemInfo.getHardware(); + return true; + } catch (UnsupportedOperationException e) { + log.warn(e.getMessage()); + } + + return false; + } + + @Override + public String getName() { + return "base-network"; + } + + @Override + public String getProvides() { + return "network"; + } + + @Override + public String getDescription() { + return "Base Network Metrics"; + } + + @Override + public MetricResult getMetrics() { + + long rxBytes = 0L; + long rxPackets = 0L; + long rxErrs = 0L; + long txBytes = 0L; + long txPackets = 0L; + long txErrs = 0L; + + Map tagsMap = new HashMap<>(); + Map fieldsMap = new HashMap<>(); + + List interfaces = hardwareAbstractionLayer.getNetworkIFs(); + for(NetworkIF netif : interfaces) { + //String name = netif.getName(); + //log.warn("Device: " + name); + rxPackets += netif.getPacketsRecv(); + txPackets += netif.getPacketsSent(); + rxBytes += netif.getBytesRecv(); + txBytes += netif.getBytesSent(); + rxErrs += netif.getInErrors(); + txErrs += netif.getOutErrors(); + } + + fieldsMap.put("rxPackets", rxPackets); + fieldsMap.put("txPackets", txPackets); + fieldsMap.put("rxBytes", rxBytes); + fieldsMap.put("txBytes", txBytes); + fieldsMap.put("rxErrors", rxErrs); + fieldsMap.put("txErrors", txErrs); + + return new MetricResult("network", new Measurement(tagsMap, fieldsMap)); + } + +} diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BasePlugin.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BasePlugin.java new file mode 100644 index 0000000..203cceb --- /dev/null +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BasePlugin.java @@ -0,0 +1,17 @@ +package sysmon.plugins.os_base; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.pf4j.Plugin; +import org.pf4j.PluginWrapper; + + +public class BasePlugin extends Plugin { + + private static final Logger log = LoggerFactory.getLogger(BasePlugin.class); + + public BasePlugin(PluginWrapper wrapper) { + super(wrapper); + } + +} diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessorExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessorExtension.java new file mode 100644 index 0000000..ee47348 --- /dev/null +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessorExtension.java @@ -0,0 +1,111 @@ +package sysmon.plugins.os_base; + +import org.pf4j.Extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import oshi.SystemInfo; +import oshi.hardware.CentralProcessor; +import oshi.hardware.HardwareAbstractionLayer; +import sysmon.shared.Measurement; +import sysmon.shared.MetricExtension; +import sysmon.shared.MetricResult; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Extension +public class BaseProcessorExtension implements MetricExtension { + + private static final Logger log = LoggerFactory.getLogger(BaseProcessorExtension.class); + + private SystemInfo systemInfo; + private HardwareAbstractionLayer hardwareAbstractionLayer; + + @Override + public boolean isSupported() { + + try { + systemInfo = new SystemInfo(); + hardwareAbstractionLayer = systemInfo.getHardware(); + return true; + } catch (UnsupportedOperationException e) { + log.warn(e.getMessage()); + } + + return false; + } + + @Override + public String getName() { + return "base-processor"; + } + + @Override + public String getProvides() { + return "processor"; + } + + @Override + public String getDescription() { + return "Base Processor Metrics"; + } + + + @Override + public MetricResult getMetrics() { + + Map tagsMap = new HashMap<>(); + Map fieldsMap = new HashMap<>(); + + long user = 0L; + long system = 0L; + long steal = 0L; + long irq = 0L; + long softirq = 0L; + long nice = 0L; + long idle = 0L; + long iowait = 0L; + + long[][] ticks = hardwareAbstractionLayer.getProcessor().getProcessorCpuLoadTicks(); + int cores = ticks.length; + //log.warn("Cores: " + cores); + for (long[] tick : ticks) { + nice += tick[CentralProcessor.TickType.NICE.getIndex()]; + user += tick[CentralProcessor.TickType.USER.getIndex()]; + system += tick[CentralProcessor.TickType.SYSTEM.getIndex()]; + steal += tick[CentralProcessor.TickType.STEAL.getIndex()]; + irq += tick[CentralProcessor.TickType.IRQ.getIndex()]; + softirq += tick[CentralProcessor.TickType.SOFTIRQ.getIndex()]; + idle += tick[CentralProcessor.TickType.IDLE.getIndex()]; + iowait += tick[CentralProcessor.TickType.IOWAIT.getIndex()]; + } + + long busy = nice + user + system + steal + irq + softirq; + long nonBusy = idle + iowait; + long total = busy + nonBusy; + + log.info("idle: " + idle); + log.info("iowait: " + iowait); + log.info("busy: " + busy); + log.info("nonBusy: " + nonBusy); + log.info("total: " + total); + + fieldsMap.put("user", (float) user / (float) total); + fieldsMap.put("iowait", (float) iowait / (float) total); + fieldsMap.put("idle", (float) nonBusy / (float) total); + fieldsMap.put("busy", (float) busy / (float) total); + fieldsMap.put("system", (float) system / (float) total); + + log.info(fieldsMap.toString()); + return new MetricResult("processor", new Measurement(tagsMap, fieldsMap)); + } + +} + + diff --git a/plugins/os-linux/src/test/resources/free.txt b/plugins/os-base/src/test/resources/free.txt similarity index 100% rename from plugins/os-linux/src/test/resources/free.txt rename to plugins/os-base/src/test/resources/free.txt diff --git a/plugins/os-linux/src/test/resources/meminfo.txt b/plugins/os-base/src/test/resources/meminfo.txt similarity index 100% rename from plugins/os-linux/src/test/resources/meminfo.txt rename to plugins/os-base/src/test/resources/meminfo.txt diff --git a/plugins/os-linux/src/test/resources/proc_diskstats1.txt b/plugins/os-base/src/test/resources/proc_diskstats1.txt similarity index 100% rename from plugins/os-linux/src/test/resources/proc_diskstats1.txt rename to plugins/os-base/src/test/resources/proc_diskstats1.txt diff --git a/plugins/os-linux/src/test/resources/proc_diskstats2.txt b/plugins/os-base/src/test/resources/proc_diskstats2.txt similarity index 100% rename from plugins/os-linux/src/test/resources/proc_diskstats2.txt rename to plugins/os-base/src/test/resources/proc_diskstats2.txt diff --git a/plugins/os-linux/src/test/resources/proc_net_dev1.txt b/plugins/os-base/src/test/resources/proc_net_dev1.txt similarity index 100% rename from plugins/os-linux/src/test/resources/proc_net_dev1.txt rename to plugins/os-base/src/test/resources/proc_net_dev1.txt diff --git a/plugins/os-linux/src/test/resources/proc_net_dev2.txt b/plugins/os-base/src/test/resources/proc_net_dev2.txt similarity index 100% rename from plugins/os-linux/src/test/resources/proc_net_dev2.txt rename to plugins/os-base/src/test/resources/proc_net_dev2.txt diff --git a/plugins/os-base/src/test/resources/proc_net_sockstat.txt b/plugins/os-base/src/test/resources/proc_net_sockstat.txt new file mode 100644 index 0000000..f0c0afc --- /dev/null +++ b/plugins/os-base/src/test/resources/proc_net_sockstat.txt @@ -0,0 +1,6 @@ +sockets: used 1238 +TCP: inuse 52 orphan 0 tw 18 alloc 55 mem 7 +UDP: inuse 11 mem 10 +UDPLITE: inuse 0 +RAW: inuse 0 +FRAG: inuse 0 memory 0 diff --git a/plugins/os-linux/src/test/resources/proc_stats1.txt b/plugins/os-base/src/test/resources/proc_stats1.txt similarity index 100% rename from plugins/os-linux/src/test/resources/proc_stats1.txt rename to plugins/os-base/src/test/resources/proc_stats1.txt diff --git a/plugins/os-linux/src/test/resources/proc_stats2.txt b/plugins/os-base/src/test/resources/proc_stats2.txt similarity index 100% rename from plugins/os-linux/src/test/resources/proc_stats2.txt rename to plugins/os-base/src/test/resources/proc_stats2.txt diff --git a/plugins/os-linux/README.md b/plugins/os-linux/README.md index 3e23e69..6a0bd86 100644 --- a/plugins/os-linux/README.md +++ b/plugins/os-linux/README.md @@ -1,14 +1,14 @@ -# Linux Plugin +# Base Plugin ## Processor Extension Reports the following metrics seen: -- **user** - Percentage of CPU time spend on user processes. -- **sys** - Percentage of CPU time spend on system processes. -- **wait** - Percentage of CPU time spend on waiting (for i/o). -- **idle** - Percentage of CPU time spend on idle (doing nothing). -- **busy** - Percentage of CPU time not spend on idle (working). +- **user** - CPU time spend on user processes. +- **system** -CPU time spend on system processes. +- **iowait** - CPU time spend on waiting (for i/o). +- **idle** - CPU time spend on idle (doing nothing). +- **busy** - CPU time not spend on idle (working). ## Memory Extension diff --git a/plugins/os-linux/gradle.properties b/plugins/os-linux/gradle.properties index 3a97f32..715d387 100644 --- a/plugins/os-linux/gradle.properties +++ b/plugins/os-linux/gradle.properties @@ -3,5 +3,5 @@ pluginClass=sysmon.plugins.os_linux.LinuxPlugin pluginVersion=0.0.1 pluginProvider=System Monitor pluginDependencies= -pluginDescription=Collects Linux OS metrics. +pluginDescription=Linux OS Metrics. diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskExtension.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskExtension.java deleted file mode 100644 index c46d237..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskExtension.java +++ /dev/null @@ -1,88 +0,0 @@ -package sysmon.plugins.os_linux; - -import org.pf4j.Extension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sysmon.shared.Measurement; -import sysmon.shared.MetricExtension; -import sysmon.shared.MetricResult; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -@Extension -public class LinuxDiskExtension implements MetricExtension { - - private static final Logger log = LoggerFactory.getLogger(LinuxDiskExtension.class); - - - @Override - public boolean isSupported() { - return System.getProperty("os.name").toLowerCase().contains("linux"); - } - - @Override - public String getName() { - return "linux-disk"; - } - - @Override - public String getProvides() { - return "disk"; - } - - @Override - public String getDescription() { - return "Linux Disk Metrics"; - } - - - @Override - public MetricResult getMetrics() { - - LinuxDiskProcLine proc1 = processFileOutput(readProcFile()); - try { - Thread.sleep(1 * 1000); // TODO: Configure sample collect time - } catch (InterruptedException e) { - log.warn("getMetrics() - sleep interrupted"); - return null; - } - LinuxDiskProcLine proc2 = processFileOutput(readProcFile()); - - LinuxDiskStat stat = new LinuxDiskStat(proc1, proc2); - return new MetricResult("disk", new Measurement(stat.getTags(), stat.getFields())); - } - - - protected List readProcFile() { - - List allLines = new ArrayList<>(); - try { - allLines = Files.readAllLines(Paths.get("/proc/diskstats"), StandardCharsets.UTF_8); - } catch (IOException e) { - log.error(e.getMessage()); - } - return allLines; - } - - - protected LinuxDiskProcLine processFileOutput(List inputLines) { - - List lines = new ArrayList<>(inputLines.size()); - for(String line : inputLines) { - String[] splitStr = line.trim().split("\\s+"); - String device = splitStr[2]; - if (device.matches("[sv]d[a-z]{1}") || device.matches("nvme[0-9]n[0-9]")) { - //log.warn("Going for: " + line); - lines.add(line); - } - } - - return new LinuxDiskProcLine(lines); - } - -} \ No newline at end of file diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskProcLine.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskProcLine.java deleted file mode 100644 index c3b8dff..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskProcLine.java +++ /dev/null @@ -1,146 +0,0 @@ -package sysmon.plugins.os_linux; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; - -public class LinuxDiskProcLine { - - // Sectors to bytes - each sector is 512 bytes - https://lkml.org/lkml/2015/8/17/269 - private static final int SECTOR_BYTE_SIZE = 512; - - private static final Logger log = LoggerFactory.getLogger(LinuxDiskProcLine.class); - - - /* - == =================================== - 1 major number - 2 minor mumber - 3 device name - 4 reads completed successfully - 5 reads merged - 6 sectors read - 7 time spent reading (ms) - 8 writes completed - 9 writes merged - 10 sectors written - 11 time spent writing (ms) - 12 I/Os currently in progress - 13 time spent doing I/Os (ms) - 14 weighted time spent doing I/Os (ms) - == =================================== - - Kernel 4.18+ appends four more fields for discard - tracking putting the total at 18: - - == =================================== - 15 discards completed successfully - 16 discards merged - 17 sectors discarded - 18 time spent discarding - == =================================== - - Kernel 5.5+ appends two more fields for flush requests: - - == ===================================== - 19 flush requests completed successfully - 20 time spent flushing - == ===================================== - */ - - private long readsCompleted; // successfully - //private long readsMerged; - private long sectorsRead; // 512 bytes pr. sector - private long timeSpentReading; // ms - private long writesCompleted; // successfully - //private long writesMerged; - private long sectorsWritten; // 512 bytes pr. sector - private long timeSpentWriting; // ms - //private long ioInProgress; - private long timeSpentOnIo; // ms - //private long timeSpentOnIoWeighted; - - //private long discardsCompleted; // successfully - //private long discardsMerged; - //private long sectorsDiscarded; // 512 bytes pr. sector - //private long timeSpentDiscarding; // ms - - //private long flushRequestsCompleted; - //private long timeSpentFlushing; // ms - - - public LinuxDiskProcLine(List procLines) { - - for(String procLine : procLines) { - - String[] splitStr = procLine.trim().split("\\s+"); - if (splitStr.length < 14) { - throw new UnsupportedOperationException("Linux proc DISK string error: " + procLine); - } - - //this.major = Integer.parseInt(splitStr[0]); - //this.minor = Integer.parseInt(splitStr[1]); - //this.device = splitStr[2]; - this.readsCompleted += Long.parseLong(splitStr[3]); - //this.readsMerged += Long.parseLong(splitStr[4]); - this.sectorsRead += Long.parseLong(splitStr[5]); - this.timeSpentReading += Long.parseLong(splitStr[6]); - this.writesCompleted += Long.parseLong(splitStr[7]); - //this.writesMerged += Long.parseLong(splitStr[8]); - this.sectorsWritten += Long.parseLong(splitStr[9]); - this.timeSpentWriting += Long.parseLong(splitStr[10]); - //this.ioInProgress += Long.parseLong(splitStr[11]); - this.timeSpentOnIo += Long.parseLong(splitStr[12]); - //this.timeSpentOnIoWeighted += Long.parseLong(splitStr[13]); - - /* - if (splitStr.length >= 18) { - this.discardsCompleted += Long.parseLong(splitStr[10]); - this.discardsMerged += Long.parseLong(splitStr[11]); - this.sectorsDiscarded += Long.parseLong(splitStr[12]); - this.timeSpentDiscarding += Long.parseLong(splitStr[13]); - } else { - this.discardsCompleted = null; - this.discardsMerged = null; - this.sectorsDiscarded = null; - this.timeSpentDiscarding = null; - } - - if (splitStr.length == 20) { - this.flushRequestsCompleted += Long.parseLong(splitStr[14]); - this.timeSpentFlushing += Long.parseLong(splitStr[15]); - } else { - this.flushRequestsCompleted = null; - this.timeSpentFlushing = null; - } - */ - - } - } - - public Long getTimeSpentOnIo() { - return timeSpentOnIo; - } - - public Long getBytesRead() { - return sectorsRead * SECTOR_BYTE_SIZE; - } - - public Long getBytesWritten() { - return sectorsWritten * SECTOR_BYTE_SIZE; - } - - public Long getTimeSpentReading() { - return timeSpentReading; - } - - public Long getTimeSpentWriting() { - return timeSpentWriting; - } - - public Long getTransactions() { - return readsCompleted + writesCompleted; - } - -} diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskStat.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskStat.java deleted file mode 100644 index 71fcb5e..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxDiskStat.java +++ /dev/null @@ -1,39 +0,0 @@ -package sysmon.plugins.os_linux; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.Map; - -public class LinuxDiskStat { - - private String device; - private final long iotime; - private final long reads; - private final long writes; - private final long kbps; - private final long tps; - - LinuxDiskStat(LinuxDiskProcLine proc1, LinuxDiskProcLine proc2) { - iotime = proc2.getTimeSpentOnIo() - proc1.getTimeSpentOnIo(); - writes = proc2.getBytesWritten() - proc1.getBytesWritten(); - reads = proc2.getBytesRead() - proc1.getBytesRead(); - kbps = (writes + reads) / 1024; - tps = proc2.getTransactions() - proc1.getTransactions(); - } - - public Map getTags() { - return new HashMap<>(); - } - - public Map getFields() { - Map fields = new HashMap<>(); - fields.put("iotime", iotime); - fields.put("writes", writes); - fields.put("reads", reads); - fields.put("kbps", kbps); - fields.put("tps", tps); - return fields; - } -} \ No newline at end of file diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxMemoryExtension.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxMemoryExtension.java deleted file mode 100644 index 5995879..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxMemoryExtension.java +++ /dev/null @@ -1,67 +0,0 @@ -package sysmon.plugins.os_linux; - -import org.pf4j.Extension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sysmon.shared.Measurement; -import sysmon.shared.MetricExtension; -import sysmon.shared.MetricResult; -import sysmon.shared.PluginHelper; - -import java.util.List; -import java.util.Map; - -@Extension -public class LinuxMemoryExtension implements MetricExtension { - - private static final Logger log = LoggerFactory.getLogger(LinuxMemoryExtension.class); - - @Override - public boolean isSupported() { - - if(!System.getProperty("os.name").toLowerCase().contains("linux")) { - log.warn("Requires Linux."); - return false; - } - - if(!PluginHelper.canExecute("free")) { - log.warn("Requires the 'free' command."); - return false; - } - - return true; - } - - @Override - public String getName() { - return "linux-memory"; - } - - @Override - public String getProvides() { - return "memory"; - } - - @Override - public String getDescription() { - return "Linux Memory Metrics"; - } - - @Override - public MetricResult getMetrics() { - - List svmon = PluginHelper.executeCommand("free -k"); - LinuxMemoryStat memoryStat = processCommandOutput(svmon); - - Map tagsMap = memoryStat.getTags(); - Map fieldsMap = memoryStat.getFields(); - - return new MetricResult("memory", new Measurement(tagsMap, fieldsMap)); - } - - protected LinuxMemoryStat processCommandOutput(List inputLines) { - return new LinuxMemoryStat(inputLines); - } - - -} diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxMemoryStat.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxMemoryStat.java deleted file mode 100644 index d1d863b..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxMemoryStat.java +++ /dev/null @@ -1,63 +0,0 @@ -package sysmon.plugins.os_linux; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class LinuxMemoryStat { - - /* - total used free shared buff/cache available - Mem: 16069172 5896832 4597860 639780 5574480 9192992 - Swap: 3985404 0 3985404 - */ - private static final Pattern pattern = Pattern.compile("^Mem:\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)"); - - private long total; - private long used; - private long free; - private long shared; - private long buffers; - private long available; - //private String mode; - - LinuxMemoryStat(List lines) { - for (String line : lines) { - Matcher matcher = pattern.matcher(line); - if (matcher.find() && matcher.groupCount() == 6) { - total = Long.parseLong(matcher.group(1)); - used = Long.parseLong(matcher.group(2)); - free = Long.parseLong(matcher.group(3)); - shared = Long.parseLong(matcher.group(4)); - buffers = Long.parseLong(matcher.group(5)); - available = Long.parseLong(matcher.group(6)); - break; - } - } - } - - - public Map getTags() { - return new HashMap<>(); - } - - - public Map getFields() { - - float usage = ((float) (total - available) / total ) * 100; - //BigDecimal usage = new BigDecimal(tmp).setScale(2, RoundingMode.HALF_UP); - - Map fields = new HashMap<>(); - fields.put("total", total); - fields.put("used", used); - fields.put("free", free); - fields.put("shared", shared); - fields.put("buffers", buffers); - fields.put("available", available); - fields.put("usage", usage); - return fields; - } - -} diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevStat.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevStat.java deleted file mode 100644 index bdae2e6..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevStat.java +++ /dev/null @@ -1,105 +0,0 @@ -package sysmon.plugins.os_linux; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class LinuxNetworkDevStat { - - private static final Logger log = LoggerFactory.getLogger(LinuxNetworkDevStat.class); - - private static final Pattern pattern1 = Pattern.compile("^\\s+([a-z]{2,}[0-9]+):.*"); - private static final Pattern pattern2 = Pattern.compile("^\\s+([a-z]{2,}[0-9]+):\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)"); - - private long rxBytes; - private long rxPackets; - private long rxErrs; - - private long txBytes; - private long txPackets; - private long txErrs; - - /* - Inter-| Receive | Transmit - face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed - env2: 657010764 483686 0 0 0 0 0 0 55416850 431020 0 0 0 0 0 0 - env3: 6900272 41836 0 0 0 0 0 0 7667444 41849 0 0 0 0 0 0 - lo: 3098805 14393 0 0 0 0 0 0 3098805 14393 0 0 0 0 0 0 - - */ - - public LinuxNetworkDevStat(List procLines) { - - Matcher matcher1; - Matcher matcher2; - for(String procLine : procLines) { - - matcher1 = pattern1.matcher(procLine); - if(matcher1.matches()) { - - if(matcher1.group(1).equals("lo")) { - continue; - } - - matcher2 = pattern2.matcher(procLine); - if(matcher2.matches() && matcher2.groupCount() == 17) { - - rxBytes += Long.parseLong(matcher2.group(2)); - rxPackets += Long.parseLong(matcher2.group(3)); - rxErrs += Long.parseLong(matcher2.group(4)); - - txBytes += Long.parseLong(matcher2.group(10)); - txPackets += Long.parseLong(matcher2.group(11)); - txErrs += Long.parseLong(matcher2.group(12)); - } - - } - - } - } - - - public long getRxBytes() { - return rxBytes; - } - - public long getRxPackets() { - return rxPackets; - } - - public long getRxErrs() { - return rxErrs; - } - - public long getTxBytes() { - return txBytes; - } - - public long getTxPackets() { - return txPackets; - } - - public long getTxErrs() { - return txErrs; - } - - - public Map getTags() { - return new HashMap<>(); - } - - public Map getFields() { - Map fields = new HashMap<>(); - fields.put("rxBytes", rxBytes); - fields.put("rxPackets", rxPackets); - fields.put("txBytes", txBytes); - fields.put("txPackets", txPackets); - return fields; - } - -} diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkExtension.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkExtension.java index 1d1b710..666051c 100644 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkExtension.java +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkExtension.java @@ -29,39 +29,33 @@ public class LinuxNetworkExtension implements MetricExtension { @Override public String getName() { - return "linux-network"; + return "linux-network-sockets"; } @Override public String getProvides() { - return "network"; + return "network-sockets"; } @Override public String getDescription() { - return "Linux Network Metrics"; + return "Linux Network Socket Metrics"; } @Override public MetricResult getMetrics() { LinuxNetworkSockStat sockStat = processSockOutput(PluginHelper.readFile("/proc/net/sockstat")); - LinuxNetworkDevStat devStat = processDevOutput(PluginHelper.readFile("/proc/net/dev")); Map tagsMap = sockStat.getTags(); Map fieldsMap = sockStat.getFields(); - fieldsMap.putAll(devStat.getFields()); - return new MetricResult("network", new Measurement(tagsMap, fieldsMap)); + return new MetricResult("network_sockets", new Measurement(tagsMap, fieldsMap)); + } protected LinuxNetworkSockStat processSockOutput(List inputLines) { return new LinuxNetworkSockStat(inputLines); } - protected LinuxNetworkDevStat processDevOutput(List inputLines) { - return new LinuxNetworkDevStat(inputLines); - } - - } diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorExtension.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorExtension.java deleted file mode 100644 index cf7cee0..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorExtension.java +++ /dev/null @@ -1,95 +0,0 @@ -package sysmon.plugins.os_linux; - -import org.pf4j.Extension; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import sysmon.shared.Measurement; -import sysmon.shared.MetricExtension; -import sysmon.shared.MetricResult; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -@Extension -public class LinuxProcessorExtension implements MetricExtension { - - private static final Logger log = LoggerFactory.getLogger(LinuxProcessorExtension.class); - - private List currentProcessorProc; - private List previousProcessorProc; - - - @Override - public boolean isSupported() { - return System.getProperty("os.name").toLowerCase().contains("linux"); - } - - @Override - public String getName() { - return "linux-processor"; - } - - @Override - public String getProvides() { - return "processor"; - } - - @Override - public String getDescription() { - return "Linux Processor Metrics"; - } - - - @Override - public MetricResult getMetrics() { - - LinuxProcessorProcLine proc1 = processFileOutput(readProcFile()); - - try { - Thread.sleep(1 * 1000); // TODO: Configure sample collect time - } catch (InterruptedException e) { - log.warn("getMetrics() - sleep interrupted"); - return null; - } - - LinuxProcessorProcLine proc2 = processFileOutput(readProcFile()); - - LinuxProcessorStat stat = new LinuxProcessorStat(proc1, proc2); - - return new MetricResult("processor", new Measurement(stat.getTags(), stat.getFields())); - } - - - - protected List readProcFile() { - - List allLines = new ArrayList<>(); - try { - allLines = Files.readAllLines(Paths.get("/proc/stat"), StandardCharsets.UTF_8); - } catch (IOException e) { - log.error(e.getMessage()); - } - return allLines; - - } - - - protected LinuxProcessorProcLine processFileOutput(List inputLines) { - - for(String line : inputLines) { - if(line.matches("^cpu\\S+.*")) { - return new LinuxProcessorProcLine(line); - } - } - - return null; - } - - -} - - diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorProcLine.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorProcLine.java deleted file mode 100644 index 9ba6369..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorProcLine.java +++ /dev/null @@ -1,95 +0,0 @@ -package sysmon.plugins.os_linux; - -public class LinuxProcessorProcLine { - - private final String cpuName; - private final long userTime; - private final long niceTime; - private final long systemTime; - private final long idleTime; - private final long ioWaitTime; - private final long irqTime; - private final long softIrqTime; - private final long stealTime; - private final long guestTime; - private final long guestNiceTime; - - - public LinuxProcessorProcLine(String procString) { - - String[] splitStr = procString.trim().split("\\s+"); - if(splitStr.length != 11) { - throw new UnsupportedOperationException("Linux proc CPU string error: " + procString); - } - - this.cpuName = splitStr[0]; - this.userTime = Long.parseLong(splitStr[1]); - this.niceTime = Long.parseLong(splitStr[2]); - this.systemTime = Long.parseLong(splitStr[3]); - this.idleTime = Long.parseLong(splitStr[4]); - this.ioWaitTime = Long.parseLong(splitStr[5]); - this.irqTime = Long.parseLong(splitStr[6]); - this.softIrqTime = Long.parseLong(splitStr[7]); - this.stealTime = Long.parseLong(splitStr[8]); - this.guestTime = Long.parseLong(splitStr[9]); - this.guestNiceTime = Long.parseLong(splitStr[10]); - - } - - public String getCpuName() { - return cpuName; - } - - public long getUserTime() { - return userTime; - } - - public long getNiceTime() { - return niceTime; - } - - public long getSystemTime() { - return systemTime; - } - - public long getIdleTime() { - return idleTime; - } - - public long getIoWaitTime() { - return ioWaitTime; - } - - public long getIrqTime() { - return irqTime; - } - - public long getSoftIrqTime() { - return softIrqTime; - } - - public long getStealTime() { - return stealTime; - } - - public long getGuestTime() { - return guestTime; - } - - public long getGuestNiceTime() { - return guestNiceTime; - } - - public long getCombinedIdleTime() { - return idleTime + ioWaitTime; - } - - public long getCombinedWorkTime() { - return userTime + niceTime + systemTime + irqTime + softIrqTime + stealTime + guestTime + guestNiceTime; - } - - public long getCombinedTime() { - return getCombinedIdleTime() + getCombinedWorkTime(); - } - -} diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorStat.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorStat.java deleted file mode 100644 index 8b9947e..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxProcessorStat.java +++ /dev/null @@ -1,60 +0,0 @@ -package sysmon.plugins.os_linux; - -import java.util.HashMap; -import java.util.Map; - -public class LinuxProcessorStat { - - private final float user; - private final float sys; - private final float wait; - private final float idle; - private final float busy; - - public LinuxProcessorStat(LinuxProcessorProcLine previous, LinuxProcessorProcLine current) { - - long workTime = current.getCombinedTime() - previous.getCombinedTime(); - - long busyTime = current.getCombinedIdleTime() - previous.getCombinedIdleTime(); - float busyDiff = (float) (workTime - busyTime) / workTime; - busy = (busyDiff * 100); - - long userTime = current.getUserTime() - previous.getUserTime(); - float userDiff = (float) (workTime - userTime) / workTime; - user = 100 - (userDiff * 100); - - long sysTime = current.getSystemTime() - previous.getSystemTime(); - float sysDiff = (float) (workTime - sysTime) / workTime; - sys = 100 - (sysDiff * 100); - - long waitTime = current.getIoWaitTime() - previous.getIoWaitTime(); - float waitDiff = (float) (workTime - waitTime) / workTime; - wait = 100 - (waitDiff * 100); - - long idleTime = current.getIdleTime() - previous.getIdleTime(); - float idleDiff = (float) (workTime - idleTime) / workTime; - idle = 100 - (idleDiff * 100); - - } - - - public Float getBusy() { - return busy; - } - - public Map getTags() { - return new HashMap<>(); - } - - public Map getFields() { - Map fields = new HashMap<>(); - fields.put("user", user); - fields.put("sys", sys); - fields.put("wait", wait); - fields.put("idle", idle); - fields.put("busy", busy); - return fields; - } - - -} diff --git a/plugins/os-linux/src/test/groovy/LinuxDiskTest.groovy b/plugins/os-linux/src/test/groovy/LinuxDiskTest.groovy deleted file mode 100644 index 5c9cfdf..0000000 --- a/plugins/os-linux/src/test/groovy/LinuxDiskTest.groovy +++ /dev/null @@ -1,43 +0,0 @@ -import sysmon.plugins.os_linux.LinuxDiskExtension -import sysmon.plugins.os_linux.LinuxDiskProcLine -import sysmon.plugins.os_linux.LinuxDiskStat -import spock.lang.Specification - -class LinuxDiskTest extends Specification { - - void "test proc file processing"() { - - setup: - def testFile = new File(getClass().getResource('/proc_diskstats1.txt').toURI()) - List lines = testFile.readLines("UTF-8") - - when: - LinuxDiskExtension extension = new LinuxDiskExtension() - LinuxDiskProcLine procLine = extension.processFileOutput(lines) - - then: - procLine.getTimeSpentOnIo() == 11145860l - } - - - void "test disk utilization"() { - - setup: - def testFile1 = new File(getClass().getResource('/proc_diskstats1.txt').toURI()) - def testFile2 = new File(getClass().getResource('/proc_diskstats2.txt').toURI()) - LinuxDiskExtension extension = new LinuxDiskExtension() - LinuxDiskProcLine procLine1 = extension.processFileOutput(testFile1.readLines()) - LinuxDiskProcLine procLine2 = extension.processFileOutput(testFile2.readLines()) - - when: - LinuxDiskStat diskStat = new LinuxDiskStat(procLine1, procLine2) - - then: - diskStat.getFields().get("iotime") == 180L - diskStat.getFields().get("writes") == 108371968L - diskStat.getFields().get("reads") == 69632L - diskStat.getFields().get("kbps") == 105900.0f - diskStat.getFields().get("tps") == 97.0f - - } -} diff --git a/plugins/os-linux/src/test/groovy/LinuxMemoryTest.groovy b/plugins/os-linux/src/test/groovy/LinuxMemoryTest.groovy deleted file mode 100644 index 1e59068..0000000 --- a/plugins/os-linux/src/test/groovy/LinuxMemoryTest.groovy +++ /dev/null @@ -1,28 +0,0 @@ -import sysmon.plugins.os_linux.LinuxMemoryExtension -import sysmon.plugins.os_linux.LinuxMemoryStat -import spock.lang.Specification - -class LinuxMemoryTest extends Specification { - - void "test Linux free output processing"() { - - setup: - def testFile = new File(getClass().getResource('/free.txt').toURI()) - List lines = testFile.readLines("UTF-8") - - when: - LinuxMemoryExtension extension = new LinuxMemoryExtension() - LinuxMemoryStat stats = extension.processCommandOutput(lines) - - then: - stats.getFields().get("total") == 16069172l - stats.getFields().get("used") == 5896832l - stats.getFields().get("free") == 4597860l - stats.getFields().get("shared") == 639780l - stats.getFields().get("buffers") == 5574480l - stats.getFields().get("available") == 9192992l - stats.getFields().get("usage") == 42.79113f - - } - -} diff --git a/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy b/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy index 9006970..3b1aad1 100644 --- a/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy +++ b/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy @@ -1,5 +1,4 @@ import spock.lang.Specification -import sysmon.plugins.os_linux.LinuxNetworkDevStat import sysmon.plugins.os_linux.LinuxNetworkExtension import sysmon.plugins.os_linux.LinuxNetworkSockStat @@ -27,44 +26,4 @@ class LinuxNetworkTest extends Specification { } - - void "test /proc/net/dev parsing"() { - - setup: - def testFile = new File(getClass().getResource('/proc_net_dev1.txt').toURI()) - List lines = testFile.readLines("UTF-8") - - when: - LinuxNetworkExtension extension = new LinuxNetworkExtension() - LinuxNetworkDevStat procLine = extension.processDevOutput(lines) - - then: - procLine.getRxBytes() == 663911036L - procLine.getRxPackets() == 525522L - procLine.getRxErrs() == 0L - procLine.getTxBytes() == 63084294L - procLine.getTxPackets() == 472869L - procLine.getTxErrs() == 0L - } - - /* - void "test dev utilization"() { - - setup: - def testFile1 = new File(getClass().getResource('/proc_net_dev1.txt').toURI()) - def testFile2 = new File(getClass().getResource('/proc_net_dev2.txt').toURI()) - LinuxNetworkExtension extension = new LinuxNetworkExtension() - LinuxNetworkDevStat procLine1 = extension.processDevOutput(testFile1.readLines()) - LinuxNetworkDevStat procLine2 = extension.processDevOutput(testFile2.readLines()) - - when: - LinuxNetworkDevStat networkDevStat = new LinuxNetworkDevStat(procLine1, procLine2) - - then: - networkDevStat.getFields().get("rxPackets") == 223L - networkDevStat.getFields().get("rxBytes") == 31501L - networkDevStat.getFields().get("txBytes") == 46460L - networkDevStat.getFields().get("txPackets") == 341L - }*/ - } diff --git a/plugins/os-linux/src/test/groovy/LinuxProcessorTest.groovy b/plugins/os-linux/src/test/groovy/LinuxProcessorTest.groovy deleted file mode 100644 index b37f2c2..0000000 --- a/plugins/os-linux/src/test/groovy/LinuxProcessorTest.groovy +++ /dev/null @@ -1,48 +0,0 @@ -import sysmon.plugins.os_linux.LinuxProcessorExtension -import sysmon.plugins.os_linux.LinuxProcessorProcLine -import sysmon.plugins.os_linux.LinuxProcessorStat -import spock.lang.Specification - -class LinuxProcessorTest extends Specification { - - void "test proc file processing"() { - - setup: - def testFile = new File(getClass().getResource('/proc_stats1.txt').toURI()) - List lines = testFile.readLines("UTF-8") - - when: - LinuxProcessorExtension extension = new LinuxProcessorExtension() - LinuxProcessorProcLine procLine = extension.processFileOutput(lines) - - then: - procLine.getSystemTime() == 4686l - procLine.getUserTime() == 27477l - procLine.getIdleTime() == 281276l - procLine.getIoWaitTime() == 252l - - } - - - void "test processor utilization"() { - - setup: - def testFile1 = new File(getClass().getResource('/proc_stats1.txt').toURI()) - def testFile2 = new File(getClass().getResource('/proc_stats2.txt').toURI()) - LinuxProcessorProcLine processorProcLine1 = new LinuxProcessorProcLine(testFile1.readLines().get(0)) - LinuxProcessorProcLine processorProcLine2 = new LinuxProcessorProcLine(testFile2.readLines().get(0)) - - when: - LinuxProcessorStat processorStat = new LinuxProcessorStat(processorProcLine1, processorProcLine2) - - then: - processorStat.getBusy() == 38.001614f - processorStat.getFields().get("user") == 35.6989f - processorStat.getFields().get("sys") == 2.2623215f - processorStat.getFields().get("idle") == 61.823322f - processorStat.getFields().get("wait") == 0.17505646f - - } - - -}