From 9b99e22b8b7764953540b8cb3f864f8fd4e5c307 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Tue, 4 May 2021 14:23:34 +0200 Subject: [PATCH] Combined work from collector branch into this. --- agent/build.gradle | 15 ++-- .../java/org/sysmon/agent/Application.java | 74 ++++++---------- .../agent/ArrayListAggregationStrategy.java | 25 ++++++ .../org/sysmon/agent/MetricProcessor.java | 32 +++++++ .../sysmon/agent/MyAggregationStrategy.java | 18 ++++ .../java/org/sysmon/agent/MyRouteBuilder.java | 88 +++++++++++++++++++ .../agent/StringAggregationStrategy.java | 18 ++++ .../org/sysmon/agent/SysmonPluginManager.java | 30 ------- .../agent/SysmonPluginStatusProvider.java | 57 ------------ .../src/main/resources/application.properties | 42 +++++++++ .../main/resources/simplelogger.properties | 2 +- .../test/resources/simplelogger.properties | 6 ++ collector/build.gradle | 35 ++++++++ .../org/sysmon/collector/Application.java | 19 ++++ .../collector/CollectorRouteBuilder.java | 34 +++++++ .../java/org/sysmon/collector/bean/Hello.java | 21 +++++ .../bean/IncomingMetricProcessor.java | 23 +++++ .../src/main/resources/application.properties | 43 +++++++++ .../main/resources/simplelogger.properties | 6 ++ .../test/resources/simplelogger.properties | 6 ++ .../plugins/sysmon_aix/AixDiskExtension.java | 9 +- .../sysmon/plugins/sysmon_aix/AixPlugin.java | 18 ---- .../sysmon_aix/AixProcessorExtension.java | 9 +- .../sysmon_linux/LinuxDiskExtension.java | 9 +- .../sysmon_linux/LinuxMemoryExtension.java | 9 +- .../plugins/sysmon_linux/LinuxPlugin.java | 18 ---- .../sysmon_linux/LinuxProcessorExtension.java | 8 +- settings.gradle | 2 +- .../java/org/sysmon/shared/MetricBean.java | 9 -- .../org/sysmon/shared/MetricExtension.java | 5 +- .../java/org/sysmon/shared/SysmonPlugin.java | 24 ----- .../sysmon/shared/dto/MetricMessageDTO.java | 45 ++++++++++ 32 files changed, 535 insertions(+), 224 deletions(-) create mode 100644 agent/src/main/java/org/sysmon/agent/ArrayListAggregationStrategy.java create mode 100644 agent/src/main/java/org/sysmon/agent/MetricProcessor.java create mode 100644 agent/src/main/java/org/sysmon/agent/MyAggregationStrategy.java create mode 100644 agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java create mode 100644 agent/src/main/java/org/sysmon/agent/StringAggregationStrategy.java delete mode 100644 agent/src/main/java/org/sysmon/agent/SysmonPluginManager.java delete mode 100644 agent/src/main/java/org/sysmon/agent/SysmonPluginStatusProvider.java create mode 100644 agent/src/main/resources/application.properties create mode 100644 agent/src/test/resources/simplelogger.properties create mode 100644 collector/build.gradle create mode 100644 collector/src/main/java/org/sysmon/collector/Application.java create mode 100644 collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java create mode 100644 collector/src/main/java/org/sysmon/collector/bean/Hello.java create mode 100644 collector/src/main/java/org/sysmon/collector/bean/IncomingMetricProcessor.java create mode 100644 collector/src/main/resources/application.properties create mode 100644 collector/src/main/resources/simplelogger.properties create mode 100644 collector/src/test/resources/simplelogger.properties delete mode 100644 shared/src/main/java/org/sysmon/shared/MetricBean.java delete mode 100644 shared/src/main/java/org/sysmon/shared/SysmonPlugin.java create mode 100644 shared/src/main/java/org/sysmon/shared/dto/MetricMessageDTO.java diff --git a/agent/build.gradle b/agent/build.gradle index 8b245bb..d0fa9e9 100644 --- a/agent/build.gradle +++ b/agent/build.gradle @@ -1,11 +1,3 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java application project to get you started. - * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle - * User Manual available at https://docs.gradle.org/7.0/userguide/building_java_projects.html - */ - plugins { id 'groovy' id 'application' @@ -30,6 +22,13 @@ dependencies { annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") implementation group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}" + implementation group: 'org.apache.camel', name: 'camel-core', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-main', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-http', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-jackson', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-bean', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-timer', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-stream', version: '3.7.3' } application { diff --git a/agent/src/main/java/org/sysmon/agent/Application.java b/agent/src/main/java/org/sysmon/agent/Application.java index f40ad7b..139fede 100644 --- a/agent/src/main/java/org/sysmon/agent/Application.java +++ b/agent/src/main/java/org/sysmon/agent/Application.java @@ -3,53 +3,50 @@ */ package org.sysmon.agent; -import org.pf4j.*; +import org.apache.camel.main.Main; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sysmon.shared.MetricExtension; - -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; public class Application { private static final Logger log = LoggerFactory.getLogger(Application.class); + public static void main(String[] args) { + + // use Camels Main class + Main main = new Main(); + + // and add the routes (you can specify multiple classes) + main.configure().addRoutesBuilder(MyRouteBuilder.class); + + // now keep the application running until the JVM is terminated (ctrl + c or sigterm) + try { + main.run(args); + } catch(Exception e) { + System.err.println(e.getMessage()); + } + + } + +/* public static void main(String[] args) throws InterruptedException { // create the plugin manager - PluginManager pluginManager = new SysmonPluginManager(); // or "new ZipPluginManager() / new DefaultPluginManager()" + PluginManager pluginManager = new JarPluginManager(); // or "new ZipPluginManager() / new DefaultPluginManager()" // start and load all plugins of application pluginManager.loadPlugins(); pluginManager.startPlugins(); - /* - final PluginManager pluginManager = new SysmonPluginManager() { - - protected ExtensionFinder createExtensionFinder() { - DefaultExtensionFinder extensionFinder = (DefaultExtensionFinder) super.createExtensionFinder(); - extensionFinder.addServiceProviderExtensionFinder(); - return extensionFinder; - } - - }; - - pluginManager.loadPlugins(); - pluginManager.startPlugins(); - */ - - /* - List plugins = pluginManager.getPlugins(); - for(PluginWrapper wrapper : plugins) { - log.info(">>> Plugin Description: " + wrapper.getDescriptor().getPluginDescription()); - } - */ List metricExtensions = pluginManager.getExtensions(MetricExtension.class); log.info(String.format("Found %d extensions for extension point '%s':", metricExtensions.size(), MetricExtension.class.getName())); - for (MetricExtension plugin : metricExtensions) { - log.info(">>> " + plugin.getGreeting()); + for (MetricExtension ext : metricExtensions) { + if(ext.isSupported()) { + log.info(">>> " + ext.getGreeting()); + + // TODO: Setup camel + } } @@ -62,24 +59,7 @@ public class Application { Runtime.getRuntime().addShutdownHook(shutdownHook); - /* - do { - - for (MetricExtension plugin : metricExtensions) { - - // TODO: Find better way to avoid using plugins not working on runtime OS. - - if(plugin.isSupported()) { - System.out.println(">>> " + plugin.getMetrics()); - } - } - - Thread.sleep(15000); - } while (keepRunning.get()); - */ - - } - + */ } diff --git a/agent/src/main/java/org/sysmon/agent/ArrayListAggregationStrategy.java b/agent/src/main/java/org/sysmon/agent/ArrayListAggregationStrategy.java new file mode 100644 index 0000000..443f65a --- /dev/null +++ b/agent/src/main/java/org/sysmon/agent/ArrayListAggregationStrategy.java @@ -0,0 +1,25 @@ +package org.sysmon.agent; + +import org.apache.camel.AggregationStrategy; +import org.apache.camel.Exchange; + +import java.util.ArrayList; + +//simply combines Exchange body values into an ArrayList +class ArrayListAggregationStrategy implements AggregationStrategy { + + public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { + Object newBody = newExchange.getIn().getBody(); + ArrayList list = null; + if (oldExchange == null) { + list = new ArrayList(); + list.add(newBody); + newExchange.getIn().setBody(list); + return newExchange; + } else { + list = oldExchange.getIn().getBody(ArrayList.class); + list.add(newBody); + return oldExchange; + } + } +} diff --git a/agent/src/main/java/org/sysmon/agent/MetricProcessor.java b/agent/src/main/java/org/sysmon/agent/MetricProcessor.java new file mode 100644 index 0000000..1d00a2e --- /dev/null +++ b/agent/src/main/java/org/sysmon/agent/MetricProcessor.java @@ -0,0 +1,32 @@ +package org.sysmon.agent; + +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; + +import java.util.concurrent.atomic.AtomicLong; + +public class MetricProcessor implements Processor { + + private final static Logger log = LoggerFactory.getLogger(MetricProcessor.class); + + private static final AtomicLong counter = new AtomicLong(); + + public void process(Exchange exchange) throws Exception { + + MetricResult reading = exchange.getIn().getBody(MetricResult.class); + log.debug(reading.toString()); + + // do something with the payload and/or exchange here + //exchange.getIn().setBody("Changed body"); + + // do something... + MetricMessageDTO payload = new MetricMessageDTO("event " + reading, counter.getAndIncrement()); + exchange.getIn().setBody(payload, MetricMessageDTO.class); + } + + +} \ No newline at end of file diff --git a/agent/src/main/java/org/sysmon/agent/MyAggregationStrategy.java b/agent/src/main/java/org/sysmon/agent/MyAggregationStrategy.java new file mode 100644 index 0000000..3954683 --- /dev/null +++ b/agent/src/main/java/org/sysmon/agent/MyAggregationStrategy.java @@ -0,0 +1,18 @@ +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/java/org/sysmon/agent/MyRouteBuilder.java b/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java new file mode 100644 index 0000000..4d513dc --- /dev/null +++ b/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java @@ -0,0 +1,88 @@ +package org.sysmon.agent; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.pf4j.JarPluginManager; +import org.pf4j.PluginManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.sysmon.shared.MetricExtension; + +import java.util.List; + +public class MyRouteBuilder extends RouteBuilder { + + private static final Logger log = LoggerFactory.getLogger(MyRouteBuilder.class); + + + @Override + public void configure() throws Exception { + + PluginManager pluginManager = new JarPluginManager(); + pluginManager.loadPlugins(); + pluginManager.startPlugins(); + + List metricExtensions = pluginManager.getExtensions(MetricExtension.class); + //log.info(String.format("Found %d extensions for extension point '%s':", metricExtensions.size(), MetricExtension.class.getName())); + for (MetricExtension ext : metricExtensions) { + if(ext.isSupported()) { + log.info(">>> Enabling extension: " + ext.getDescription()); + + // Setup Camel route for this extension + from("timer:collect?period=5000") + .bean(ext, "getMetrics") + .setHeader("ext", constant(ext.getName())) + .to("seda:metrics"); + + } + } + + + + /* + TODO: How to combine/wrap the individual metrics into a container which also contains + some extra information, such as our hostname, operating system, timestamp, etc. + + Like one JSON or XML output with all metrics: + + { + "hostname": "sauron", + "timestamp": "1322334343434", + "metrics": [ + { "processor": [ + { "cpu0":"10" }, + { "cpu1":"12" } + ]}, + { "memory": [ + { "memUsed": "323434"}, + { "memFree": "4454545"} + ]} + ] + } + */ + + + /* + from("seda:metrics") + .aggregate(header("ext"), new ArrayListAggregationStrategy()) + .completionInterval(5000) + .to("seda:aggregated"); + + from("seda:aggregated") + .log("${body}"); + */ + + + // Send to collector when combined + from("seda:metrics") + .process(new MetricProcessor()) + .marshal().json() + .setHeader(Exchange.HTTP_METHOD, constant("POST")) + .to("http://127.0.0.1:9925/metrics"); + + + + + } + +} \ No newline at end of file diff --git a/agent/src/main/java/org/sysmon/agent/StringAggregationStrategy.java b/agent/src/main/java/org/sysmon/agent/StringAggregationStrategy.java new file mode 100644 index 0000000..cf74c3e --- /dev/null +++ b/agent/src/main/java/org/sysmon/agent/StringAggregationStrategy.java @@ -0,0 +1,18 @@ +package org.sysmon.agent; + +import org.apache.camel.AggregationStrategy; +import org.apache.camel.Exchange; + +class StringAggregationStrategy implements AggregationStrategy { + + public Exchange aggregate(Exchange oldExchange, Exchange newExchange) { + if (oldExchange == null) { + return newExchange; + } + + String oldBody = oldExchange.getIn().getBody(String.class); + String newBody = newExchange.getIn().getBody(String.class); + oldExchange.getIn().setBody(oldBody + "+" + newBody); + return oldExchange; + } +} diff --git a/agent/src/main/java/org/sysmon/agent/SysmonPluginManager.java b/agent/src/main/java/org/sysmon/agent/SysmonPluginManager.java deleted file mode 100644 index 83b85ed..0000000 --- a/agent/src/main/java/org/sysmon/agent/SysmonPluginManager.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sysmon.agent; - -import org.pf4j.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SysmonPluginManager extends DefaultPluginManager { - - private static final Logger log = LoggerFactory.getLogger(SysmonPluginManager.class); - - - public SysmonPluginManager() { - super(); - log.warn("SysmonPluginManager()"); - } - - @Override - protected PluginStatusProvider createPluginStatusProvider() { - log.warn("createPluginStatusProvider()"); - return new SysmonPluginStatusProvider(); - } - - @Override - protected ExtensionFactory createExtensionFactory() { - log.warn("createExtensionFactory()"); - return new SingletonExtensionFactory(); - } - - -} diff --git a/agent/src/main/java/org/sysmon/agent/SysmonPluginStatusProvider.java b/agent/src/main/java/org/sysmon/agent/SysmonPluginStatusProvider.java deleted file mode 100644 index 83d4ae6..0000000 --- a/agent/src/main/java/org/sysmon/agent/SysmonPluginStatusProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.sysmon.agent; - -import org.pf4j.PluginStatusProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -public class SysmonPluginStatusProvider implements PluginStatusProvider { - - private static final Logger log = LoggerFactory.getLogger(SysmonPluginStatusProvider.class); - - private final List enabledPlugins = new ArrayList<>(); - private final List disabledPlugins = new ArrayList<>(); - - - public SysmonPluginStatusProvider() { - log.warn("SysmonPluginManager()"); - } - - - @Override - public boolean isPluginDisabled(String pluginId) { - log.warn("isPluginDisabled() - " + pluginId); - if (disabledPlugins.contains(pluginId)) { - return true; - } - - return !enabledPlugins.isEmpty() && !enabledPlugins.contains(pluginId); - } - - @Override - public void disablePlugin(String pluginId) { - - log.warn("disablePlugin() - " + pluginId); - - if (isPluginDisabled(pluginId)) { - // do nothing - return; - } - - } - - @Override - public void enablePlugin(String pluginId) { - - log.warn("enablePlugin() - " + pluginId); - - if (!isPluginDisabled(pluginId)) { - // do nothing - return; - } - - } - -} diff --git a/agent/src/main/resources/application.properties b/agent/src/main/resources/application.properties new file mode 100644 index 0000000..20a58a6 --- /dev/null +++ b/agent/src/main/resources/application.properties @@ -0,0 +1,42 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +# to configure camel main +# here you can configure options on camel main (see MainConfigurationProperties class) +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 + +# run in lightweight mode to be tiny as possible +camel.main.lightweight = true +# and eager load classes +#camel.main.eager-classloading = true + +# use object pooling to reduce JVM garbage collection +#camel.main.exchange-factory = pooled +#camel.main.exchange-factory-statistics-enabled = true + +# can be used to not start the route +# camel.main.auto-startup = false + +# configure beans +camel.beans.metricProcessor = #class:org.sysmon.agent.MetricProcessor diff --git a/agent/src/main/resources/simplelogger.properties b/agent/src/main/resources/simplelogger.properties index 82fb15c..df664d0 100644 --- a/agent/src/main/resources/simplelogger.properties +++ b/agent/src/main/resources/simplelogger.properties @@ -1,4 +1,4 @@ -org.slf4j.simpleLogger.logFile=System.err +org.slf4j.simpleLogger.logFile=System.out org.slf4j.simpleLogger.showDateTime=true org.slf4j.simpleLogger.showShortLogName=true org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS diff --git a/agent/src/test/resources/simplelogger.properties b/agent/src/test/resources/simplelogger.properties new file mode 100644 index 0000000..603d7a6 --- /dev/null +++ b/agent/src/test/resources/simplelogger.properties @@ -0,0 +1,6 @@ +org.slf4j.simpleLogger.logFile=System.err +org.slf4j.simpleLogger.showDateTime=false +org.slf4j.simpleLogger.showShortLogName=true +org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS +org.slf4j.simpleLogger.levelInBrackets=true +org.slf4j.simpleLogger.defaultLogLevel=debug \ No newline at end of file diff --git a/collector/build.gradle b/collector/build.gradle new file mode 100644 index 0000000..e04115a --- /dev/null +++ b/collector/build.gradle @@ -0,0 +1,35 @@ +plugins { + id 'groovy' + id 'application' +} + +repositories { + // Use Maven Central for resolving dependencies. + mavenCentral() +} + +dependencies { + implementation project(':shared') + implementation "org.slf4j:slf4j-api:${slf4jVersion}" + implementation "org.slf4j:slf4j-simple:${slf4jVersion}" + + implementation group: 'org.apache.camel', name: 'camel-core', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-rest', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-jetty', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-jackson', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-main', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-bean', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-timer', version: '3.7.3' + implementation group: 'org.apache.camel', name: 'camel-stream', version: '3.7.3' +} + + +application { + // Define the main class for the application. + mainClassName = 'org.sysmon.collector.Application' +} + +tasks.named('test') { + // Use junit platform for unit tests. + useJUnitPlatform() +} diff --git a/collector/src/main/java/org/sysmon/collector/Application.java b/collector/src/main/java/org/sysmon/collector/Application.java new file mode 100644 index 0000000..4bb1ba3 --- /dev/null +++ b/collector/src/main/java/org/sysmon/collector/Application.java @@ -0,0 +1,19 @@ +package org.sysmon.collector; + +import org.apache.camel.main.Main; + +public class Application { + + public static void main(String[] args) { + Main main = new Main(); + main.configure().addRoutesBuilder(CollectorRouteBuilder.class); + + // now keep the application running until the JVM is terminated (ctrl + c or sigterm) + try { + main.run(args); + } catch (Exception e) { + System.err.println(e.getMessage()); + } + + } +} diff --git a/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java b/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java new file mode 100644 index 0000000..f86d862 --- /dev/null +++ b/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java @@ -0,0 +1,34 @@ +package org.sysmon.collector; + + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.rest.RestBindingMode; +import org.sysmon.shared.dto.MetricMessageDTO; + +public class CollectorRouteBuilder extends RouteBuilder { + + @Override + public void configure() throws Exception { + restConfiguration().component("jetty") + .bindingMode(RestBindingMode.auto) + .host("127.0.0.1") + .port(9925); + + rest() + .get("/") + .produces("text/html") + .route() + .to("log:stdout") + .endRest(); + + rest() + .post("/metrics") + .consumes("application/json") + .produces("text/html") + .type(MetricMessageDTO.class) + .route() + .to("bean:incomingMetricProcessor") + .endRest(); + } + +} diff --git a/collector/src/main/java/org/sysmon/collector/bean/Hello.java b/collector/src/main/java/org/sysmon/collector/bean/Hello.java new file mode 100644 index 0000000..44e2c83 --- /dev/null +++ b/collector/src/main/java/org/sysmon/collector/bean/Hello.java @@ -0,0 +1,21 @@ +package org.sysmon.collector.bean; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; + +public class Hello implements Processor { + + private final static Logger log = LoggerFactory.getLogger(Hello.class); + + public void process(Exchange exchange) throws Exception { + String name = exchange.getIn().getHeader("name", String.class); + String msg = "Hello " + Objects.requireNonNull(name, "universe"); + log.info(msg); + + exchange.getMessage().setBody(msg); + } +} \ No newline at end of file diff --git a/collector/src/main/java/org/sysmon/collector/bean/IncomingMetricProcessor.java b/collector/src/main/java/org/sysmon/collector/bean/IncomingMetricProcessor.java new file mode 100644 index 0000000..d3752aa --- /dev/null +++ b/collector/src/main/java/org/sysmon/collector/bean/IncomingMetricProcessor.java @@ -0,0 +1,23 @@ +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.dto.MetricMessageDTO; + +public class IncomingMetricProcessor implements Processor { + + private final static Logger log = LoggerFactory.getLogger(IncomingMetricProcessor.class); + + public void process(Exchange exchange) throws Exception { + + MetricMessageDTO payload = exchange.getIn().getBody(MetricMessageDTO.class); + log.info("I am going to send this data to InfluxDB."); + log.info(payload.toString()); + + exchange.getMessage().setBody("OK"); + } + + +} diff --git a/collector/src/main/resources/application.properties b/collector/src/main/resources/application.properties new file mode 100644 index 0000000..0da8a68 --- /dev/null +++ b/collector/src/main/resources/application.properties @@ -0,0 +1,43 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +# to configure camel main +# here you can configure options on camel main (see MainConfigurationProperties class) +camel.main.name = SysMon-Collector + +# enable tracing +camel.main.tracing = true + +# bean introspection to log reflection based configuration +camel.main.beanIntrospectionExtendedStatistics=true +camel.main.beanIntrospectionLoggingLevel=INFO + +# run in lightweight mode to be tiny as possible +camel.main.lightweight = true +# and eager load classes +#camel.main.eager-classloading = true + +# use object pooling to reduce JVM garbage collection +#camel.main.exchange-factory = pooled +#camel.main.exchange-factory-statistics-enabled = true + +# can be used to not start the route +# 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 diff --git a/collector/src/main/resources/simplelogger.properties b/collector/src/main/resources/simplelogger.properties new file mode 100644 index 0000000..df664d0 --- /dev/null +++ b/collector/src/main/resources/simplelogger.properties @@ -0,0 +1,6 @@ +org.slf4j.simpleLogger.logFile=System.out +org.slf4j.simpleLogger.showDateTime=true +org.slf4j.simpleLogger.showShortLogName=true +org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS +org.slf4j.simpleLogger.levelInBrackets=true +org.slf4j.simpleLogger.defaultLogLevel=info diff --git a/collector/src/test/resources/simplelogger.properties b/collector/src/test/resources/simplelogger.properties new file mode 100644 index 0000000..603d7a6 --- /dev/null +++ b/collector/src/test/resources/simplelogger.properties @@ -0,0 +1,6 @@ +org.slf4j.simpleLogger.logFile=System.err +org.slf4j.simpleLogger.showDateTime=false +org.slf4j.simpleLogger.showShortLogName=true +org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS +org.slf4j.simpleLogger.levelInBrackets=true +org.slf4j.simpleLogger.defaultLogLevel=debug \ No newline at end of file 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 fd766ac..598593f 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 @@ -13,8 +13,13 @@ public class AixDiskExtension implements MetricExtension { } @Override - public String getGreeting() { - return "Welcome from AIX DiskMetric"; + public String getName() { + return "aix-disk"; + } + + @Override + public String getDescription() { + return "AIX Disk Metrics (TODO)"; } @Override diff --git a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixPlugin.java b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixPlugin.java index a210e43..11f279d 100644 --- a/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixPlugin.java +++ b/plugins/sysmon-aix/src/main/java/org/sysmon/plugins/sysmon_aix/AixPlugin.java @@ -1,6 +1,5 @@ package org.sysmon.plugins.sysmon_aix; -import org.pf4j.PluginState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.pf4j.Plugin; @@ -14,23 +13,6 @@ public class AixPlugin extends Plugin { super(wrapper); } - @Override - public void start() { - if(!System.getProperty("os.name").toLowerCase().contains("aix")) { - log.warn("start() - Plugin not supported here."); - wrapper.setPluginState(PluginState.DISABLED); - wrapper.getPlugin().stop(); - } else { - log.info("start() - Good to go."); - } - } - - @Override - public void stop() { - log.debug("stop()"); - } - - } 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 971d67d..7a7b506 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 @@ -22,8 +22,13 @@ public class AixProcessorExtension implements MetricExtension { } @Override - public String getGreeting() { - return "Welcome from AIX ProcessorMetric"; + public String getName() { + return "aix-processor"; + } + + @Override + public String getDescription() { + return "AIX Processor Metrics"; } @Override 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 777a83f..5022f06 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 @@ -24,8 +24,13 @@ public class LinuxDiskExtension implements MetricExtension { } @Override - public String getGreeting() { - return "Welcome from Linux DiskMetric"; + public String getName() { + return "linux-disk"; + } + + @Override + public String getDescription() { + return "Linux Disk Metrics"; } @Override 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 a5871ec..faeccdf 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 @@ -25,8 +25,13 @@ public class LinuxMemoryExtension implements MetricExtension { } @Override - public String getGreeting() { - return "Welcome from Linux MemoryMetric"; + public String getName() { + return "linux-memory"; + } + + @Override + public String getDescription() { + return "Linux Memory Metrics"; } diff --git a/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxPlugin.java b/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxPlugin.java index ef2139d..515156b 100644 --- a/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxPlugin.java +++ b/plugins/sysmon-linux/src/main/java/org/sysmon/plugins/sysmon_linux/LinuxPlugin.java @@ -1,6 +1,5 @@ package org.sysmon.plugins.sysmon_linux; -import org.pf4j.PluginState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.pf4j.Plugin; @@ -15,21 +14,4 @@ public class LinuxPlugin extends Plugin { super(wrapper); } - @Override - public void start() { - if(!System.getProperty("os.name").toLowerCase().contains("linux")) { - log.warn("start() - Plugin not supported here."); - wrapper.setPluginState(PluginState.DISABLED); - } else { - log.info("start() - Good to go."); - } - } - - @Override - public void stop() { - log.debug("stop()"); - } - - - } 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 50fbdcb..a9670ed 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 @@ -29,10 +29,14 @@ public class LinuxProcessorExtension implements MetricExtension { return System.getProperty("os.name").toLowerCase().contains("linux"); } + @Override + public String getName() { + return "linux-processor"; + } @Override - public String getGreeting() { - return "Welcome from Linux ProcessorMetric"; + public String getDescription() { + return "Linux Processor Metrics"; } diff --git a/settings.gradle b/settings.gradle index 7523a79..6985859 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,7 +8,7 @@ */ rootProject.name = 'sysmon' -include('shared', 'agent', 'plugins') +include('shared', 'agent', 'collector', 'plugins') new File(rootDir, "plugins").listFiles().each { diff --git a/shared/src/main/java/org/sysmon/shared/MetricBean.java b/shared/src/main/java/org/sysmon/shared/MetricBean.java deleted file mode 100644 index b51c8e3..0000000 --- a/shared/src/main/java/org/sysmon/shared/MetricBean.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sysmon.shared; - -import java.util.concurrent.Callable; - -public interface MetricBean { - - public MetricResult getMetrics(); - -} diff --git a/shared/src/main/java/org/sysmon/shared/MetricExtension.java b/shared/src/main/java/org/sysmon/shared/MetricExtension.java index 47b3d3f..95a2081 100644 --- a/shared/src/main/java/org/sysmon/shared/MetricExtension.java +++ b/shared/src/main/java/org/sysmon/shared/MetricExtension.java @@ -5,7 +5,10 @@ import org.pf4j.ExtensionPoint; public interface MetricExtension extends ExtensionPoint { boolean isSupported(); - String getGreeting(); + + String getName(); + String getDescription(); + MetricResult getMetrics(); } diff --git a/shared/src/main/java/org/sysmon/shared/SysmonPlugin.java b/shared/src/main/java/org/sysmon/shared/SysmonPlugin.java deleted file mode 100644 index 9603038..0000000 --- a/shared/src/main/java/org/sysmon/shared/SysmonPlugin.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.sysmon.shared; - -import org.pf4j.Plugin; -import org.pf4j.PluginWrapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SysmonPlugin extends Plugin { - - private static final Logger log = LoggerFactory.getLogger(SysmonPlugin.class); - - public SysmonPlugin(PluginWrapper wrapper) { - super(wrapper); - log.warn("SysmonPlugin"); - } - - @Override - public void start() { - log.warn("start();"); - } - - - -} diff --git a/shared/src/main/java/org/sysmon/shared/dto/MetricMessageDTO.java b/shared/src/main/java/org/sysmon/shared/dto/MetricMessageDTO.java new file mode 100644 index 0000000..5450ad9 --- /dev/null +++ b/shared/src/main/java/org/sysmon/shared/dto/MetricMessageDTO.java @@ -0,0 +1,45 @@ +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 + + '}'; + } + +}