diff --git a/gradle.properties b/gradle.properties index 9ad9b18..d015b8f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -version=0.0.5 +version=0.0.6 pf4jVersion=3.6.0 -slf4jVersion=1.7.30 -camelVersion=3.10.0 +slf4jVersion=1.7.31 +camelVersion=3.11.0 picocliVersion=4.6.1 oshiVersion=5.7.5 \ No newline at end of file diff --git a/server/src/main/java/sysmon/server/Application.java b/server/src/main/java/sysmon/server/Application.java index dd22e72..2328896 100644 --- a/server/src/main/java/sysmon/server/Application.java +++ b/server/src/main/java/sysmon/server/Application.java @@ -2,7 +2,9 @@ package sysmon.server; import org.apache.camel.main.Main; import org.influxdb.InfluxDB; +import org.influxdb.InfluxDBException; import org.influxdb.InfluxDBFactory; +import org.influxdb.dto.Query; import picocli.CommandLine; import java.io.IOException; @@ -21,8 +23,8 @@ public class Application implements Callable { @CommandLine.Option(names = { "-p", "--influxdb-pass" }, description = "InfluxDB Password (default: ${DEFAULT-VALUE}).", defaultValue = "", paramLabel = "") private String influxPass; - //@CommandLine.Option(names = { "-d", "--influxdb-db" }, description = "InfluxDB Database (default: ${DEFAULT-VALUE}).", defaultValue = "", paramLabel = "") - //private String influxName = "sysmon"; + @CommandLine.Option(names = { "-d", "--influxdb-db" }, description = "InfluxDB Database (default: ${DEFAULT-VALUE}).", defaultValue = "sysmon", paramLabel = "") + private String influxName; @CommandLine.Option(names = { "-H", "--server-host" }, description = "Server listening address (default: ${DEFAULT-VALUE}).", paramLabel = "") private String listenHost = "0.0.0.0"; @@ -42,20 +44,21 @@ public class Application implements Callable { @Override public Integer call() throws IOException { + InfluxDB influxDB = InfluxDBFactory.connect(influxUrl.toString(), influxUser, influxPass); /* - Properties properties = new Properties(); - properties.put("http.host", listenHost); - properties.put("http.port", listenPort); -*/ - InfluxDB influxConnectionBean = InfluxDBFactory.connect(influxUrl.toString(), influxUser, influxPass); + try { + influxDB.query(new Query("CREATE DATABASE " + influxName)); + } catch (InfluxDBException e) { + System.err.println(e.getMessage()); + return -1; + }*/ Main main = new Main(); - main.bind("myInfluxConnection", influxConnectionBean); + main.bind("myInfluxConnection", influxDB); main.bind("http.host", listenHost); main.bind("http.port", listenPort); - //main.bind("properties", properties); main.bind("threads", threads); - //main.bind("influxdb_name", influxName); + main.bind("dbname", influxName); main.configure().addRoutesBuilder(ServerRouteBuilder.class); // now keep the application running until the JVM is terminated (ctrl + c or sigterm) diff --git a/server/src/main/java/sysmon/server/ServerRouteBuilder.java b/server/src/main/java/sysmon/server/ServerRouteBuilder.java index 5bfc315..0cc0f39 100644 --- a/server/src/main/java/sysmon/server/ServerRouteBuilder.java +++ b/server/src/main/java/sysmon/server/ServerRouteBuilder.java @@ -2,6 +2,7 @@ package sysmon.server; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.influxdb.InfluxDbConstants; import org.apache.camel.model.rest.RestBindingMode; import org.apache.camel.spi.Registry; import sysmon.shared.MetricResult; @@ -11,7 +12,9 @@ public class ServerRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { - Registry registry = getContext().getRegistry(); + final Registry registry = getContext().getRegistry(); + final String dbname = registry.lookupByNameAndType("dbname", String.class); + final Integer threads = registry.lookupByNameAndType("threads", Integer.class); restConfiguration().component("netty-http") .bindingMode(RestBindingMode.auto) @@ -38,11 +41,11 @@ public class ServerRouteBuilder extends RouteBuilder { .to("seda:inbound") .endRest(); - fromF("seda:inbound?concurrentConsumers=%s", registry.lookupByNameAndType("threads", Integer.class)) + fromF("seda:inbound?concurrentConsumers=%s", threads) .log(">>> metric: ${header.hostname} - ${body}") .doTry() .process(new MetricResultToPointProcessor()) - .toF("influxdb://ref.myInfluxConnection?databaseName=%s&retentionPolicy=autogen", "sysmon") + .toF("influxdb://ref.myInfluxConnection?databaseName=%s&retentionPolicy=autogen", dbname) .doCatch(Exception.class) .log("Error storing metric to InfluxDB: ${exception}") .end();