From 7f1b7148708e3d65a7e902a5af8b43173f142efb Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Tue, 27 Apr 2021 20:47:26 +0200 Subject: [PATCH] Try to support both Linux and AIX. --- .../java/org/sysmon/agent/MyRouteBuilder.java | 41 ++++++++--- .../sysmon/agent/beans/ProcessorBeanAix.java | 69 +++++++++++++++++++ ...essorBean.java => ProcessorBeanLinux.java} | 4 +- .../src/main/resources/application.properties | 2 +- 4 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 agent/src/main/java/org/sysmon/agent/beans/ProcessorBeanAix.java rename agent/src/main/java/org/sysmon/agent/beans/{ProcessorBean.java => ProcessorBeanLinux.java} (98%) diff --git a/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java b/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java index 3a67ab9..ec5fb61 100644 --- a/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java +++ b/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java @@ -1,28 +1,53 @@ package org.sysmon.agent; import org.apache.camel.builder.RouteBuilder; +import org.sysmon.agent.beans.ProcessorBeanAix; +import org.sysmon.agent.beans.ProcessorBeanLinux; public class MyRouteBuilder extends RouteBuilder { - + + private static final String osName = System.getProperty("os.name").toLowerCase(); + @Override public void configure() throws Exception { + + // TODO: Some smarter way to do this ? + + if(osName.contains("linux")) { + // Linux specific beans + from("timer:collect?period=5000") + .bean(new ProcessorBeanLinux(), "getMetrics") + .to("seda:metrics"); + + } else if(osName.contains("aix")) { + // AIX specific beans + from("timer:collect?period=5000") + .bean(new ProcessorBeanAix(), "getMetrics") + .to("seda:metrics"); + + } else { + // Unsupported OS + throw new UnsupportedOperationException("OS not implemented: " + osName); + } + + + + // TODO: Discover beans on classpath and setup accordingly ?? + // Setup metrics measurement beans - // TODO: Discover beans on classpath and setup accordingly from("timer:collect?period=5000") .bean("memoryBean", "getMetrics") .to("seda:metrics"); - from("timer:collect?period=5000") - .bean("processorBean", "getMetrics") - .to("seda:metrics"); + from("timer:collect?period=5000") .bean("diskBean", "getMetrics") .to("seda:metrics"); - // TODO: Somehow combine all results in a format suitable for sending to REST endpoint - from("seda:metrics").process("metricProcessor"); - // Could we store the last n results from each bean, and send mean value to the REST endpoint? + // TODO: Somehow combine all results in a format suitable for sending to a central REST endpoint + + from("seda:metrics").process("metricProcessor"); } diff --git a/agent/src/main/java/org/sysmon/agent/beans/ProcessorBeanAix.java b/agent/src/main/java/org/sysmon/agent/beans/ProcessorBeanAix.java new file mode 100644 index 0000000..c0f1ac7 --- /dev/null +++ b/agent/src/main/java/org/sysmon/agent/beans/ProcessorBeanAix.java @@ -0,0 +1,69 @@ +package org.sysmon.agent.beans; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sysmon.shared.MetricBean; +import org.sysmon.shared.MetricResult; + +public class ProcessorBeanAix implements MetricBean { + + private final static Logger log = LoggerFactory.getLogger(ProcessorBeanAix.class); + + + @Override + public MetricResult getMetrics() { + log.warn("TODO: AIX processor stat."); + return null; + } + +} + + +/* + + +# mpstat -v + +System configuration: lcpu=8 ent=0.5 mode=Uncapped + + +vcpu lcpu us sy wa id pbusy pc VTB(ms) +---- ---- ---- ---- ----- ----- ----- ----- ------- +0 12.26 10.89 0.11 76.74 0.00[ 23.1%] 0.00[ 0.0%] 121967 + 0 10.58 8.53 0.04 5.71 0.00[ 19.1%] 0.00[ 24.9%] - + 1 1.32 1.21 0.05 11.16 0.00[ 2.5%] 0.00[ 13.7%] - + 2 0.22 0.28 0.01 8.24 0.00[ 0.5%] 0.00[ 8.8%] - + 3 0.11 0.19 0.01 11.63 0.00[ 0.3%] 0.00[ 11.9%] - + 4 0.01 0.10 0.00 8.34 0.00[ 0.1%] 0.00[ 8.5%] - + 5 0.00 0.07 0.00 11.69 0.00[ 0.1%] 0.00[ 11.8%] - + 6 0.00 0.13 0.00 8.33 0.00[ 0.1%] 0.00[ 8.5%] - + 7 0.01 0.37 0.00 11.63 0.00[ 0.4%] 0.00[ 12.0%] - + + + + +# mpstat + +System configuration: lcpu=8 ent=0.5 mode=Uncapped + +cpu min maj mpc int cs ics rq mig lpa sysc us sy wa id pc %ec lcs + 0 1489677 9337 2633 2146943 1160666 30547 3 2951 100 8361624 43 35 0 23 0.00 0.0 1646908 + 1 336156 2711 383 266244 25376 5494 0 3401 100 1042507 10 9 0 80 0.00 0.0 230605 + 2 45820 829 377 116004 5984 2326 0 1889 100 474631 3 3 0 94 0.00 0.0 117923 + 3 46812 699 377 115297 6217 2306 0 1746 100 58549 1 2 0 97 0.00 0.0 117011 + 4 2786 39 377 112634 1485 1124 0 1143 100 7432 0 1 0 99 0.00 0.0 114271 + 5 1233 45 377 112032 1369 1111 0 1147 100 7591 0 1 0 99 0.00 0.0 113674 + 6 25415 238 377 112763 1519 1235 0 1126 100 2403 0 2 0 98 0.00 0.0 114479 + 7 3596 124 377 193193 1615 1181 0 1123 100 2572 0 3 0 97 0.00 0.0 195104 + U - - - - - - - - - - - - 0 100 0.50 100.0 - +ALL 1951495 14022 5278 3175110 1204231 45324 3 14526 100 9957309 0 0 0 100 0.00 0.0 2649975 + + +%ec + (Default, -a flag) The percentage of entitled capacity consumed by the logical processor. + The %ec of the ALL CPU row represents the percentage of entitled capacity consumed. + Because the time base over which this data is computed can vary, the entitled capacity + percentage can sometimes exceed 100%. This excess is noticeable only with small sampling intervals. + The attribute is displayed only in a shared partition. + + */ diff --git a/agent/src/main/java/org/sysmon/agent/beans/ProcessorBean.java b/agent/src/main/java/org/sysmon/agent/beans/ProcessorBeanLinux.java similarity index 98% rename from agent/src/main/java/org/sysmon/agent/beans/ProcessorBean.java rename to agent/src/main/java/org/sysmon/agent/beans/ProcessorBeanLinux.java index fe990b9..a35c294 100644 --- a/agent/src/main/java/org/sysmon/agent/beans/ProcessorBean.java +++ b/agent/src/main/java/org/sysmon/agent/beans/ProcessorBeanLinux.java @@ -15,9 +15,9 @@ import org.sysmon.shared.MetricMeasurement; import org.sysmon.shared.MetricResult; @Configurer -public class ProcessorBean implements MetricBean { +public class ProcessorBeanLinux implements MetricBean { - private final static Logger log = LoggerFactory.getLogger(ProcessorBean.class); + private final static Logger log = LoggerFactory.getLogger(ProcessorBeanLinux.class); private List currentProcessorStats; private List previousProcessorStats; diff --git a/agent/src/main/resources/application.properties b/agent/src/main/resources/application.properties index a23a07f..bf2ff6c 100644 --- a/agent/src/main/resources/application.properties +++ b/agent/src/main/resources/application.properties @@ -42,4 +42,4 @@ camel.main.lightweight = true camel.beans.metricProcessor = #class:org.sysmon.agent.MetricProcessor camel.beans.diskBean = #class:org.sysmon.agent.beans.DiskBean camel.beans.memoryBean = #class:org.sysmon.agent.beans.MemoryBean -camel.beans.processorBean = #class:org.sysmon.agent.beans.ProcessorBean +#camel.beans.processorBean = #class:org.sysmon.agent.beans.ProcessorBean