diff --git a/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java b/agent/src/main/java/org/sysmon/agent/AgentRouteBuilder.java similarity index 72% rename from agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java rename to agent/src/main/java/org/sysmon/agent/AgentRouteBuilder.java index 624f5cc..f004be3 100644 --- a/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java +++ b/agent/src/main/java/org/sysmon/agent/AgentRouteBuilder.java @@ -12,10 +12,9 @@ import org.sysmon.shared.MetricResult; import java.util.List; -public class MyRouteBuilder extends RouteBuilder { - - private static final Logger log = LoggerFactory.getLogger(MyRouteBuilder.class); +public class AgentRouteBuilder extends RouteBuilder { + private static final Logger log = LoggerFactory.getLogger(AgentRouteBuilder.class); @Override public void configure() throws Exception { @@ -33,14 +32,12 @@ public class MyRouteBuilder extends RouteBuilder { // Setup Camel route for this extension from("timer:collect?period=10000") .bean(ext, "getMetrics") - //.setHeader("ext", constant(ext.getName())) - .doTry() - .process(new MetricProcessor()) - .choice() - .when(exchangeProperty("skip").isEqualTo(true)) - .stop() + //.doTry() + .process(new MetricEnrichProcessor()) + .choice().when(exchangeProperty("skip").isEqualTo(true)) + .stop() .otherwise() - .to("seda:metrics"); + .to("seda:metrics"); } } @@ -48,12 +45,14 @@ public class MyRouteBuilder extends RouteBuilder { from("seda:metrics") .setHeader(Exchange.HTTP_METHOD, constant("POST")) + //.setHeader(Exchange.CONTENT_TYPE, constant("application/json")) .doTry() //.process(new MetricProcessor()) .marshal().json(JsonLibrary.Jackson, MetricResult.class) .to("http://127.0.0.1:9925/metrics") .doCatch(Exception.class) - .log("Error sending metric to collector: ${exception}") + .log("Error: ${exception.message}") + //.log("Error sending metric to collector: ${body}") .end(); } diff --git a/agent/src/main/java/org/sysmon/agent/Application.java b/agent/src/main/java/org/sysmon/agent/Application.java index 139fede..f55ff44 100644 --- a/agent/src/main/java/org/sysmon/agent/Application.java +++ b/agent/src/main/java/org/sysmon/agent/Application.java @@ -17,7 +17,7 @@ public class Application { Main main = new Main(); // and add the routes (you can specify multiple classes) - main.configure().addRoutesBuilder(MyRouteBuilder.class); + main.configure().addRoutesBuilder(AgentRouteBuilder.class); // now keep the application running until the JVM is terminated (ctrl + c or sigterm) try { diff --git a/agent/src/main/java/org/sysmon/agent/MetricProcessor.java b/agent/src/main/java/org/sysmon/agent/MetricEnrichProcessor.java similarity index 56% rename from agent/src/main/java/org/sysmon/agent/MetricProcessor.java rename to agent/src/main/java/org/sysmon/agent/MetricEnrichProcessor.java index ab120b9..4ba1fbb 100644 --- a/agent/src/main/java/org/sysmon/agent/MetricProcessor.java +++ b/agent/src/main/java/org/sysmon/agent/MetricEnrichProcessor.java @@ -5,19 +5,21 @@ import org.apache.camel.Processor; import org.sysmon.shared.MetricResult; -public class MetricProcessor implements Processor { +public class MetricEnrichProcessor implements Processor { + + // TODO: Read hostname from future configuration + private final static String hostname = "saruman"; public void process(Exchange exchange) throws Exception { MetricResult result = exchange.getIn().getBody(MetricResult.class); - if(result.getMeasurementList().size() < 1) { + result.setHostname(hostname); + + // We make sure MetricResults with no measurements are not sent further down the line + if(result.getMeasurements().size() < 1) { exchange.setProperty("skip", true); } exchange.getIn().setHeader("component", result.getName()); - - // TODO: Read hostname from configuration - result.setHostname("sauron"); - exchange.getIn().setBody(result); } diff --git a/agent/src/main/java/org/sysmon/agent/MyAggregationStrategy.java b/agent/src/main/java/org/sysmon/agent/MyAggregationStrategy.java deleted file mode 100644 index 3954683..0000000 --- a/agent/src/main/java/org/sysmon/agent/MyAggregationStrategy.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sysmon.agent; - -import org.apache.camel.AggregationStrategy; -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.sysmon.shared.MetricResult; - -public class MyAggregationStrategy implements AggregationStrategy { - - public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { - Message newIn = newExchange.getIn(); - MetricResult oldBody = oldExchange.getIn().getBody(MetricResult.class); - String newBody = newIn.getBody(String.class); - newIn.setBody(oldBody + newBody); - return newExchange; - } - -} diff --git a/agent/src/main/resources/application.properties b/agent/src/main/resources/application.properties index 15f8b0d..2969166 100644 --- a/agent/src/main/resources/application.properties +++ b/agent/src/main/resources/application.properties @@ -17,14 +17,14 @@ # to configure camel main # here you can configure options on camel main (see MainConfigurationProperties class) -camel.main.name = SysMon-Agent +camel.main.name = sysmon-agent # enable tracing #camel.main.tracing = true # bean introspection to log reflection based configuration -camel.main.beanIntrospectionExtendedStatistics=true -camel.main.beanIntrospectionLoggingLevel=INFO +#camel.main.beanIntrospectionExtendedStatistics=true +#camel.main.beanIntrospectionLoggingLevel=INFO # run in lightweight mode to be tiny as possible camel.main.lightweight = true @@ -39,4 +39,4 @@ camel.main.lightweight = true # camel.main.auto-startup = false # configure beans -camel.beans.metricProcessor = #class:org.sysmon.agent.MetricProcessor +#camel.beans.metricProcessor = #class:org.sysmon.agent.MetricProcessor diff --git a/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java b/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java index aec2e83..09feed2 100644 --- a/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java +++ b/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java @@ -1,13 +1,8 @@ package org.sysmon.collector; -import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jackson.JacksonDataFormat; -import org.apache.camel.model.dataformat.JsonLibrary; import org.apache.camel.model.rest.RestBindingMode; -import org.sysmon.collector.processor.MetricResultToPointProcessor; import org.sysmon.shared.MetricResult; -import org.sysmon.shared.dto.MetricMessageDTO; public class CollectorRouteBuilder extends RouteBuilder { diff --git a/collector/src/main/java/org/sysmon/collector/processor/MetricResultToPointProcessor.java b/collector/src/main/java/org/sysmon/collector/MetricResultToPointProcessor.java similarity index 84% rename from collector/src/main/java/org/sysmon/collector/processor/MetricResultToPointProcessor.java rename to collector/src/main/java/org/sysmon/collector/MetricResultToPointProcessor.java index 0133040..69a5271 100644 --- a/collector/src/main/java/org/sysmon/collector/processor/MetricResultToPointProcessor.java +++ b/collector/src/main/java/org/sysmon/collector/MetricResultToPointProcessor.java @@ -1,9 +1,9 @@ -package org.sysmon.collector.processor; +package org.sysmon.collector; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.influxdb.dto.Point; -import org.sysmon.shared.MetricMeasurement; +import org.sysmon.shared.MeasurementPair; import org.sysmon.shared.MetricResult; import java.util.List; @@ -20,8 +20,8 @@ public class MetricResultToPointProcessor implements Processor { .time(metricResult.getTimestamp(), TimeUnit.MILLISECONDS) .tag("hostname", metricResult.getHostname()); - List measurements = metricResult.getMeasurementList(); - for(MetricMeasurement measurement : measurements) { + List measurements = metricResult.getMeasurements(); + for(MeasurementPair measurement : measurements) { if(measurement.getValue() instanceof Number) { Number num = (Number) measurement.getValue(); builder.addField(measurement.getName(), num); diff --git a/collector/src/main/java/org/sysmon/collector/bean/IncomingMetricProcessor.java b/collector/src/main/java/org/sysmon/collector/bean/IncomingMetricProcessor.java index 31befdf..09f0c38 100644 --- a/collector/src/main/java/org/sysmon/collector/bean/IncomingMetricProcessor.java +++ b/collector/src/main/java/org/sysmon/collector/bean/IncomingMetricProcessor.java @@ -2,10 +2,7 @@ package org.sysmon.collector.bean; import org.apache.camel.Exchange; import org.apache.camel.Processor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.sysmon.shared.MetricResult; -import org.sysmon.shared.dto.MetricMessageDTO; public class IncomingMetricProcessor implements Processor { diff --git a/collector/src/main/resources/application.properties b/collector/src/main/resources/application.properties index 45d8959..7dde120 100644 --- a/collector/src/main/resources/application.properties +++ b/collector/src/main/resources/application.properties @@ -23,8 +23,8 @@ camel.main.name = sysmon-collector #camel.main.tracing = true # bean introspection to log reflection based configuration -camel.main.beanIntrospectionExtendedStatistics=true -camel.main.beanIntrospectionLoggingLevel=INFO +#camel.main.beanIntrospectionExtendedStatistics=true +#camel.main.beanIntrospectionLoggingLevel=INFO # run in lightweight mode to be tiny as possible camel.main.lightweight = true @@ -39,5 +39,5 @@ camel.main.lightweight = true # camel.main.auto-startup = false # configure beans -camel.beans.incomingMetricProcessor = #class:org.sysmon.collector.bean.IncomingMetricProcessor -camel.beans.hello = #class:org.sysmon.collector.bean.Hello +#camel.beans.incomingMetricProcessor = #class:org.sysmon.collector.bean.IncomingMetricProcessor +#camel.beans.hello = #class:org.sysmon.collector.bean.Hello diff --git a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixProcessorExtension.java b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixProcessorExtension.java index 7a7b506..2740ce0 100644 --- a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixProcessorExtension.java +++ b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixProcessorExtension.java @@ -4,7 +4,7 @@ import org.pf4j.Extension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sysmon.shared.MetricExtension; -import org.sysmon.shared.MetricMeasurement; +import org.sysmon.shared.MeasurementPair; import org.sysmon.shared.MetricResult; import org.sysmon.shared.PluginHelper; @@ -39,7 +39,7 @@ public class AixProcessorExtension implements MetricExtension { List mpstat = PluginHelper.executeCommand("mpstat", "-a"); List processorStats = processCommandOutput(mpstat); for(AixProcessorStat stat : processorStats) { - result.addMetricMeasurement(new MetricMeasurement(String.format("cpu%d", stat.getCpuNum()), stat.getUtilizationPercentage())); + result.addMetricMeasurement(new MeasurementPair(String.format("cpu%d", stat.getCpuNum()), stat.getUtilizationPercentage())); } return result; 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 fbbaa6d..44d3e01 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 @@ -2,7 +2,7 @@ package org.sysmon.plugins.sysmon_linux; import org.pf4j.Extension; import org.sysmon.shared.MetricExtension; -import org.sysmon.shared.MetricMeasurement; +import org.sysmon.shared.MeasurementPair; import org.sysmon.shared.MetricResult; import java.io.IOException; @@ -76,9 +76,9 @@ public class LinuxDiskExtension implements MetricExtension { } - private List calculate() { + private List calculate() { - List measurementList = new ArrayList<>(); + List measurementList = new ArrayList<>(); if(previousDiskStats == null || previousDiskStats.size() != currentDiskStats.size()) { return measurementList; @@ -101,7 +101,7 @@ public class LinuxDiskExtension implements MetricExtension { if(!ignore.get()) { long timeSpendDoingIo = curStat.getTimeSpentOnIo() - preStat.getTimeSpentOnIo(); // TODO: Calculate differences for wanted disk io stats - measurementList.add(new MetricMeasurement(curStat.getDevice() + "-iotime", timeSpendDoingIo)); + measurementList.add(new MeasurementPair(curStat.getDevice() + "-iotime", timeSpendDoingIo)); } } diff --git a/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxMemoryExtension.java b/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxMemoryExtension.java index faeccdf..26e8cd3 100644 --- a/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxMemoryExtension.java +++ b/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxMemoryExtension.java @@ -2,7 +2,7 @@ package org.sysmon.plugins.sysmon_linux; import org.pf4j.Extension; import org.sysmon.shared.MetricExtension; -import org.sysmon.shared.MetricMeasurement; +import org.sysmon.shared.MeasurementPair; import org.sysmon.shared.MetricResult; import java.io.IOException; @@ -49,9 +49,9 @@ public class LinuxMemoryExtension implements MetricExtension { } - private List readProcFile() throws IOException { + private List readProcFile() throws IOException { - List measurementList = new ArrayList<>(); + List measurementList = new ArrayList<>(); List allLines = Files.readAllLines(Paths.get("/proc/meminfo"), StandardCharsets.UTF_8); for (String line : allLines) { @@ -59,7 +59,7 @@ public class LinuxMemoryExtension implements MetricExtension { if (line.startsWith("Mem")) { Matcher matcher = pattern.matcher(line); if (matcher.find() && matcher.groupCount() == 2) { - measurementList.add(new MetricMeasurement(matcher.group(1), matcher.group(2))); + measurementList.add(new MeasurementPair(matcher.group(1), matcher.group(2))); } } } diff --git a/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxProcessorExtension.java b/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxProcessorExtension.java index a9670ed..5479a4f 100644 --- a/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxProcessorExtension.java +++ b/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxProcessorExtension.java @@ -5,7 +5,7 @@ import org.pf4j.Extension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sysmon.shared.MetricExtension; -import org.sysmon.shared.MetricMeasurement; +import org.sysmon.shared.MeasurementPair; import org.sysmon.shared.MetricResult; import java.io.IOException; @@ -55,9 +55,9 @@ public class LinuxProcessorExtension implements MetricExtension { } - private List calculateDifference() { + private List calculateDifference() { - List measurementList = new ArrayList<>(); + List measurementList = new ArrayList<>(); if(previousProcessorStats == null || previousProcessorStats.size() != currentProcessorStats.size()) { return measurementList; @@ -73,7 +73,7 @@ public class LinuxProcessorExtension implements MetricExtension { float percentUsage = (float) (workTimeDiff - idleTimeDiff) / workTimeDiff; Integer pct = (int) (percentUsage * 100); - measurementList.add(new MetricMeasurement(curStat.getCpuName(), pct)); + measurementList.add(new MeasurementPair(curStat.getCpuName(), pct)); } diff --git a/shared/src/main/java/org/sysmon/shared/MetricMeasurement.java b/shared/src/main/java/org/sysmon/shared/MeasurementPair.java similarity index 68% rename from shared/src/main/java/org/sysmon/shared/MetricMeasurement.java rename to shared/src/main/java/org/sysmon/shared/MeasurementPair.java index 2d1fb4f..b08ede3 100644 --- a/shared/src/main/java/org/sysmon/shared/MetricMeasurement.java +++ b/shared/src/main/java/org/sysmon/shared/MeasurementPair.java @@ -1,13 +1,17 @@ package org.sysmon.shared; -public class MetricMeasurement { +import java.io.Serializable; + +public class MeasurementPair implements Serializable { + + private static final long serialVersionUID = 1L; private String name; private Object value; - public MetricMeasurement() { } + public MeasurementPair() { } - public MetricMeasurement(String name, Object value) { + public MeasurementPair(String name, Object value) { this.name = name; this.value = value; } diff --git a/shared/src/main/java/org/sysmon/shared/MetricResult.java b/shared/src/main/java/org/sysmon/shared/MetricResult.java index e94e8ef..11abb61 100644 --- a/shared/src/main/java/org/sysmon/shared/MetricResult.java +++ b/shared/src/main/java/org/sysmon/shared/MetricResult.java @@ -12,7 +12,7 @@ public class MetricResult implements Serializable { private String name; private Long timestamp; // epoch milli private String hostname; - private List measurementList = new ArrayList<>(); + private List measurements = new ArrayList<>(); public MetricResult() { @@ -23,12 +23,12 @@ public class MetricResult implements Serializable { this.timestamp = Instant.now().toEpochMilli(); } - public void setMetricMeasurementList(List measurementList) { - this.measurementList = measurementList; + public void setMetricMeasurementList(List measurementList) { + this.measurements = measurementList; } - public void addMetricMeasurement(MetricMeasurement measurement) { - measurementList.add(measurement); + public void addMetricMeasurement(MeasurementPair measurement) { + measurements.add(measurement); } public void setHostname(String hostname) { @@ -55,13 +55,13 @@ public class MetricResult implements Serializable { return hostname; } - public List getMeasurementList() { - return measurementList; + public List getMeasurements() { + return measurements; } public String toString() { StringBuilder sb = new StringBuilder(String.format("%s - %s\n", timestamp.toString(), name)); - for(MetricMeasurement mm : measurementList) { + for(MeasurementPair mm : measurements) { sb.append(mm.toString()).append("\n"); } diff --git a/shared/src/main/java/org/sysmon/shared/dto/MetricMessageDTO.java b/shared/src/main/java/org/sysmon/shared/dto/MetricMessageDTO.java deleted file mode 100644 index 5450ad9..0000000 --- a/shared/src/main/java/org/sysmon/shared/dto/MetricMessageDTO.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.sysmon.shared.dto; - -import java.util.Objects; - -public class MetricMessageDTO { - - private String msg; - private long id; - - public MetricMessageDTO() { - // empty constructor is required bu Jackson for deserialization - } - - public MetricMessageDTO(String msg, long id) { - Objects.requireNonNull(msg); - - this.msg = msg; - this.id = id; - } - - public String getMsg() { - return msg; - } - - public long getId() { - return id; - } - - public void setMsg(String msg) { - this.msg = msg; - } - - public void setId(long id) { - this.id = id; - } - - @Override - public String toString() { - return "MetricMessageDTO{" + - "msg='" + msg + '\'' + - ", id=" + id + - '}'; - } - -}