Cleanup and option for debug logging.
This commit is contained in:
parent
731d8b8d10
commit
ea5d17bc5c
|
@ -1,12 +1,19 @@
|
|||
# Configuration for sysmon-client
|
||||
|
||||
[extension.base_filesystem]
|
||||
###
|
||||
### Sysmon Client
|
||||
###
|
||||
### Example configuration with default values.
|
||||
###
|
||||
|
||||
[extension.base_disk]
|
||||
enabled = true
|
||||
|
||||
[extension.base_filesystem]
|
||||
enabled = true
|
||||
exclude_type = [ "tmpfs", "ahafs" ]
|
||||
exclude_mount = [ "/boot/efi" ]
|
||||
|
||||
[extension.base_process]
|
||||
enabled = true
|
||||
include = [ "java", "influxd", "grafana-server" ]
|
||||
include = [ "java", "mysqld", "postgres", "influxd" ]
|
||||
|
||||
|
||||
|
|
|
@ -42,12 +42,12 @@ public class Application implements Callable<Integer> {
|
|||
@Override
|
||||
public Integer call() throws IOException {
|
||||
|
||||
Configuration configuration = new Configuration();
|
||||
|
||||
if(enableDebug) {
|
||||
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
|
||||
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");
|
||||
}
|
||||
|
||||
Configuration configuration = new Configuration();
|
||||
|
||||
if(hostname == null || hostname.isEmpty()) {
|
||||
try {
|
||||
hostname = InetAddress.getLocalHost().getHostName();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package sysmon.client;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.LoggingLevel;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.model.dataformat.JsonLibrary;
|
||||
import org.apache.camel.spi.Registry;
|
||||
|
@ -64,7 +65,7 @@ public class ClientRouteBuilder extends RouteBuilder {
|
|||
.outputType(MetricResult.class)
|
||||
.process(new MetricEnrichProcessor(registry))
|
||||
.choice().when(exchangeProperty("skip").isEqualTo(true))
|
||||
.log("Skipping empty measurement.")
|
||||
.log(LoggingLevel.WARN,"Skipping empty measurement.")
|
||||
.stop()
|
||||
.otherwise()
|
||||
.to("seda:metrics?discardWhenFull=true");
|
||||
|
@ -84,7 +85,7 @@ public class ClientRouteBuilder extends RouteBuilder {
|
|||
.marshal().json(JsonLibrary.Jackson, MetricResult.class)
|
||||
.to((String)registry.lookupByName("myServerUrl"))
|
||||
.doCatch(Exception.class)
|
||||
.log("Error: ${exception.message}")
|
||||
.log(LoggingLevel.WARN,"Error: ${exception.message}")
|
||||
//.log("Error sending metric to collector: ${body}")
|
||||
.end();
|
||||
|
||||
|
|
|
@ -30,15 +30,3 @@ camel.main.name = sysmon-client
|
|||
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.client.MetricProcessor
|
||||
|
||||
#camel.dataformat.json-jackson.use-list = true
|
|
@ -3,4 +3,4 @@ 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
|
||||
org.slf4j.simpleLogger.defaultLogLevel=warn
|
||||
|
|
|
@ -25,6 +25,9 @@ public class BaseProcessExtension implements MetricExtension {
|
|||
private boolean enabled = true;
|
||||
private List<?> includeList = new ArrayList<Object>() {{
|
||||
add("java");
|
||||
add("mysqld");
|
||||
add("postgres");
|
||||
add("influxd");
|
||||
}};
|
||||
|
||||
private SystemInfo systemInfo;
|
||||
|
@ -63,9 +66,9 @@ public class BaseProcessExtension implements MetricExtension {
|
|||
if(map.containsKey("include")) {
|
||||
includeList = (List<?>) map.get("include");
|
||||
}
|
||||
log.info(includeList.toString());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public MetricResult getMetrics() {
|
||||
|
||||
|
@ -85,23 +88,24 @@ public class BaseProcessExtension implements MetricExtension {
|
|||
}
|
||||
log.debug("pid: " + p.getProcessID() + ", name: " + name + ", virt: " + p.getVirtualSize() + " rss: " + p.getResidentSetSize());
|
||||
|
||||
HashMap<String, String> tagsMap = new HashMap<>();
|
||||
HashMap<String, Object> fieldsMap = new HashMap<>();
|
||||
HashMap<String, String> tagsMap = new HashMap<String, String>() {{
|
||||
put("pid", String.valueOf(p.getProcessID()));
|
||||
put("name", name);
|
||||
}};
|
||||
|
||||
tagsMap.put("pid", String.valueOf(p.getProcessID()));
|
||||
tagsMap.put("name", name);
|
||||
|
||||
fieldsMap.put("mem_rss", p.getResidentSetSize());
|
||||
fieldsMap.put("mem_vsz", p.getVirtualSize());
|
||||
fieldsMap.put("kernel_time", p.getKernelTime());
|
||||
fieldsMap.put("user_time", p.getUserTime());
|
||||
fieldsMap.put("read_bytes", p.getBytesRead());
|
||||
fieldsMap.put("write_bytes", p.getBytesWritten());
|
||||
fieldsMap.put("files", p.getOpenFiles());
|
||||
fieldsMap.put("threads", p.getThreadCount());
|
||||
fieldsMap.put("user", p.getUser());
|
||||
fieldsMap.put("group", p.getGroup());
|
||||
fieldsMap.put("prio", p.getPriority());
|
||||
HashMap<String, Object> fieldsMap = new HashMap<String, Object>() {{
|
||||
put("mem_rss", p.getResidentSetSize());
|
||||
put("mem_vsz", p.getVirtualSize());
|
||||
put("kernel_time", p.getKernelTime());
|
||||
put("user_time", p.getUserTime());
|
||||
put("read_bytes", p.getBytesRead());
|
||||
put("write_bytes", p.getBytesWritten());
|
||||
put("files", p.getOpenFiles());
|
||||
put("threads", p.getThreadCount());
|
||||
put("user", p.getUser());
|
||||
put("group", p.getGroup());
|
||||
put("prio", p.getPriority());
|
||||
}};
|
||||
|
||||
measurementList.add(new Measurement(tagsMap, fieldsMap));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package sysmon.server;
|
|||
import org.apache.camel.main.Main;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.InfluxDBFactory;
|
||||
import org.slf4j.impl.SimpleLogger;
|
||||
import picocli.CommandLine;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -21,7 +22,7 @@ public class Application implements Callable<Integer> {
|
|||
@CommandLine.Option(names = { "-p", "--influxdb-pass" }, description = "InfluxDB Password (default: ${DEFAULT-VALUE}).", defaultValue = "", paramLabel = "<pass>")
|
||||
private String influxPass;
|
||||
|
||||
@CommandLine.Option(names = { "-d", "--influxdb-db" }, description = "InfluxDB Database (default: ${DEFAULT-VALUE}).", defaultValue = "sysmon", paramLabel = "<db>")
|
||||
@CommandLine.Option(names = { "-n", "--influxdb-db" }, description = "InfluxDB Database (default: ${DEFAULT-VALUE}).", defaultValue = "sysmon", paramLabel = "<db>")
|
||||
private String influxName;
|
||||
|
||||
@CommandLine.Option(names = { "-H", "--server-host" }, description = "Server listening address (default: ${DEFAULT-VALUE}).", paramLabel = "<addr>")
|
||||
|
@ -33,6 +34,10 @@ public class Application implements Callable<Integer> {
|
|||
@CommandLine.Option(names = { "-t", "--threads" }, description = "Threads for processing inbound metrics(default: ${DEFAULT-VALUE}).", paramLabel = "<num>")
|
||||
private Integer threads = 5;
|
||||
|
||||
@CommandLine.Option(names = { "-d", "--debug" }, description = "Enable debugging (default: ${DEFAULT_VALUE}).")
|
||||
private boolean enableDebug = false;
|
||||
|
||||
|
||||
public static void main(String... args) {
|
||||
int exitCode = new CommandLine(new Application()).execute(args);
|
||||
System.exit(exitCode);
|
||||
|
@ -42,6 +47,10 @@ public class Application implements Callable<Integer> {
|
|||
@Override
|
||||
public Integer call() throws IOException {
|
||||
|
||||
if(enableDebug) {
|
||||
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");
|
||||
}
|
||||
|
||||
InfluxDB influxDB = InfluxDBFactory.connect(influxUrl.toString(), influxUser, influxPass);
|
||||
/*
|
||||
try {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package sysmon.server;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.LoggingLevel;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.model.rest.RestBindingMode;
|
||||
import org.apache.camel.spi.Registry;
|
||||
|
|
|
@ -30,16 +30,3 @@ camel.main.name = sysmon-server
|
|||
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:IncomingMetricProcessor
|
||||
#camel.beans.hello = #class:Hello
|
||||
|
||||
#camel.dataformat.json-jackson.use-list = true
|
|
@ -3,4 +3,4 @@ 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
|
||||
org.slf4j.simpleLogger.defaultLogLevel=warn
|
||||
|
|
|
@ -70,15 +70,6 @@ public class MetricResult implements Serializable {
|
|||
return hostname;
|
||||
}
|
||||
|
||||
/*
|
||||
public Measurement getMeasurement() {
|
||||
if(measurements != null && !measurements.isEmpty()) {
|
||||
return measurements.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
public ArrayList<Measurement> getMeasurements() {
|
||||
return measurements;
|
||||
}
|
||||
|
@ -87,24 +78,29 @@ public class MetricResult implements Serializable {
|
|||
StringBuilder sb = new StringBuilder(String.format("%s - %s => ", timestamp.toString(), name));
|
||||
|
||||
if(measurements != null && !measurements.isEmpty()) {
|
||||
sb.append("{");
|
||||
|
||||
for(Measurement m : measurements) {
|
||||
|
||||
sb.append("{ ");
|
||||
if(m != null && m.getTags() != null) {
|
||||
for (Map.Entry<String, String> entry : m.getTags().entrySet())
|
||||
sb.append(" [").append(entry.getKey()).append(": ").append(entry.getValue()).append("]");
|
||||
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append(", ");
|
||||
}
|
||||
sb.append("} ");
|
||||
|
||||
/*
|
||||
sb.append("[ ");
|
||||
if(m != null && m.getFields() != null) {
|
||||
for (Map.Entry<String,Object> entry : m.getFields().entrySet())
|
||||
sb.append(" [").append(entry.getKey()).append(": ").append(entry.getValue()).append("]");
|
||||
}
|
||||
|
||||
}
|
||||
sb.append("},");
|
||||
}
|
||||
|
||||
return sb.append(" }").toString();
|
||||
sb.append(entry.getKey()).append(": ").append(entry.getValue()).append(", ");
|
||||
}
|
||||
sb.append("] ");
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue