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 - - } + }*/ }