Initial command line options.
This commit is contained in:
parent
d1fc7582ac
commit
0dcd02e2b5
|
@ -1,5 +1,9 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'application'
|
id 'application'
|
||||||
|
|
||||||
|
id "com.github.johnrengelman.shadow" version "6.1.0"
|
||||||
|
id "net.nemerosa.versioning" version "2.14.0"
|
||||||
|
id "nebula.ospackage" version "8.4.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -9,6 +13,9 @@ dependencies {
|
||||||
annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}")
|
annotationProcessor(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}")
|
||||||
implementation group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}"
|
implementation group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}"
|
||||||
|
|
||||||
|
annotationProcessor "info.picocli:picocli-codegen:${picocliVersion}"
|
||||||
|
implementation "info.picocli:picocli:${picocliVersion}"
|
||||||
|
|
||||||
implementation group: 'org.apache.camel', name: 'camel-core', version: camelVersion
|
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-main', version: camelVersion
|
||||||
implementation group: 'org.apache.camel', name: 'camel-http', version: camelVersion
|
implementation group: 'org.apache.camel', name: 'camel-http', version: camelVersion
|
||||||
|
@ -31,3 +38,54 @@ tasks.named('test') {
|
||||||
// Use junit platform for unit tests.
|
// Use junit platform for unit tests.
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
apply plugin: 'nebula.ospackage'
|
||||||
|
ospackage {
|
||||||
|
packageName = 'sysmon-client'
|
||||||
|
release = '1'
|
||||||
|
user = 'root'
|
||||||
|
packager = "Mark Nellemann <mark.nellemann@gmail.com>"
|
||||||
|
|
||||||
|
into '/opt/sysmon-client'
|
||||||
|
|
||||||
|
from(shadowJar.outputs.files) {
|
||||||
|
into 'lib'
|
||||||
|
}
|
||||||
|
|
||||||
|
from('build/scriptsShadow') {
|
||||||
|
into 'bin'
|
||||||
|
}
|
||||||
|
|
||||||
|
from('doc/') {
|
||||||
|
into 'doc'
|
||||||
|
}
|
||||||
|
|
||||||
|
from(['README.md', 'LICENSE']) {
|
||||||
|
into 'doc'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
buildRpm {
|
||||||
|
dependsOn startShadowScripts
|
||||||
|
os = "LINUX"
|
||||||
|
}
|
||||||
|
|
||||||
|
buildDeb {
|
||||||
|
dependsOn startShadowScripts
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
'Created-By' : "Gradle ${gradle.gradleVersion}",
|
||||||
|
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}",
|
||||||
|
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
|
||||||
|
'Build-User' : System.properties['user.name'],
|
||||||
|
'Build-Version' : versioning.info.tag ?: (versioning.info.branch + "-" + versioning.info.build),
|
||||||
|
'Build-Revision' : versioning.info.commit,
|
||||||
|
'Build-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ").toString(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -4,62 +4,42 @@
|
||||||
package org.sysmon.client;
|
package org.sysmon.client;
|
||||||
|
|
||||||
import org.apache.camel.main.Main;
|
import org.apache.camel.main.Main;
|
||||||
import org.slf4j.Logger;
|
import picocli.CommandLine;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
public class Application {
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(Application.class);
|
@CommandLine.Command(name = "sysmon-client", mixinStandardHelpOptions = true)
|
||||||
|
public class Application implements Callable<Integer> {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
@CommandLine.Option(names = { "-s", "--server-url" }, description = "Server URL [default: 'http://127.0.0.1:9925/metrics'].", defaultValue = "http://127.0.0.1:9925/metrics", paramLabel = "<url>")
|
||||||
|
private URL serverUrl;
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
int exitCode = new CommandLine(new Application()).execute(args);
|
||||||
|
System.exit(exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer call() throws IOException {
|
||||||
|
|
||||||
// use Camels Main class
|
|
||||||
Main main = new Main();
|
Main main = new Main();
|
||||||
|
main.bind("myServerUrl", serverUrl.toString());
|
||||||
// and add the routes (you can specify multiple classes)
|
main.configure().addRoutesBuilder(ClientRouteBuilder.class);
|
||||||
main.configure().addRoutesBuilder(AgentRouteBuilder.class);
|
|
||||||
|
|
||||||
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
|
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
|
||||||
try {
|
try {
|
||||||
main.run(args);
|
main.run();
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
/*
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
|
||||||
|
|
||||||
// create the plugin manager
|
|
||||||
PluginManager pluginManager = new JarPluginManager(); // or "new ZipPluginManager() / new DefaultPluginManager()"
|
|
||||||
|
|
||||||
// start and load all plugins of application
|
|
||||||
pluginManager.loadPlugins();
|
|
||||||
pluginManager.startPlugins();
|
|
||||||
|
|
||||||
|
|
||||||
List<MetricExtension> 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(">>> " + ext.getGreeting());
|
|
||||||
|
|
||||||
// TODO: Setup camel
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AtomicBoolean keepRunning = new AtomicBoolean(true);
|
|
||||||
Thread shutdownHook = new Thread(() -> {
|
|
||||||
keepRunning.set(false);
|
|
||||||
pluginManager.stopPlugins();
|
|
||||||
System.out.println("Stopping sysmon, please wait ...");
|
|
||||||
});
|
|
||||||
Runtime.getRuntime().addShutdownHook(shutdownHook);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.sysmon.client;
|
||||||
import org.apache.camel.Exchange;
|
import org.apache.camel.Exchange;
|
||||||
import org.apache.camel.builder.RouteBuilder;
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
import org.apache.camel.model.dataformat.JsonLibrary;
|
import org.apache.camel.model.dataformat.JsonLibrary;
|
||||||
|
import org.apache.camel.spi.Registry;
|
||||||
import org.pf4j.JarPluginManager;
|
import org.pf4j.JarPluginManager;
|
||||||
import org.pf4j.PluginManager;
|
import org.pf4j.PluginManager;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -12,13 +13,15 @@ import org.sysmon.shared.MetricResult;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AgentRouteBuilder extends RouteBuilder {
|
public class ClientRouteBuilder extends RouteBuilder {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(AgentRouteBuilder.class);
|
private static final Logger log = LoggerFactory.getLogger(ClientRouteBuilder.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure() throws Exception {
|
public void configure() throws Exception {
|
||||||
|
|
||||||
|
Registry registry = getContext().getRegistry();
|
||||||
|
|
||||||
PluginManager pluginManager = new JarPluginManager();
|
PluginManager pluginManager = new JarPluginManager();
|
||||||
pluginManager.loadPlugins();
|
pluginManager.loadPlugins();
|
||||||
pluginManager.startPlugins();
|
pluginManager.startPlugins();
|
||||||
|
@ -50,7 +53,7 @@ public class AgentRouteBuilder extends RouteBuilder {
|
||||||
.doTry()
|
.doTry()
|
||||||
//.process(new MetricProcessor())
|
//.process(new MetricProcessor())
|
||||||
.marshal().json(JsonLibrary.Jackson, MetricResult.class)
|
.marshal().json(JsonLibrary.Jackson, MetricResult.class)
|
||||||
.to("http://127.0.0.1:9925/metrics")
|
.to((String)registry.lookupByName("myServerUrl"))
|
||||||
.doCatch(Exception.class)
|
.doCatch(Exception.class)
|
||||||
.log("Error: ${exception.message}")
|
.log("Error: ${exception.message}")
|
||||||
//.log("Error sending metric to collector: ${body}")
|
//.log("Error sending metric to collector: ${body}")
|
|
@ -1,3 +1,4 @@
|
||||||
pf4jVersion=3.6.0
|
pf4jVersion=3.6.0
|
||||||
slf4jVersion=1.7.30
|
slf4jVersion=1.7.30
|
||||||
camelVersion=3.7.3
|
camelVersion=3.7.3
|
||||||
|
picocliVersion=4.6.1
|
|
@ -1,11 +1,18 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'application'
|
id 'application'
|
||||||
|
|
||||||
|
id "com.github.johnrengelman.shadow" version "6.1.0"
|
||||||
|
id "net.nemerosa.versioning" version "2.14.0"
|
||||||
|
id "nebula.ospackage" version "8.4.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation project(':shared')
|
testImplementation project(':shared')
|
||||||
implementation project(':shared')
|
implementation project(':shared')
|
||||||
|
|
||||||
|
annotationProcessor "info.picocli:picocli-codegen:${picocliVersion}"
|
||||||
|
implementation "info.picocli:picocli:${picocliVersion}"
|
||||||
|
|
||||||
implementation group: 'org.apache.camel', name: 'camel-core', version: camelVersion
|
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-main', version: camelVersion
|
||||||
implementation group: 'org.apache.camel', name: 'camel-rest', version: camelVersion
|
implementation group: 'org.apache.camel', name: 'camel-rest', version: camelVersion
|
||||||
|
@ -24,3 +31,53 @@ tasks.named('test') {
|
||||||
// Use junit platform for unit tests.
|
// Use junit platform for unit tests.
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apply plugin: 'nebula.ospackage'
|
||||||
|
ospackage {
|
||||||
|
packageName = 'sysmon-server'
|
||||||
|
release = '1'
|
||||||
|
user = 'root'
|
||||||
|
packager = "Mark Nellemann <mark.nellemann@gmail.com>"
|
||||||
|
|
||||||
|
into '/opt/sysmon-server'
|
||||||
|
|
||||||
|
from(shadowJar.outputs.files) {
|
||||||
|
into 'lib'
|
||||||
|
}
|
||||||
|
|
||||||
|
from('build/scriptsShadow') {
|
||||||
|
into 'bin'
|
||||||
|
}
|
||||||
|
|
||||||
|
from('doc/') {
|
||||||
|
into 'doc'
|
||||||
|
}
|
||||||
|
|
||||||
|
from(['README.md', 'LICENSE']) {
|
||||||
|
into 'doc'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
buildRpm {
|
||||||
|
dependsOn startShadowScripts
|
||||||
|
os = "LINUX"
|
||||||
|
}
|
||||||
|
|
||||||
|
buildDeb {
|
||||||
|
dependsOn startShadowScripts
|
||||||
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
'Created-By' : "Gradle ${gradle.gradleVersion}",
|
||||||
|
'Build-OS' : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}",
|
||||||
|
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
|
||||||
|
'Build-User' : System.properties['user.name'],
|
||||||
|
'Build-Version' : versioning.info.tag ?: (versioning.info.branch + "-" + versioning.info.build),
|
||||||
|
'Build-Revision' : versioning.info.commit,
|
||||||
|
'Build-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ").toString(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,25 +3,54 @@ package org.sysmon.server;
|
||||||
import org.apache.camel.main.Main;
|
import org.apache.camel.main.Main;
|
||||||
import org.influxdb.InfluxDB;
|
import org.influxdb.InfluxDB;
|
||||||
import org.influxdb.InfluxDBFactory;
|
import org.influxdb.InfluxDBFactory;
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
public class Application {
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
@CommandLine.Command(name = "sysmon-server", mixinStandardHelpOptions = true)
|
||||||
|
public class Application implements Callable<Integer> {
|
||||||
|
|
||||||
InfluxDB influxConnectionBean = InfluxDBFactory.connect("http://localhost:8086", "root", "");
|
@CommandLine.Option(names = { "-i", "--influxdb-url" }, description = "InfluxDB URL [default: 'http://localhost:8086'].", defaultValue = "http://localhost:8086", paramLabel = "<url>")
|
||||||
|
private URL influxUrl;
|
||||||
|
|
||||||
|
@CommandLine.Option(names = { "-u", "--influxdb-user" }, description = "InfluxDB User [default: 'root'].", defaultValue = "root", paramLabel = "<user>")
|
||||||
|
private String influxUser;
|
||||||
|
|
||||||
|
@CommandLine.Option(names = { "-p", "--influxdb-pass" }, description = "InfluxDB Password [default: ''].", defaultValue = "", paramLabel = "<pass>")
|
||||||
|
private String influxPass;
|
||||||
|
|
||||||
|
@CommandLine.Option(names = { "-l", "--listen-port" }, description = "Listening port [default: '9925'].", defaultValue = "9925", paramLabel = "<port>")
|
||||||
|
private String listenPort;
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String... args) {
|
||||||
|
int exitCode = new CommandLine(new Application()).execute(args);
|
||||||
|
System.exit(exitCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer call() throws IOException {
|
||||||
|
|
||||||
|
InfluxDB influxConnectionBean = InfluxDBFactory.connect(influxUrl.toString(), influxUser, influxPass);
|
||||||
|
|
||||||
Main main = new Main();
|
Main main = new Main();
|
||||||
main.bind("myInfluxConnection", influxConnectionBean);
|
main.bind("myInfluxConnection", influxConnectionBean);
|
||||||
main.configure().addRoutesBuilder(CollectorRouteBuilder.class);
|
main.bind("myListenPort", Integer.parseInt(listenPort));
|
||||||
|
main.configure().addRoutesBuilder(ServerRouteBuilder.class);
|
||||||
|
|
||||||
|
|
||||||
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
|
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
|
||||||
try {
|
try {
|
||||||
main.run(args);
|
main.run();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println(e.getMessage());
|
System.err.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,17 +2,20 @@ package org.sysmon.server;
|
||||||
|
|
||||||
import org.apache.camel.builder.RouteBuilder;
|
import org.apache.camel.builder.RouteBuilder;
|
||||||
import org.apache.camel.model.rest.RestBindingMode;
|
import org.apache.camel.model.rest.RestBindingMode;
|
||||||
|
import org.apache.camel.spi.Registry;
|
||||||
import org.sysmon.shared.MetricResult;
|
import org.sysmon.shared.MetricResult;
|
||||||
|
|
||||||
public class CollectorRouteBuilder extends RouteBuilder {
|
public class ServerRouteBuilder extends RouteBuilder {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure() throws Exception {
|
public void configure() throws Exception {
|
||||||
|
|
||||||
|
Registry registry = getContext().getRegistry();
|
||||||
|
|
||||||
restConfiguration().component("jetty")
|
restConfiguration().component("jetty")
|
||||||
.bindingMode(RestBindingMode.auto)
|
.bindingMode(RestBindingMode.auto)
|
||||||
.host("127.0.0.1")
|
.host("127.0.0.1")
|
||||||
.port(9925);
|
.port((Integer) registry.lookupByName("myListenPort"));
|
||||||
|
|
||||||
rest()
|
rest()
|
||||||
.get("/")
|
.get("/")
|
Loading…
Reference in a new issue