diff --git a/doc/AIX.md b/doc/AIX.md new file mode 100644 index 0000000..c32f79d --- /dev/null +++ b/doc/AIX.md @@ -0,0 +1,13 @@ +# AIX Notes + +## Installation + +```shell +rpm -i --ignoreos sysmon-client.rpm sysmon-plugins.rpm +``` + +## Run automatically at boot + +```shell +mkitab 'sysmon:2:respawn:env JAVA_HOME=/usr/java8_64 /opt/sysmon/client/bin/client -s http://10.20.30.40:9925/metrics >/tmp/sysmon.log 2>&1' +``` diff --git a/doc/sysmon-client.service b/doc/sysmon-client.service new file mode 100644 index 0000000..33d62ce --- /dev/null +++ b/doc/sysmon-client.service @@ -0,0 +1,10 @@ +[Unit] +Description=Sysmon Client Service + +[Service] +TimeoutStartSec=0 +Restart=always +ExecStart=/opt/sysmon/client/bin/client -s http://10.20.30.40:9925/metrics + +[Install] +WantedBy=default.target diff --git a/doc/sysmon-server.service b/doc/sysmon-server.service new file mode 100644 index 0000000..54e3c47 --- /dev/null +++ b/doc/sysmon-server.service @@ -0,0 +1,10 @@ +[Unit] +Description=Sysmon Server Service + +[Service] +TimeoutStartSec=0 +Restart=always +ExecStart=/opt/sysmon/server/bin/server + +[Install] +WantedBy=default.target diff --git a/doc/systemd.md b/doc/systemd.md new file mode 100644 index 0000000..29b5fe2 --- /dev/null +++ b/doc/systemd.md @@ -0,0 +1,12 @@ +# SystemD Notes + +Edit the *sysmon-client.service* file and change the sysmon-server URL accordingly to your environment. + +Setup as systemd service to start automatically at boot: + +```shell +cp sysmon-client.service /etc/systemd/system/ +systemctl daemon-reload +systemctl enable sysmon-client +systemctl restart sysmon-client +``` \ No newline at end of file diff --git a/plugins/build.gradle b/plugins/build.gradle index e135ccd..a55ce2d 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -12,6 +12,7 @@ subprojects { dependencies { testImplementation 'org.spockframework:spock-core:2.0-groovy-3.0' testImplementation "org.slf4j:slf4j-api:${slf4jVersion}" + testImplementation "org.slf4j:slf4j-simple:${slf4jVersion}" testImplementation project(':shared') implementation project(':shared') diff --git a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorStat.java b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorStat.java index df0e575..f545916 100644 --- a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorStat.java +++ b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorStat.java @@ -1,5 +1,8 @@ package sysmon.plugins.os_aix; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -8,8 +11,13 @@ import java.util.regex.Pattern; public class AixProcessorStat { + private static final Logger log = LoggerFactory.getLogger(AixProcessorStat.class); + // System configuration: type=Shared mode=Uncapped smt=8 lcpu=8 mem=4096MB psize=19 ent=0.50 - private final Pattern patternAix = Pattern.compile("^System configuration: type=(\\S+) mode=(\\S+) smt=(\\d+) lcpu=(\\d+) mem=(\\d+)MB psize=(\\d+) ent=(\\d+\\.?\\d*)"); + private final Pattern patternAixShared = Pattern.compile("^System configuration: type=(\\S+) mode=(\\S+) smt=(\\d+) lcpu=(\\d+) mem=(\\d+)MB psize=(\\d+) ent=(\\d+\\.?\\d*)"); + + // System configuration: type=Dedicated mode=Donating smt=8 lcpu=16 mem=4096MB + private final Pattern patternAixDedicated = Pattern.compile("^System configuration: type=(\\S+) mode=(\\S+) smt=(\\d+) lcpu=(\\d+) mem=(\\d+)MB"); // type=Shared mode=Uncapped smt=8 lcpu=4 mem=4101120 kB cpus=24 ent=4.00 private final Pattern patternLinux = Pattern.compile("^type=(\\S+) mode=(\\S+) smt=(\\d+) lcpu=(\\d+) mem=(\\d+) kB cpus=(\\d+) ent=(\\d+\\.?\\d*)"); @@ -36,7 +44,7 @@ public class AixProcessorStat { for (String line : lines) { if (line.startsWith("System configuration:")) { - Matcher matcher = patternAix.matcher(line); + Matcher matcher = patternAixShared.matcher(line); if (matcher.find() && matcher.groupCount() == 7) { type = matcher.group(1); mode = matcher.group(2); @@ -45,6 +53,13 @@ public class AixProcessorStat { psize = Integer.parseInt(matcher.group(5)); ent = Float.parseFloat(matcher.group(7)); } + matcher = patternAixDedicated.matcher(line); + if (matcher.find() && matcher.groupCount() == 5) { + type = matcher.group(1); + mode = matcher.group(2); + smt = Integer.parseInt(matcher.group(3)); + lcpu = Integer.parseInt(matcher.group(4)); + } } if (line.startsWith("type=")) { @@ -64,7 +79,8 @@ public class AixProcessorStat { String lparstat = lines.get(lines.size() -1); String[] splitStr = lparstat.trim().split("\\s+"); - if(splitStr.length < 9) { + if(type.equalsIgnoreCase("shared") && splitStr.length < 9 || + type.equalsIgnoreCase("dedicated") && splitStr.length < 8) { throw new UnsupportedOperationException("lparstat string error: " + lparstat); } @@ -73,9 +89,13 @@ public class AixProcessorStat { this.wait = Float.parseFloat(splitStr[2]); this.idle = Float.parseFloat(splitStr[3]); this.physc = Float.parseFloat(splitStr[4]); - this.entc = Float.parseFloat(splitStr[5]); - this.lbusy = Float.parseFloat(splitStr[6]); - + if(type.equalsIgnoreCase("shared")) { + this.entc = Float.parseFloat(splitStr[5]); + this.lbusy = Float.parseFloat(splitStr[6]); + } else { + this.entc = 0f; + this.lbusy = 0f; + } } public float getUser() { diff --git a/plugins/os-aix/src/test/groovy/AixProcessorTest.groovy b/plugins/os-aix/src/test/groovy/AixProcessorTest.groovy index dd481b1..c462e84 100644 --- a/plugins/os-aix/src/test/groovy/AixProcessorTest.groovy +++ b/plugins/os-aix/src/test/groovy/AixProcessorTest.groovy @@ -4,10 +4,10 @@ import spock.lang.Specification class AixProcessorTest extends Specification { - void "test AIX lparstat output processing"() { + void "test AIX lparstat shared output processing"() { setup: - def testFile = new File(getClass().getResource('/lparstat-aix.txt').toURI()) + def testFile = new File(getClass().getResource('/lparstat-aix-shared.txt').toURI()) List lines = testFile.readLines("UTF-8") when: @@ -20,9 +20,29 @@ class AixProcessorTest extends Specification { stats.getWait() == 0.0f stats.getIdle() == 13.0f stats.getFields().get("ent") == 0.50f + stats.getFields().get("type") == "Shared" } + void "test AIX lparstat dedicated output processing"() { + + setup: + def testFile = new File(getClass().getResource('/lparstat-aix-dedicated.txt').toURI()) + List lines = testFile.readLines("UTF-8") + + when: + AixProcessorExtension extension = new AixProcessorExtension() + AixProcessorStat stats = extension.processCommandOutput(lines) + + then: + stats.getUser() == 0.1f + stats.getSys() == 0.2f + stats.getWait() == 0.0f + stats.getIdle() == 99.7f + stats.getFields().get("physc") == 0.07f + stats.getFields().get("type") == "Dedicated" + + } void "test Linux lparstat output processing"() { @@ -45,4 +65,6 @@ class AixProcessorTest extends Specification { } + // java.lang.UnsupportedOperationException: lparstat string error: 2.2 1.2 0.0 96.6 0.28 1100 132 24.23 + } diff --git a/plugins/os-aix/src/test/resources/lparstat-aix-dedicated.txt b/plugins/os-aix/src/test/resources/lparstat-aix-dedicated.txt new file mode 100644 index 0000000..ac10634 --- /dev/null +++ b/plugins/os-aix/src/test/resources/lparstat-aix-dedicated.txt @@ -0,0 +1,6 @@ + +System configuration: type=Dedicated mode=Donating smt=8 lcpu=16 mem=4096MB + +%user %sys %wait %idle physc vcsw %nsp %utcyc +----- ----- ------ ------ ----- ----- ----- ------ + 0.1 0.2 0.0 99.7 0.07 1014627468 132 24.21 \ No newline at end of file diff --git a/plugins/os-aix/src/test/resources/lparstat-aix.txt b/plugins/os-aix/src/test/resources/lparstat-aix-shared.txt similarity index 100% rename from plugins/os-aix/src/test/resources/lparstat-aix.txt rename to plugins/os-aix/src/test/resources/lparstat-aix-shared.txt diff --git a/plugins/os-ibmi/src/main/java/sysmon/plugins/os_ibmi/TestExtension.java b/plugins/os-ibmi/src/main/java/sysmon/plugins/os_ibmi/TestExtension.java new file mode 100644 index 0000000..52e0d94 --- /dev/null +++ b/plugins/os-ibmi/src/main/java/sysmon/plugins/os_ibmi/TestExtension.java @@ -0,0 +1,44 @@ +package sysmon.plugins.os_ibmi; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import sysmon.shared.MetricExtension; +import sysmon.shared.MetricResult; + +public class TestExtension implements MetricExtension { + + private static final Logger log = LoggerFactory.getLogger(TestExtension.class); + + + @Override + public boolean isSupported() { + + String osArch = System.getProperty("os.arch").toLowerCase(); + String osName = System.getProperty("os.name").toLowerCase(); + + System.err.println("OS Arch: " + osArch); + System.err.println("OS Name: " + osName); + + return true; + } + + @Override + public String getName() { + return "ibmi-test"; + } + + @Override + public String getProvides() { + return "test"; + } + + @Override + public String getDescription() { + return "IBM i Test Extension"; + } + + @Override + public MetricResult getMetrics() { + return null; + } +}