From 94eb0d17f9a5c56803e0ca4aabfe2d57ad3fb6cc Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Tue, 4 May 2021 17:54:47 +0200 Subject: [PATCH] Cleanup in build files. Handle errors in http route. Some steps towards influx in collector. --- agent/build.gradle | 29 +++++-------------- .../java/org/sysmon/agent/MyRouteBuilder.java | 6 +++- build.gradle | 12 ++++++-- collector/build.gradle | 27 +++++++---------- .../org/sysmon/collector/Application.java | 9 ++++++ .../collector/CollectorRouteBuilder.java | 11 ++++++- gradle.properties | 1 + plugins/build.gradle | 4 +-- 8 files changed, 53 insertions(+), 46 deletions(-) diff --git a/agent/build.gradle b/agent/build.gradle index d0fa9e9..e94b6ba 100644 --- a/agent/build.gradle +++ b/agent/build.gradle @@ -1,34 +1,21 @@ plugins { - id 'groovy' id 'application' } -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - dependencies { - testImplementation 'org.codehaus.groovy:groovy:3.0.7' - testImplementation 'org.spockframework:spock-core:2.0-M4-groovy-3.0' - testImplementation 'junit:junit:4.13.1' - testImplementation "org.slf4j:slf4j-api:${slf4jVersion}" testImplementation project(':shared') - implementation project(':shared') - implementation "org.slf4j:slf4j-api:${slf4jVersion}" - implementation "org.slf4j:slf4j-simple:${slf4jVersion}" 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' + implementation group: 'org.apache.camel', name: 'camel-core', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-main', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-http', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-jackson', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-bean', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-timer', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-stream', version: camelVersion } application { @@ -43,4 +30,4 @@ run { tasks.named('test') { // Use junit platform for unit tests. useJUnitPlatform() -} +} \ No newline at end of file diff --git a/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java b/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java index 4d513dc..c817150 100644 --- a/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java +++ b/agent/src/main/java/org/sysmon/agent/MyRouteBuilder.java @@ -78,7 +78,11 @@ public class MyRouteBuilder extends RouteBuilder { .process(new MetricProcessor()) .marshal().json() .setHeader(Exchange.HTTP_METHOD, constant("POST")) - .to("http://127.0.0.1:9925/metrics"); + .doTry() + .to("http://127.0.0.1:9925/metrics") + .doCatch(Exception.class) + .log("Error sending metric to collector.") + .end(); diff --git a/build.gradle b/build.gradle index f41962c..d40349a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,20 @@ subprojects { apply plugin: 'java' + apply plugin: 'groovy' dependencies { - testImplementation project(':shared') + testImplementation 'org.spockframework:spock-core:2.0-M5-groovy-3.0' + testImplementation "org.slf4j:slf4j-api:${slf4jVersion}" + + implementation "org.slf4j:slf4j-api:${slf4jVersion}" + implementation "org.slf4j:slf4j-simple:${slf4jVersion}" } repositories { mavenLocal() mavenCentral() } + + sourceCompatibility = 1.8 + targetCompatibility = 1.8 } - - diff --git a/collector/build.gradle b/collector/build.gradle index e04115a..78fc9c6 100644 --- a/collector/build.gradle +++ b/collector/build.gradle @@ -1,29 +1,22 @@ plugins { - id 'groovy' id 'application' } -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - dependencies { + testImplementation project(':shared') 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' + implementation group: 'org.apache.camel', name: 'camel-core', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-rest', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-jetty', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-jackson', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-main', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-bean', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-timer', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-stream', version: camelVersion + implementation group: 'org.apache.camel', name: 'camel-influxdb', version: camelVersion } - application { // Define the main class for the application. mainClassName = 'org.sysmon.collector.Application' diff --git a/collector/src/main/java/org/sysmon/collector/Application.java b/collector/src/main/java/org/sysmon/collector/Application.java index 4bb1ba3..ee3e6d5 100644 --- a/collector/src/main/java/org/sysmon/collector/Application.java +++ b/collector/src/main/java/org/sysmon/collector/Application.java @@ -1,13 +1,21 @@ package org.sysmon.collector; import org.apache.camel.main.Main; +import org.apache.camel.support.SimpleRegistry; +import org.influxdb.InfluxDB; +import org.influxdb.InfluxDBFactory; public class Application { public static void main(String[] args) { + + InfluxDB influxConnectionBean = InfluxDBFactory.connect("http://localhost:8086", "root", ""); + Main main = new Main(); + main.bind("myInfluxConnection", influxConnectionBean); main.configure().addRoutesBuilder(CollectorRouteBuilder.class); + // now keep the application running until the JVM is terminated (ctrl + c or sigterm) try { main.run(args); @@ -16,4 +24,5 @@ public class Application { } } + } diff --git a/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java b/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java index f86d862..7702ef5 100644 --- a/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java +++ b/collector/src/main/java/org/sysmon/collector/CollectorRouteBuilder.java @@ -1,6 +1,5 @@ package org.sysmon.collector; - import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.rest.RestBindingMode; import org.sysmon.shared.dto.MetricMessageDTO; @@ -9,6 +8,7 @@ public class CollectorRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { + restConfiguration().component("jetty") .bindingMode(RestBindingMode.auto) .host("127.0.0.1") @@ -28,7 +28,16 @@ public class CollectorRouteBuilder extends RouteBuilder { .type(MetricMessageDTO.class) .route() .to("bean:incomingMetricProcessor") + .to("seda:inbound") .endRest(); + + /* + from("seda:inbound") + .to("influxdb://myInfluxConnection?databaseName=sysmon"); + */ + } + + } diff --git a/gradle.properties b/gradle.properties index 6b9bbe0..c4590bc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,3 @@ pf4jVersion=3.6.0 slf4jVersion=1.7.30 +camelVersion=3.7.3 \ No newline at end of file diff --git a/plugins/build.gradle b/plugins/build.gradle index 74113f6..bf0fdff 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -3,8 +3,7 @@ subprojects { apply plugin: 'groovy' dependencies { - - testImplementation 'org.spockframework:spock-core:2.0-M4-groovy-3.0' + testImplementation 'org.spockframework:spock-core:2.0-M5-groovy-3.0' testImplementation "org.slf4j:slf4j-api:${slf4jVersion}" testImplementation project(':shared') @@ -14,7 +13,6 @@ subprojects { } annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") implementation "org.slf4j:slf4j-api:${slf4jVersion}" - } jar {