From cca1c099df9f0bfc0cc72f652ead072312bb311a Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Mon, 17 May 2021 15:05:35 +0200 Subject: [PATCH] Fix 500 status code when POST'ing to server. Various improvements to plugins. --- client/build.gradle | 1 + .../org/sysmon/client/ClientRouteBuilder.java | 2 +- plugins/sysmon-aix/README.md | 44 +++++++++++++++++++ .../plugins/sysmon_aix/AixDiskExtension.java | 2 +- .../sysmon_aix/AixMemoryExtension.java | 3 +- .../plugins/sysmon_aix/AixMemoryStat.java | 16 +++---- .../src/test/groovy/AixMemoryTest.groovy | 14 +++--- .../sysmon-aix/src/test/resources/svmon.txt | 13 +++--- plugins/sysmon-linux/README.md | 36 +++++++++++++++ .../sysmon_linux/LinuxDiskExtension.java | 1 - .../server/MetricResultToPointProcessor.java | 2 +- .../org/sysmon/server/ServerRouteBuilder.java | 3 ++ 12 files changed, 109 insertions(+), 28 deletions(-) create mode 100644 plugins/sysmon-aix/README.md create mode 100644 plugins/sysmon-linux/README.md diff --git a/client/build.gradle b/client/build.gradle index bd311ab..351a82f 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -17,6 +17,7 @@ dependencies { annotationProcessor "info.picocli:picocli-codegen:${picocliVersion}" implementation "info.picocli:picocli:${picocliVersion}" + implementation 'org.tomlj:tomlj:1.0.0' implementation group: 'org.apache.camel', name: 'camel-core', version: camelVersion implementation group: 'org.apache.camel', name: 'camel-main', version: camelVersion diff --git a/client/src/main/java/org/sysmon/client/ClientRouteBuilder.java b/client/src/main/java/org/sysmon/client/ClientRouteBuilder.java index 0a29ace..93deaad 100644 --- a/client/src/main/java/org/sysmon/client/ClientRouteBuilder.java +++ b/client/src/main/java/org/sysmon/client/ClientRouteBuilder.java @@ -47,7 +47,7 @@ public class ClientRouteBuilder extends RouteBuilder { // Setup Camel route for this extension // a unique timer name gives the timer it's own thread, otherwise it's a shared thread for other timers with same name. - from("timer:"+provides+"?fixedRate=true&period=10s") + from("timer:"+provides+"?fixedRate=true&period=30s") .bean(ext, "getMetrics") //.doTry() .process(new MetricEnrichProcessor(registry)) diff --git a/plugins/sysmon-aix/README.md b/plugins/sysmon-aix/README.md new file mode 100644 index 0000000..ab367b7 --- /dev/null +++ b/plugins/sysmon-aix/README.md @@ -0,0 +1,44 @@ +# AIX Plugin + +## Processor Extension + +The processor extension works for both AIX and Linux on the Power ppc64/ppc64le architecture. + +Metrics reported are: + +- **mode** - Processor mode, Capped or Uncapped +- **type** - Processor type, Shared or Dedicated +- **lcpu** - Number of logical CPU's available for this partition +- **ent** - Processor entitlements available for this partition +- **user** - Indicates the percentage of the entitled processing capacity used while executing at the user level (application). +- **sys** - Indicates the percentage of the entitled processing capacity used while executing at the system level (kernel). +- **idle** - Indicates the percentage of the entitled processing capacity unused while the partition was idle and did not have any outstanding disk I/O request. +- **wait** - Indicates the percentage of the entitled processing capacity unused while the partition was idle and had outstanding disk I/O request(s). +- **physc** - Indicates the number of physical processors consumed. +- **entc** - Indicates the percentage of the entitled capacity consumed. +- **lbusy** - Indicates the percentage of logical processor(s) utilization that occurred while executing at the user and system level. + + +## Memory Extension + +Metrics reported are: + +- **total** - Total amount of memory (in KB). +- **used** - real memory consumption (in KB). +- **free** - free memory for use (in KB). +- **pin** - pinned memory consumption (in KB). +- **virtual** - virtual memory consumption (in KB). +- **available** - available memory (if freeing up virtual) (in KB). +- **paged** - paging space consumption (in KB). + +*Pinning a memory region prohibits the pager from stealing pages from the pages backing the pinned memory region.* + +## 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/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixDiskExtension.java b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixDiskExtension.java index 871d509..81707c3 100644 --- a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixDiskExtension.java +++ b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixDiskExtension.java @@ -50,7 +50,7 @@ public class AixDiskExtension implements MetricExtension { @Override public MetricResult getMetrics() { - List iostat = PluginHelper.executeCommand("iostat -d"); + List iostat = PluginHelper.executeCommand("iostat -d 1 1"); AixDiskStat diskStat = processCommandOutput(iostat); Map tagsMap = diskStat.getTags(); diff --git a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixMemoryExtension.java b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixMemoryExtension.java index 881e89f..b47936d 100644 --- a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixMemoryExtension.java +++ b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixMemoryExtension.java @@ -50,7 +50,8 @@ public class AixMemoryExtension implements MetricExtension { @Override public MetricResult getMetrics() { - List svmon = PluginHelper.executeCommand("svmon -G -O unit=KB"); + //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(); diff --git a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixMemoryStat.java b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixMemoryStat.java index ac1f14d..b517d92 100644 --- a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixMemoryStat.java +++ b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixMemoryStat.java @@ -15,28 +15,27 @@ public class AixMemoryStat { private static final Logger log = LoggerFactory.getLogger(AixMemoryStat.class); - // size inuse free pin virtual available mmode - // memory 4194304 4036532 157772 1854772 2335076 1652640 Ded - private final Pattern patternAix = Pattern.compile("^memory\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+)"); + 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 String mode; + private Long paged; AixMemoryStat(List lines) { for (String line : lines) { - Matcher matcher = patternAix.matcher(line); + 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)); + pin = Long.parseLong(matcher.group(4)); virtual = Long.parseLong(matcher.group(5)); available = Long.parseLong(matcher.group(6)); - mode = matcher.group(7); + paged = Long.parseLong(matcher.group(7)); break; } } @@ -45,7 +44,6 @@ public class AixMemoryStat { public Map getTags() { Map tags = new HashMap<>(); - tags.put("mode", mode); return tags; } @@ -59,8 +57,10 @@ public class AixMemoryStat { 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.doubleValue()); return fields; } diff --git a/plugins/sysmon-aix/src/test/groovy/AixMemoryTest.groovy b/plugins/sysmon-aix/src/test/groovy/AixMemoryTest.groovy index acc65c9..ffa9a76 100644 --- a/plugins/sysmon-aix/src/test/groovy/AixMemoryTest.groovy +++ b/plugins/sysmon-aix/src/test/groovy/AixMemoryTest.groovy @@ -15,14 +15,14 @@ class AixMemoryTest extends Specification { AixMemoryStat stats = extension.processCommandOutput(lines) then: - stats.getFields().get("total") == 4194304l - stats.getFields().get("used") == 4036532l - stats.getFields().get("free") == 157772l - stats.getFields().get("virtual") == 2335076l - stats.getFields().get("available") == 1652640l - stats.getFields().get("usage") == 60.6d - stats.getTags().get("mode") == "Ded" + 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.78d } diff --git a/plugins/sysmon-aix/src/test/resources/svmon.txt b/plugins/sysmon-aix/src/test/resources/svmon.txt index 6b9ee1e..8774006 100644 --- a/plugins/sysmon-aix/src/test/resources/svmon.txt +++ b/plugins/sysmon-aix/src/test/resources/svmon.txt @@ -1,9 +1,6 @@ Unit: KB --------------------------------------------------------------------------------------- - size inuse free pin virtual available mmode -memory 4194304 4036532 157772 1854772 2335076 1652640 Ded -pg space 524288 12400 - - work pers clnt other -pin 1407060 0 16736 430976 -in use 2335076 0 1701456 +------------------------------------------------------------------------ + Memory +------------------------------------------------------------------------ + Size Inuse Free Pin Virtual Available Pgsp + 4194304 4065060 129244 1878240 2784988 1058012 524288 diff --git a/plugins/sysmon-linux/README.md b/plugins/sysmon-linux/README.md new file mode 100644 index 0000000..3e23e69 --- /dev/null +++ b/plugins/sysmon-linux/README.md @@ -0,0 +1,36 @@ +# Linux 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). + + +## 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/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxDiskExtension.java b/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxDiskExtension.java index adcee51..15882b2 100644 --- a/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxDiskExtension.java +++ b/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxDiskExtension.java @@ -54,7 +54,6 @@ public class LinuxDiskExtension implements MetricExtension { LinuxDiskProcLine proc2 = processFileOutput(readProcFile()); LinuxDiskStat stat = new LinuxDiskStat(proc1, proc2); - System.err.println("FOOBAR"); return new MetricResult("disk", new Measurement(stat.getTags(), stat.getFields())); } diff --git a/server/src/main/java/org/sysmon/server/MetricResultToPointProcessor.java b/server/src/main/java/org/sysmon/server/MetricResultToPointProcessor.java index 1853cd9..26e21d8 100644 --- a/server/src/main/java/org/sysmon/server/MetricResultToPointProcessor.java +++ b/server/src/main/java/org/sysmon/server/MetricResultToPointProcessor.java @@ -46,8 +46,8 @@ public class MetricResultToPointProcessor implements Processor { } } - exchange.getIn().setBody(builder.build()); + } } diff --git a/server/src/main/java/org/sysmon/server/ServerRouteBuilder.java b/server/src/main/java/org/sysmon/server/ServerRouteBuilder.java index ce57274..d98831e 100644 --- a/server/src/main/java/org/sysmon/server/ServerRouteBuilder.java +++ b/server/src/main/java/org/sysmon/server/ServerRouteBuilder.java @@ -1,5 +1,6 @@ package org.sysmon.server; +import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.rest.RestBindingMode; import org.apache.camel.spi.Registry; @@ -32,6 +33,8 @@ public class ServerRouteBuilder extends RouteBuilder { .produces("text/html") .type(MetricResult.class) .route() + .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(202)) + .setHeader("Content-Type", constant("application/x-www-form-urlencoded")) .to("seda:inbound") .endRest();