From 1a77edfe814a81ba972ed4fd21c0192348d0873b Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Tue, 14 Sep 2021 12:46:21 +0200 Subject: [PATCH] Cleanup. --- gradle.properties | 4 +-- .../plugins/os_aix/AixProcessorExtension.java | 3 +- .../plugins/os_aix/AixProcessorStat.java | 32 +++++++++---------- .../plugins/os_base/BaseDiskExtension.java | 3 +- .../plugins/os_base/BaseProcessExtension.java | 2 +- .../os_linux/LinuxNetstatExtension.java | 5 ++- .../plugins/os_linux/LinuxNetstatParser.java | 25 +++++++-------- .../os_linux/LinuxNetworkSockStat.java | 20 ++++++------ .../os_linux/LinuxSockstatExtension.java | 2 -- .../sysmon/server/ServerRouteBuilder.java | 2 +- 10 files changed, 45 insertions(+), 53 deletions(-) diff --git a/gradle.properties b/gradle.properties index d0d47a7..260fb63 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -version=0.0.11 +version=0.0.12 pf4jVersion=3.6.0 slf4jVersion=1.7.32 -camelVersion=3.11.1 +camelVersion=3.11.2 picocliVersion=4.6.1 oshiVersion=5.8.2 \ No newline at end of file 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 a594174..c847368 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 @@ -77,7 +77,7 @@ public class AixProcessorExtension implements MetricExtension { HashMap tagsMap = null; HashMap fieldsMap = null; - try (InputStream buf = PluginHelper.executeCommand("lparstat 5 1")) { + try (InputStream buf = PluginHelper.executeCommand("lparstat 3 1")) { AixProcessorStat processorStat = processCommandOutput(buf); tagsMap = processorStat.getTags(); fieldsMap = processorStat.getFields(); @@ -93,5 +93,4 @@ public class AixProcessorExtension implements MetricExtension { return new AixProcessorStat(input); } - } 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 085bb9f..488a424 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 @@ -17,13 +17,13 @@ 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 patternAixShared = Pattern.compile("^System configuration: type=(\\S+) mode=(\\S+) smt=(\\d+) lcpu=(\\d+) mem=(\\d+)MB psize=(\\d+) ent=(\\d+\\.?\\d*)"); + private static 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"); + private static 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*)"); + private static final Pattern patternLinux = Pattern.compile("^type=(\\S+) mode=(\\S+) smt=(\\d+) lcpu=(\\d+) mem=(\\d+) kB cpus=(\\d+) ent=(\\d+\\.?\\d*)"); private String type; @@ -144,18 +144,18 @@ public class AixProcessorStat { } public HashMap getFields() { - HashMap fields = new HashMap<>(); - fields.put("lcpu", lcpu); - fields.put("ent", ent); - fields.put("user", user); - fields.put("sys", sys); - fields.put("idle", idle); - fields.put("wait", wait); - fields.put("physc", physc); - fields.put("entc", entc); - fields.put("lbusy", lbusy); - fields.put("mode", mode); - fields.put("type", type); - return fields; + return new HashMap() {{ + put("lcpu", lcpu); + put("ent", ent); + put("user", user); + put("sys", sys); + put("idle", idle); + put("wait", wait); + put("physc", physc); + put("entc", entc); + put("lbusy", lbusy); + put("mode", mode); + put("type", type); + }}; } } 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 index 01ff3f4..8cb319a 100644 --- 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 @@ -72,7 +72,7 @@ public class BaseDiskExtension implements MetricExtension { for(HWDiskStore store : diskStores) { String name = store.getName(); - if (name.matches("hdisk[0-9]+") || name.matches("/dev/x?[sv]d[a-z]") || name.matches("/dev/nvme[0-9]n[0-9]")) { + if (name.matches("h?disk[0-9]+") || name.matches("/dev/x?[sv]d[a-z]") || name.matches("/dev/nvme[0-9]n[0-9]")) { HashMap tagsMap = new HashMap() {{ put("name", name); @@ -91,7 +91,6 @@ public class BaseDiskExtension implements MetricExtension { } return new MetricResult(name, measurementList); - } } \ No newline at end of file diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessExtension.java index cfdf84a..7b0d331 100644 --- a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessExtension.java +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessExtension.java @@ -93,7 +93,7 @@ public class BaseProcessExtension implements MetricExtension { if(!includeList.contains(name)) { continue; } - log.debug("pid: " + p.getProcessID() + ", name: " + name + ", virt: " + p.getVirtualSize() + " rss: " + p.getResidentSetSize()); + log.info("pid: " + p.getProcessID() + ", name: " + name + ", virt: " + p.getVirtualSize() + " rss: " + p.getResidentSetSize()); HashMap tagsMap = new HashMap() {{ put("pid", String.valueOf(p.getProcessID())); diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetstatExtension.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetstatExtension.java index 79b73e2..8fb4cd5 100644 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetstatExtension.java +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetstatExtension.java @@ -74,8 +74,8 @@ public class LinuxNetstatExtension implements MetricExtension { @Override public MetricResult getMetrics() throws Exception { - HashMap tagsMap = null; - HashMap fieldsMap = null; + HashMap tagsMap; + HashMap fieldsMap; try (InputStream inputStream = PluginHelper.executeCommand("netstat -s")) { LinuxNetstatParser parser = processCommandOutput(inputStream); @@ -83,7 +83,6 @@ public class LinuxNetstatExtension implements MetricExtension { fieldsMap = parser.getFields(); } - log.debug(fieldsMap.toString()); return new MetricResult(name, new Measurement(tagsMap, fieldsMap)); } diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetstatParser.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetstatParser.java index 35bf550..d01b1c1 100644 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetstatParser.java +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxNetstatParser.java @@ -144,20 +144,17 @@ public class LinuxNetstatParser { } public HashMap getFields() { - HashMap fields = new HashMap<>(); - fields.put("ip_forwarded", ipForwarded); - fields.put("ip_received", ipTotalPacketsReceived); - fields.put("ip_dropped", ipOutgoingPacketsDropped); - fields.put("ip_discarded", ipIncomingPacketsDiscarded); - - fields.put("tcp_connections", tcpConnectionsEstablished); - fields.put("tcp_pkts_recv", tcpSegmentsReceived); - fields.put("tcp_pkts_sent", tcpSegmentsSent); - - fields.put("udp_pkts_recv", udpPacketsReceived); - fields.put("udp_pkts_sent", udpPacketsSent); - - return fields; + return new HashMap() {{ + put("ip_forwarded", ipForwarded); + put("ip_received", ipTotalPacketsReceived); + put("ip_dropped", ipOutgoingPacketsDropped); + put("ip_discarded", ipIncomingPacketsDiscarded); + put("tcp_connections", tcpConnectionsEstablished); + put("tcp_pkts_recv", tcpSegmentsReceived); + put("tcp_pkts_sent", tcpSegmentsSent); + put("udp_pkts_recv", udpPacketsReceived); + put("udp_pkts_sent", udpPacketsSent); + }}; } private Long getFirstLong(String line) { 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 index 8f4c595..4d27d58 100644 --- 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 @@ -81,16 +81,16 @@ public class LinuxNetworkSockStat { public HashMap getFields() { - HashMap 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; + return new HashMap() {{ + put("sockets", sockets); + put("tcp_inuse", tcp_inuse); + put("tcp_alloc", tcp_alloc); + put("tcp_orphan", tcp_orphan); + put("tcp_mem", tcp_mem); + put("tcp_tw", tcp_tw); + put("udp_inuse", udp_inuse); + put("udp_mem", udp_mem); + }}; } } diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxSockstatExtension.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxSockstatExtension.java index 311a625..29acc79 100644 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxSockstatExtension.java +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxSockstatExtension.java @@ -72,9 +72,7 @@ public class LinuxSockstatExtension implements MetricExtension { HashMap tagsMap = sockStat.getTags(); HashMap fieldsMap = sockStat.getFields(); - log.debug(fieldsMap.toString()); return new MetricResult(name, new Measurement(tagsMap, fieldsMap)); - } protected LinuxNetworkSockStat processSockOutput(List inputLines) { diff --git a/server/src/main/java/sysmon/server/ServerRouteBuilder.java b/server/src/main/java/sysmon/server/ServerRouteBuilder.java index 149441f..46bcbeb 100644 --- a/server/src/main/java/sysmon/server/ServerRouteBuilder.java +++ b/server/src/main/java/sysmon/server/ServerRouteBuilder.java @@ -47,7 +47,7 @@ public class ServerRouteBuilder extends RouteBuilder { .process(new MetricResultToPointProcessor(dbname)) .toF("influxdb://ref.myInfluxConnection?batch=true") //&retentionPolicy=autogen .doCatch(Exception.class) - .log("Error storing metric to InfluxDB: ${exception}") + .log(LoggingLevel.WARN, "Error: ${exception}") .end(); }