From 9f8191d0e5622de336874192099d97449bed9672 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Mon, 24 May 2021 22:47:40 +0200 Subject: [PATCH 1/5] Initial work in Linux network metrics. --- client/build.gradle | 41 ++++---- .../plugins/os_linux/LinuxDiskProcLine.java | 2 +- .../plugins/os_linux/LinuxMemoryStat.java | 2 +- .../os_linux/LinuxNetworkDevProcLine.java | 90 +++++++++++++++++ .../plugins/os_linux/LinuxNetworkDevStat.java | 36 +++++++ .../os_linux/LinuxNetworkExtension.java | 78 +++++++++++++++ .../os_linux/LinuxNetworkSockStat.java | 97 +++++++++++++++++++ .../src/test/groovy/LinuxDiskTest.groovy | 6 +- .../src/test/groovy/LinuxNetworkTest.groovy | 74 ++++++++++++++ .../src/test/groovy/LinuxProcessorTest.groovy | 6 +- .../{diskstats1.txt => proc_diskstats1.txt} | 0 .../{diskstats2.txt => proc_diskstats2.txt} | 0 .../src/test/resources/proc_net_dev1.txt | 5 + .../src/test/resources/proc_net_dev2.txt | 5 + .../src/test/resources/proc_net_sockstat.txt | 6 ++ .../resources/{proc1.txt => proc_stats1.txt} | 0 .../resources/{proc2.txt => proc_stats2.txt} | 0 .../main/java/sysmon/shared/PluginHelper.java | 12 +++ 18 files changed, 431 insertions(+), 29 deletions(-) create mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevProcLine.java create mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevStat.java create mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkExtension.java create mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkSockStat.java create mode 100644 plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy rename plugins/os-linux/src/test/resources/{diskstats1.txt => proc_diskstats1.txt} (100%) rename plugins/os-linux/src/test/resources/{diskstats2.txt => proc_diskstats2.txt} (100%) create mode 100644 plugins/os-linux/src/test/resources/proc_net_dev1.txt create mode 100644 plugins/os-linux/src/test/resources/proc_net_dev2.txt create mode 100644 plugins/os-linux/src/test/resources/proc_net_sockstat.txt rename plugins/os-linux/src/test/resources/{proc1.txt => proc_stats1.txt} (100%) rename plugins/os-linux/src/test/resources/{proc2.txt => proc_stats2.txt} (100%) diff --git a/client/build.gradle b/client/build.gradle index 1614d3e..19f4750 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -44,6 +44,26 @@ tasks.named('test') { useJUnitPlatform() } +jar { + manifest { + attributes( + 'Created-By' : "Gradle ${gradle.gradleVersion}", + 'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}", + 'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})", + 'Build-User' : System.properties['user.name'], + 'Build-Version' : versioning.info.tag ?: (versioning.info.branch + "-" + versioning.info.build), + 'Build-Revision' : versioning.info.commit, + 'Build-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ").toString(), + ) + } +} + +shadowJar { + archiveBaseName.set(projectName) + archiveClassifier.set('') + archiveVersion.set('') + mergeServiceFiles() // Tell plugin to merge duplicate service files +} apply plugin: 'nebula.ospackage' ospackage { @@ -86,24 +106,3 @@ task buildRpmAix(type: Rpm) { packageName = "${projectName}-AIX" os = Os.AIX } - -jar { - manifest { - attributes( - 'Created-By' : "Gradle ${gradle.gradleVersion}", - 'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}", - 'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})", - 'Build-User' : System.properties['user.name'], - 'Build-Version' : versioning.info.tag ?: (versioning.info.branch + "-" + versioning.info.build), - 'Build-Revision' : versioning.info.commit, - 'Build-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ").toString(), - ) - } -} - -shadowJar { - archiveBaseName.set(projectName) - archiveClassifier.set('') - archiveVersion.set('') - mergeServiceFiles() // Tell plugin to merge duplicate service files -} \ 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 index 18d859d..551ea6a 100644 --- 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 @@ -70,7 +70,7 @@ public class LinuxDiskProcLine { //private Long timeSpentFlushing = 0L; // ms - LinuxDiskProcLine(List procLines) { + public LinuxDiskProcLine(List procLines) { for(String procLine : procLines) { 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 index c29026d..d1d863b 100644 --- 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 @@ -13,7 +13,7 @@ public class LinuxMemoryStat { Mem: 16069172 5896832 4597860 639780 5574480 9192992 Swap: 3985404 0 3985404 */ - private final Pattern pattern = Pattern.compile("^Mem:\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)"); + 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; diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevProcLine.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevProcLine.java new file mode 100644 index 0000000..0fa025f --- /dev/null +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevProcLine.java @@ -0,0 +1,90 @@ +package sysmon.plugins.os_linux; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class LinuxNetworkDevProcLine { + + private static final Logger log = LoggerFactory.getLogger(LinuxNetworkDevProcLine.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 LinuxNetworkDevProcLine(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; + } + +} 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 new file mode 100644 index 0000000..59425dc --- /dev/null +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevStat.java @@ -0,0 +1,36 @@ +package sysmon.plugins.os_linux; + +import java.util.HashMap; +import java.util.Map; + +public class LinuxNetworkDevStat { + + private final long rxBytes; + private final long rxPackets; + private final long txBytes; + private final long txPackets; + + + public LinuxNetworkDevStat(LinuxNetworkDevProcLine previous, LinuxNetworkDevProcLine current) { + rxBytes = current.getRxBytes() - previous.getRxBytes(); + rxPackets = current.getRxPackets() - previous.getRxPackets(); + txBytes = current.getTxBytes() - previous.getTxBytes(); + txPackets = current.getTxPackets() - previous.getTxPackets(); + } + + + 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 new file mode 100644 index 0000000..6b9c445 --- /dev/null +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkExtension.java @@ -0,0 +1,78 @@ +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 LinuxNetworkExtension implements MetricExtension { + + private static final Logger log = LoggerFactory.getLogger(LinuxNetworkExtension.class); + + @Override + public boolean isSupported() { + + if(!System.getProperty("os.name").toLowerCase().contains("linux")) { + log.warn("Requires Linux."); + return false; + } + + return true; + } + + @Override + public String getName() { + return "linux-network"; + } + + @Override + public String getProvides() { + return "network"; + } + + @Override + public String getDescription() { + return "Linux Network Metrics"; + } + + @Override + public MetricResult getMetrics() { + + // LinuxNetworkDevStat = 2 x reading from /proc/net/dev ? + LinuxNetworkDevProcLine proc1 = processDevOutput(PluginHelper.readFile("/proc/net/dev")); + try { + Thread.sleep(1 * 1000); // TODO: Configure sample collect time + } catch (InterruptedException e) { + log.warn("getMetrics() - sleep interrupted"); + return null; + } + LinuxNetworkDevProcLine proc2 = processDevOutput(PluginHelper.readFile("/proc/net/dev")); + + // LinuxNetworkSockStat = 1 x reading from /proc/net/sockstats + LinuxNetworkSockStat stat = processSockOutput(PluginHelper.readFile("/proc/net/sockstat")); + + + Map tagsMap = stat.getTags(); + Map fieldsMap = stat.getFields(); + + + return new MetricResult("network", new Measurement(tagsMap, fieldsMap)); + } + + protected LinuxNetworkSockStat processSockOutput(List inputLines) { + return new LinuxNetworkSockStat(inputLines); + } + + protected LinuxNetworkDevProcLine processDevOutput(List inputLines) { + return new LinuxNetworkDevProcLine(inputLines); + } + + +} diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkSockStat.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkSockStat.java new file mode 100644 index 0000000..91148fe --- /dev/null +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkSockStat.java @@ -0,0 +1,97 @@ +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 LinuxNetworkSockStat { + + private static final Logger log = LoggerFactory.getLogger(LinuxNetworkSockStat.class); + + private static final Pattern pattern1 = Pattern.compile("^sockets: used (\\d+)"); + private static final Pattern pattern2 = Pattern.compile("^TCP: inuse (\\d+) orphan (\\d+) tw (\\d+) alloc (\\d+) mem (\\d+)"); + private static final Pattern pattern3 = Pattern.compile("^UDP: inuse (\\d+) mem (\\d+)"); + + private long sockets; + private long tcp_inuse; + private long tcp_orphan; + private long tcp_tw; + private long tcp_alloc; + private long tcp_mem; + private long udp_inuse; + private long udp_mem; + + /* + 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 + */ + + + LinuxNetworkSockStat(List lines) { + + Matcher matcher; + for(String line : lines) { + String proto = line.substring(0, line.indexOf(':')); + + switch (proto) { + case "sockets": + matcher = pattern1.matcher(line); + if (matcher.matches() && matcher.groupCount() == 1) { + sockets = Long.parseLong(matcher.group(1)); + } + break; + + case "TCP": + matcher = pattern2.matcher(line); + if (matcher.matches() && matcher.groupCount() == 5) { + tcp_inuse = Long.parseLong(matcher.group(1)); + tcp_orphan = Long.parseLong(matcher.group(2)); + tcp_tw = Long.parseLong(matcher.group(3)); + tcp_alloc = Long.parseLong(matcher.group(4)); + tcp_mem = Long.parseLong(matcher.group(5)); + } + break; + + case "UDP": + matcher = pattern3.matcher(line); + if (matcher.matches() && matcher.groupCount() == 2) { + udp_inuse = Long.parseLong(matcher.group(1)); + udp_mem = Long.parseLong(matcher.group(2)); + } + break; + + } + + } + + } + + + public Map getTags() { + return new HashMap<>(); + } + + + public Map getFields() { + Map fields = new HashMap<>(); + fields.put("sockets", sockets); + fields.put("tcp_inuse", tcp_inuse); + fields.put("tcp_alloc", tcp_alloc); + fields.put("tcp_orphan", tcp_orphan); + fields.put("tcp_mem", tcp_mem); + fields.put("tcp_tw", tcp_tw); + fields.put("udp_inuse", udp_inuse); + fields.put("udp_mem", udp_mem); + return fields; + } + +} diff --git a/plugins/os-linux/src/test/groovy/LinuxDiskTest.groovy b/plugins/os-linux/src/test/groovy/LinuxDiskTest.groovy index f803ccd..5c9cfdf 100644 --- a/plugins/os-linux/src/test/groovy/LinuxDiskTest.groovy +++ b/plugins/os-linux/src/test/groovy/LinuxDiskTest.groovy @@ -8,7 +8,7 @@ class LinuxDiskTest extends Specification { void "test proc file processing"() { setup: - def testFile = new File(getClass().getResource('/diskstats1.txt').toURI()) + def testFile = new File(getClass().getResource('/proc_diskstats1.txt').toURI()) List lines = testFile.readLines("UTF-8") when: @@ -23,8 +23,8 @@ class LinuxDiskTest extends Specification { void "test disk utilization"() { setup: - def testFile1 = new File(getClass().getResource('/diskstats1.txt').toURI()) - def testFile2 = new File(getClass().getResource('/diskstats2.txt').toURI()) + 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()) diff --git a/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy b/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy new file mode 100644 index 0000000..3274dff --- /dev/null +++ b/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy @@ -0,0 +1,74 @@ +import spock.lang.Specification +import sysmon.plugins.os_linux.LinuxDiskExtension +import sysmon.plugins.os_linux.LinuxDiskProcLine +import sysmon.plugins.os_linux.LinuxDiskStat +import sysmon.plugins.os_linux.LinuxNetworkDevProcLine +import sysmon.plugins.os_linux.LinuxNetworkDevStat +import sysmon.plugins.os_linux.LinuxNetworkExtension +import sysmon.plugins.os_linux.LinuxNetworkSockStat + +class LinuxNetworkTest extends Specification { + + void "test /proc/net/sockstat parsing"() { + + setup: + def testFile = new File(getClass().getResource('/proc_net_sockstat.txt').toURI()) + List lines = testFile.readLines("UTF-8") + + when: + LinuxNetworkExtension extension = new LinuxNetworkExtension() + LinuxNetworkSockStat stats = extension.processSockOutput(lines) + + then: + stats.getFields().get("sockets") == 1238L + stats.getFields().get("tcp_inuse") == 52L + stats.getFields().get("tcp_orphan") == 0L + stats.getFields().get("tcp_alloc") == 55L + stats.getFields().get("tcp_mem") == 7l + stats.getFields().get("tcp_tw") == 18L + stats.getFields().get("udp_inuse") == 11L + stats.getFields().get("udp_mem") == 10L + + } + + + 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() + LinuxNetworkDevProcLine 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() + LinuxNetworkDevProcLine procLine1 = extension.processDevOutput(testFile1.readLines()) + LinuxNetworkDevProcLine 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 index 9577a31..b37f2c2 100644 --- a/plugins/os-linux/src/test/groovy/LinuxProcessorTest.groovy +++ b/plugins/os-linux/src/test/groovy/LinuxProcessorTest.groovy @@ -8,7 +8,7 @@ class LinuxProcessorTest extends Specification { void "test proc file processing"() { setup: - def testFile = new File(getClass().getResource('/proc1.txt').toURI()) + def testFile = new File(getClass().getResource('/proc_stats1.txt').toURI()) List lines = testFile.readLines("UTF-8") when: @@ -27,8 +27,8 @@ class LinuxProcessorTest extends Specification { void "test processor utilization"() { setup: - def testFile1 = new File(getClass().getResource('/proc1.txt').toURI()) - def testFile2 = new File(getClass().getResource('/proc2.txt').toURI()) + 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)) diff --git a/plugins/os-linux/src/test/resources/diskstats1.txt b/plugins/os-linux/src/test/resources/proc_diskstats1.txt similarity index 100% rename from plugins/os-linux/src/test/resources/diskstats1.txt rename to plugins/os-linux/src/test/resources/proc_diskstats1.txt diff --git a/plugins/os-linux/src/test/resources/diskstats2.txt b/plugins/os-linux/src/test/resources/proc_diskstats2.txt similarity index 100% rename from plugins/os-linux/src/test/resources/diskstats2.txt rename to plugins/os-linux/src/test/resources/proc_diskstats2.txt diff --git a/plugins/os-linux/src/test/resources/proc_net_dev1.txt b/plugins/os-linux/src/test/resources/proc_net_dev1.txt new file mode 100644 index 0000000..9f57a9b --- /dev/null +++ b/plugins/os-linux/src/test/resources/proc_net_dev1.txt @@ -0,0 +1,5 @@ +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 diff --git a/plugins/os-linux/src/test/resources/proc_net_dev2.txt b/plugins/os-linux/src/test/resources/proc_net_dev2.txt new file mode 100644 index 0000000..3f3fb11 --- /dev/null +++ b/plugins/os-linux/src/test/resources/proc_net_dev2.txt @@ -0,0 +1,5 @@ +Inter-| Receive | Transmit + face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed + env2: 657034787 483864 0 0 0 0 0 0 55454936 431316 0 0 0 0 0 0 + env3: 6907750 41881 0 0 0 0 0 0 7675818 41894 0 0 0 0 0 0 + lo: 3098805 14393 0 0 0 0 0 0 3098805 14393 0 0 0 0 0 0 diff --git a/plugins/os-linux/src/test/resources/proc_net_sockstat.txt b/plugins/os-linux/src/test/resources/proc_net_sockstat.txt new file mode 100644 index 0000000..f0c0afc --- /dev/null +++ b/plugins/os-linux/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/proc1.txt b/plugins/os-linux/src/test/resources/proc_stats1.txt similarity index 100% rename from plugins/os-linux/src/test/resources/proc1.txt rename to plugins/os-linux/src/test/resources/proc_stats1.txt diff --git a/plugins/os-linux/src/test/resources/proc2.txt b/plugins/os-linux/src/test/resources/proc_stats2.txt similarity index 100% rename from plugins/os-linux/src/test/resources/proc2.txt rename to plugins/os-linux/src/test/resources/proc_stats2.txt diff --git a/shared/src/main/java/sysmon/shared/PluginHelper.java b/shared/src/main/java/sysmon/shared/PluginHelper.java index 984fc3f..e3f2811 100644 --- a/shared/src/main/java/sysmon/shared/PluginHelper.java +++ b/shared/src/main/java/sysmon/shared/PluginHelper.java @@ -7,6 +7,7 @@ import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; @@ -68,4 +69,15 @@ public class PluginHelper { .anyMatch(path -> Files.exists(path.resolve(cmd))); } + + public static List readFile(String filename) { + List allLines = new ArrayList<>(); + try { + allLines = Files.readAllLines(Paths.get(filename), StandardCharsets.UTF_8); + } catch (IOException e) { + log.error(e.getMessage()); + } + return allLines; + } + } From 5c18eb58d730ef2049fddb36d06aac0e4cb280eb Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Thu, 27 May 2021 22:43:56 +0200 Subject: [PATCH 2/5] Initial work in progress on plugin deps and uberjar. --- .../sysmon/client/ClientRouteBuilder.java | 2 ++ plugins/build.gradle | 31 +++++++++++++++++-- plugins/os-aix/build.gradle | 2 ++ plugins/os-ibmi/README.md | 7 +++++ plugins/os-ibmi/build.gradle | 7 +++++ plugins/os-ibmi/gradle.properties | 6 ++++ .../sysmon/plugins/os_ibmi/IbmIPlugin.java | 18 +++++++++++ plugins/os-linux/build.gradle | 2 ++ 8 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 plugins/os-ibmi/README.md create mode 100644 plugins/os-ibmi/build.gradle create mode 100644 plugins/os-ibmi/gradle.properties create mode 100644 plugins/os-ibmi/src/main/java/sysmon/plugins/os_ibmi/IbmIPlugin.java diff --git a/client/src/main/java/sysmon/client/ClientRouteBuilder.java b/client/src/main/java/sysmon/client/ClientRouteBuilder.java index b339cef..bf9db77 100644 --- a/client/src/main/java/sysmon/client/ClientRouteBuilder.java +++ b/client/src/main/java/sysmon/client/ClientRouteBuilder.java @@ -56,6 +56,8 @@ public class ClientRouteBuilder extends RouteBuilder { .stop() .otherwise() .to("seda:metrics"); + } else { + log.info(">>> Skipping extension: " + ext.getDescription()); } } diff --git a/plugins/build.gradle b/plugins/build.gradle index 7dd8719..8e5e287 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -15,13 +15,14 @@ subprojects { testImplementation project(':shared') implementation project(':shared') + implementation "org.slf4j:slf4j-api:${slf4jVersion}" implementation(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") { exclude(group: "org.slf4j") } annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") - implementation "org.slf4j:slf4j-api:${slf4jVersion}" } +/* jar { manifest { attributes( @@ -32,14 +33,38 @@ subprojects { 'Plugin-Description': "${pluginDescription}" ) } + + }*/ + + task uberJar(type: Jar) { + from sourceSets.main.output + dependsOn configurations.runtimeClasspath + from { + configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { + zipTree(it).matching { + exclude 'org/slf4j/**' + } + } + } + + manifest { + attributes( + 'Plugin-Id' : "${pluginId}", + 'Plugin-Class' : "${pluginClass}", + 'Plugin-Version' : "${pluginVersion}", + 'Plugin-Provider' : "${pluginProvider}", + 'Plugin-Description': "${pluginDescription}" + ) + } } - task copyJar(type: Copy, dependsOn:[jar]) { - from jar // here it automatically reads jar file produced from jar task + task copyJar(type: Copy, dependsOn: ['uberJar']) { + from jar into "../output/" } tasks.build.dependsOn { + uberJar copyJar } diff --git a/plugins/os-aix/build.gradle b/plugins/os-aix/build.gradle index e69de29..d18c3d3 100644 --- a/plugins/os-aix/build.gradle +++ b/plugins/os-aix/build.gradle @@ -0,0 +1,2 @@ +plugins { +} \ No newline at end of file diff --git a/plugins/os-ibmi/README.md b/plugins/os-ibmi/README.md new file mode 100644 index 0000000..7931bd5 --- /dev/null +++ b/plugins/os-ibmi/README.md @@ -0,0 +1,7 @@ +# IBM i Plugin + +## Processor Extension + +## Memory Extension + +## Disk Extension diff --git a/plugins/os-ibmi/build.gradle b/plugins/os-ibmi/build.gradle new file mode 100644 index 0000000..f3624d7 --- /dev/null +++ b/plugins/os-ibmi/build.gradle @@ -0,0 +1,7 @@ +plugins { +} + +dependencies { + // https://mvnrepository.com/artifact/net.sf.jt400/jt400 + implementation group: 'net.sf.jt400', name: 'jt400', version: '10.6' +} \ No newline at end of file diff --git a/plugins/os-ibmi/gradle.properties b/plugins/os-ibmi/gradle.properties new file mode 100644 index 0000000..cf7297d --- /dev/null +++ b/plugins/os-ibmi/gradle.properties @@ -0,0 +1,6 @@ +pluginId=sysmon-ibmi +pluginClass=sysmon.plugins.os_ibmi.IbmIPlugin +pluginVersion=0.0.1 +pluginProvider=System Monitor +pluginDependencies= +pluginDescription=Collects IBM-i OS metrics. \ No newline at end of file diff --git a/plugins/os-ibmi/src/main/java/sysmon/plugins/os_ibmi/IbmIPlugin.java b/plugins/os-ibmi/src/main/java/sysmon/plugins/os_ibmi/IbmIPlugin.java new file mode 100644 index 0000000..c622954 --- /dev/null +++ b/plugins/os-ibmi/src/main/java/sysmon/plugins/os_ibmi/IbmIPlugin.java @@ -0,0 +1,18 @@ +package sysmon.plugins.os_ibmi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.pf4j.Plugin; +import org.pf4j.PluginWrapper; + +public class IbmIPlugin extends Plugin { + + private static final Logger log = LoggerFactory.getLogger(IbmIPlugin.class); + + public IbmIPlugin(PluginWrapper wrapper) { + super(wrapper); + } + +} + + diff --git a/plugins/os-linux/build.gradle b/plugins/os-linux/build.gradle index e69de29..d18c3d3 100644 --- a/plugins/os-linux/build.gradle +++ b/plugins/os-linux/build.gradle @@ -0,0 +1,2 @@ +plugins { +} \ No newline at end of file From e7560831e828a3fb8c91f18e00a364d52c9c5bd2 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Fri, 28 May 2021 08:07:04 +0200 Subject: [PATCH 3/5] More work on Linux network metrics. --- plugins/build.gradle | 13 ++- .../plugins/os_aix/AixDiskExtension.java | 24 +++++ .../plugins/os_linux/LinuxDiskProcLine.java | 34 +++---- .../os_linux/LinuxNetworkDevProcLine.java | 90 ------------------- .../plugins/os_linux/LinuxNetworkDevStat.java | 89 +++++++++++++++--- .../os_linux/LinuxNetworkExtension.java | 25 ++---- .../src/test/groovy/LinuxNetworkTest.groovy | 14 ++- 7 files changed, 143 insertions(+), 146 deletions(-) delete mode 100644 plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevProcLine.java diff --git a/plugins/build.gradle b/plugins/build.gradle index 7dd8719..6a48326 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -4,8 +4,8 @@ plugins { id "nebula.ospackage" version "8.5.6" } - subprojects { + apply plugin: 'java' apply plugin: 'groovy' @@ -20,6 +20,7 @@ subprojects { } annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") implementation "org.slf4j:slf4j-api:${slf4jVersion}" + } jar { @@ -32,9 +33,17 @@ subprojects { 'Plugin-Description': "${pluginDescription}" ) } + + } - task copyJar(type: Copy, dependsOn:[jar]) { + task fatJar(type: Jar) { + duplicatesStrategy(DuplicatesStrategy.INCLUDE) + from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } + with jar + } + + task copyJar(type: Copy, dependsOn:[fatJar]) { from jar // here it automatically reads jar file produced from jar task into "../output/" } 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 index 519fc0a..c77bdb2 100644 --- 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 @@ -3,6 +3,8 @@ 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; @@ -11,11 +13,15 @@ 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() { @@ -32,6 +38,15 @@ public class AixDiskExtension implements MetricExtension { return true; } + + public AixDiskExtension() { + + systemInfo = new SystemInfo(); + hardwareAbstractionLayer = systemInfo.getHardware(); + + } + + @Override public String getName() { return "aix-disk"; @@ -50,6 +65,15 @@ public class AixDiskExtension implements MetricExtension { @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); 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 index 551ea6a..c3b8dff 100644 --- 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 @@ -49,25 +49,25 @@ public class LinuxDiskProcLine { == ===================================== */ - private Long readsCompleted = 0L; // successfully - //private Long readsMerged = 0L; - private Long sectorsRead = 0L; // 512 bytes pr. sector - private Long timeSpentReading = 0L; // ms - private Long writesCompleted = 0L; // successfully - //private Long writesMerged = 0L; - private Long sectorsWritten = 0L; // 512 bytes pr. sector - private Long timeSpentWriting = 0L; // ms - //private Long ioInProgress = 0L; - private Long timeSpentOnIo = 0L; // ms - //private Long timeSpentOnIoWeighted = 0L; + 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 = 0L; // successfully - //private Long discardsMerged = 0L; - //private Long sectorsDiscarded = 0L; // 512 bytes pr. sector - //private Long timeSpentDiscarding = 0L; // ms + //private long discardsCompleted; // successfully + //private long discardsMerged; + //private long sectorsDiscarded; // 512 bytes pr. sector + //private long timeSpentDiscarding; // ms - //private Long flushRequestsCompleted = 0L; - //private Long timeSpentFlushing = 0L; // ms + //private long flushRequestsCompleted; + //private long timeSpentFlushing; // ms public LinuxDiskProcLine(List procLines) { diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevProcLine.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevProcLine.java deleted file mode 100644 index 0fa025f..0000000 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetworkDevProcLine.java +++ /dev/null @@ -1,90 +0,0 @@ -package sysmon.plugins.os_linux; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class LinuxNetworkDevProcLine { - - private static final Logger log = LoggerFactory.getLogger(LinuxNetworkDevProcLine.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 LinuxNetworkDevProcLine(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; - } - -} 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 index 59425dc..bdae2e6 100644 --- 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 @@ -1,21 +1,91 @@ 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 final long rxBytes; - private final long rxPackets; - private final long txBytes; - private final long txPackets; + 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 LinuxNetworkDevStat(LinuxNetworkDevProcLine previous, LinuxNetworkDevProcLine current) { - rxBytes = current.getRxBytes() - previous.getRxBytes(); - rxPackets = current.getRxPackets() - previous.getRxPackets(); - txBytes = current.getTxBytes() - previous.getTxBytes(); - txPackets = current.getTxPackets() - previous.getTxPackets(); + 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; } @@ -32,5 +102,4 @@ public class LinuxNetworkDevStat { 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 6b9c445..1d1b710 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 @@ -45,23 +45,12 @@ public class LinuxNetworkExtension implements MetricExtension { @Override public MetricResult getMetrics() { - // LinuxNetworkDevStat = 2 x reading from /proc/net/dev ? - LinuxNetworkDevProcLine proc1 = processDevOutput(PluginHelper.readFile("/proc/net/dev")); - try { - Thread.sleep(1 * 1000); // TODO: Configure sample collect time - } catch (InterruptedException e) { - log.warn("getMetrics() - sleep interrupted"); - return null; - } - LinuxNetworkDevProcLine proc2 = processDevOutput(PluginHelper.readFile("/proc/net/dev")); - - // LinuxNetworkSockStat = 1 x reading from /proc/net/sockstats - LinuxNetworkSockStat stat = processSockOutput(PluginHelper.readFile("/proc/net/sockstat")); - - - Map tagsMap = stat.getTags(); - Map fieldsMap = stat.getFields(); + 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)); } @@ -70,8 +59,8 @@ public class LinuxNetworkExtension implements MetricExtension { return new LinuxNetworkSockStat(inputLines); } - protected LinuxNetworkDevProcLine processDevOutput(List inputLines) { - return new LinuxNetworkDevProcLine(inputLines); + protected LinuxNetworkDevStat processDevOutput(List inputLines) { + return new LinuxNetworkDevStat(inputLines); } diff --git a/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy b/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy index 3274dff..9006970 100644 --- a/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy +++ b/plugins/os-linux/src/test/groovy/LinuxNetworkTest.groovy @@ -1,8 +1,4 @@ import spock.lang.Specification -import sysmon.plugins.os_linux.LinuxDiskExtension -import sysmon.plugins.os_linux.LinuxDiskProcLine -import sysmon.plugins.os_linux.LinuxDiskStat -import sysmon.plugins.os_linux.LinuxNetworkDevProcLine import sysmon.plugins.os_linux.LinuxNetworkDevStat import sysmon.plugins.os_linux.LinuxNetworkExtension import sysmon.plugins.os_linux.LinuxNetworkSockStat @@ -40,7 +36,7 @@ class LinuxNetworkTest extends Specification { when: LinuxNetworkExtension extension = new LinuxNetworkExtension() - LinuxNetworkDevProcLine procLine = extension.processDevOutput(lines) + LinuxNetworkDevStat procLine = extension.processDevOutput(lines) then: procLine.getRxBytes() == 663911036L @@ -51,14 +47,15 @@ class LinuxNetworkTest extends Specification { 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() - LinuxNetworkDevProcLine procLine1 = extension.processDevOutput(testFile1.readLines()) - LinuxNetworkDevProcLine procLine2 = extension.processDevOutput(testFile2.readLines()) + LinuxNetworkDevStat procLine1 = extension.processDevOutput(testFile1.readLines()) + LinuxNetworkDevStat procLine2 = extension.processDevOutput(testFile2.readLines()) when: LinuxNetworkDevStat networkDevStat = new LinuxNetworkDevStat(procLine1, procLine2) @@ -68,7 +65,6 @@ class LinuxNetworkTest extends Specification { networkDevStat.getFields().get("rxBytes") == 31501L networkDevStat.getFields().get("txBytes") == 46460L networkDevStat.getFields().get("txPackets") == 341L - - } + }*/ } From 95554c503e0734e99a8a39a1219721ee728487e2 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Fri, 28 May 2021 08:08:58 +0200 Subject: [PATCH 4/5] oshi dep --- plugins/os-aix/build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/os-aix/build.gradle b/plugins/os-aix/build.gradle index e69de29..93beca3 100644 --- a/plugins/os-aix/build.gradle +++ b/plugins/os-aix/build.gradle @@ -0,0 +1,8 @@ +dependencies { + + implementation(group: 'com.github.oshi', name: 'oshi-core', version: "5.7.3") { + exclude(group: "org.slf4j") + } + +} + From ea4cbf3f6aae80943c2271c501d9d9bcb07776c0 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Fri, 28 May 2021 08:49:42 +0200 Subject: [PATCH 5/5] More work on Linux network metrics. --- plugins/build.gradle | 5 +++++ plugins/os-aix/build.gradle | 2 -- .../main/java/sysmon/plugins/os_aix/AixDiskExtension.java | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index 8e5e287..2611a36 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -42,7 +42,12 @@ subprojects { from { configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it).matching { + exclude 'org/pf4j/**' exclude 'org/slf4j/**' + exclude 'sysmon/shared/**' + exclude 'META-INF/AL2.0' + exclude 'META-INF/LGPL2.1' + exclude 'META-INF/LICENSE' } } } diff --git a/plugins/os-aix/build.gradle b/plugins/os-aix/build.gradle index 93beca3..a76f366 100644 --- a/plugins/os-aix/build.gradle +++ b/plugins/os-aix/build.gradle @@ -1,8 +1,6 @@ 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 index c77bdb2..a986d93 100644 --- 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 @@ -40,10 +40,9 @@ public class AixDiskExtension implements MetricExtension { public AixDiskExtension() { - systemInfo = new SystemInfo(); hardwareAbstractionLayer = systemInfo.getHardware(); - + log.warn(systemInfo.getOperatingSystem().toString()); }