From 731d8b8d102e095c078b119c4e9cff51393fa4f6 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Sat, 11 Sep 2021 21:55:48 +0200 Subject: [PATCH 1/2] Improvements to network and disk, plus some cleanup and refactoring. --- client/build.gradle | 2 +- client/doc/sysmon-client.toml | 4 +- .../main/java/sysmon/client/Application.java | 9 ++ .../sysmon/client/ClientRouteBuilder.java | 7 +- .../java/sysmon/client/Configuration.java | 8 +- gradle.properties | 2 +- .../plugins/os_aix/AixProcessorExtension.java | 4 +- plugins/os-base/README.md | 18 +++ .../plugins/os_base/BaseDiskExtension.java | 38 ++--- .../os_base/BaseFilesystemExtension.java | 132 ++++++++++++++++++ .../plugins/os_base/BaseNetworkExtension.java | 43 +++--- .../os_linux/LinuxSockstatExtension.java | 2 +- server/build.gradle | 2 +- 13 files changed, 213 insertions(+), 58 deletions(-) create mode 100644 plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseFilesystemExtension.java diff --git a/client/build.gradle b/client/build.gradle index 56ba734..8e7a2ad 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -37,7 +37,7 @@ def projectName = "sysmon-client" application { // Define the main class for the application. mainClass.set('sysmon.client.Application') - applicationDefaultJvmArgs = [ "-server", "-Xms16m", "-Xmx32m", "-XX:+UseG1GC" ] + applicationDefaultJvmArgs = [ "-server", "-Xmx64m", "-XX:+UseG1GC" ] } run { diff --git a/client/doc/sysmon-client.toml b/client/doc/sysmon-client.toml index 70cf8de..f7bebea 100644 --- a/client/doc/sysmon-client.toml +++ b/client/doc/sysmon-client.toml @@ -1,7 +1,9 @@ # Configuration for sysmon-client +[extension.base_filesystem] + [extension.base_disk] -enabled = false +enabled = true [extension.base_process] enabled = true diff --git a/client/src/main/java/sysmon/client/Application.java b/client/src/main/java/sysmon/client/Application.java index 4fcad29..7a73b52 100644 --- a/client/src/main/java/sysmon/client/Application.java +++ b/client/src/main/java/sysmon/client/Application.java @@ -4,6 +4,7 @@ package sysmon.client; import org.apache.camel.main.Main; +import org.slf4j.impl.SimpleLogger; import picocli.CommandLine; import java.io.File; @@ -28,6 +29,10 @@ public class Application implements Callable { @CommandLine.Option(names = { "-c", "--conf" }, description = "Configuration file [default: '/etc/sysmon-client.toml'].", paramLabel = "", defaultValue = "/etc/sysmon-client.toml") private File configurationFile; + @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); @@ -39,6 +44,10 @@ public class Application implements Callable { Configuration configuration = new Configuration(); + if(enableDebug) { + System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG"); + } + if(hostname == null || hostname.isEmpty()) { try { hostname = InetAddress.getLocalHost().getHostName(); diff --git a/client/src/main/java/sysmon/client/ClientRouteBuilder.java b/client/src/main/java/sysmon/client/ClientRouteBuilder.java index 7b08153..ea06665 100644 --- a/client/src/main/java/sysmon/client/ClientRouteBuilder.java +++ b/client/src/main/java/sysmon/client/ClientRouteBuilder.java @@ -55,13 +55,10 @@ public class ClientRouteBuilder extends RouteBuilder { log.info(">>> Enabling extension: " + ext.getDescription()); providers.add(provides); - - // TODO: Make timer thread configurable ? - // Setup Camel route for this extension // a unique timer name gives the timer it's own thread, otherwise it's a shared thread for other timers with same name. - //from("timer:"+provides+"?fixedRate=true&period=30s") - from("timer:extensions?fixedRate=true&period=30s") + //from("timer:extensions?fixedRate=true&period=30s") + from("timer:"+provides+"?fixedRate=true&period=30s") .bean(ext, "getMetrics") //.doTry() .outputType(MetricResult.class) diff --git a/client/src/main/java/sysmon/client/Configuration.java b/client/src/main/java/sysmon/client/Configuration.java index f9a4dfe..90f2227 100644 --- a/client/src/main/java/sysmon/client/Configuration.java +++ b/client/src/main/java/sysmon/client/Configuration.java @@ -46,10 +46,12 @@ public final class Configuration { String key = String.format("extension.%s", extName); TomlTable table = result.getTableOrEmpty(key); table.keySet().forEach( k -> { - if(table.isString(k)) { - map.put(k, table.getString(k)); - } else if(table.isBoolean(k)) { + if(table.isBoolean(k)) { map.put(k, table.getBoolean(k)); + } else if(table.isString(k)) { + map.put(k, table.getString(k)); + } else if(table.isLong(k)) { + map.put(k, table.getLong(k)); } else if(table.isDouble(k)) { map.put(k, table.getDouble(k)); } else if(table.isArray(k)) { diff --git a/gradle.properties b/gradle.properties index 91b92b6..d0d47a7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=0.0.10 +version=0.0.11 pf4jVersion=3.6.0 slf4jVersion=1.7.32 camelVersion=3.11.1 diff --git a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorExtension.java b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorExtension.java index 91855d4..a594174 100644 --- a/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorExtension.java +++ b/plugins/os-aix/src/main/java/sysmon/plugins/os_aix/AixProcessorExtension.java @@ -37,7 +37,7 @@ public class AixProcessorExtension implements MetricExtension { String osArch = System.getProperty("os.arch").toLowerCase(); if(!osArch.startsWith("ppc64")) { - log.warn("Requires CPU Architecture ppc64 or ppc64le, this is: " + osArch); + log.debug("Requires CPU Architecture ppc64 or ppc64le, this is: " + osArch); return false; } @@ -81,6 +81,8 @@ public class AixProcessorExtension implements MetricExtension { AixProcessorStat processorStat = processCommandOutput(buf); tagsMap = processorStat.getTags(); fieldsMap = processorStat.getFields(); + } catch (IOException e) { + log.error("lparstat error", e); } return new MetricResult(name, new Measurement(tagsMap, fieldsMap)); diff --git a/plugins/os-base/README.md b/plugins/os-base/README.md index 3a7e139..e0790fe 100644 --- a/plugins/os-base/README.md +++ b/plugins/os-base/README.md @@ -37,6 +37,24 @@ Metrics reported are: - **iotime** - Time spent on IO in milliseconds. - **queue** - Lenght of IO queue. +## Filesystem Extension + +### Metrics +- +- **free_bytes** - Free bytes for filesystem. +- **total_bytes** - Total bytes for filesystem. +- **free_inoed** - Free inodes for filesystem. +- **total_inodes** - Total inodes for filesystem. + +### Configuration + +```toml +[extension.base_filesystem] +enabled = true +exclude_type = [ "tmpfs", "ahafs" ] +exclude_mount = [ "/boot/efi" ] +``` + ## Process Extension Reports metrics on one or more running processes. diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseDiskExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseDiskExtension.java index 1fde4b9..01ff3f4 100644 --- a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseDiskExtension.java +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseDiskExtension.java @@ -9,6 +9,7 @@ import sysmon.shared.Measurement; import sysmon.shared.MetricExtension; import sysmon.shared.MetricResult; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -65,33 +66,32 @@ public class BaseDiskExtension implements MetricExtension { @Override public MetricResult getMetrics() { - long writeBytes = 0L; - long readBytes = 0L; - long transferTime = 0L; - long queueLength = 0L; - - HashMap tagsMap = new HashMap<>(); - HashMap fieldsMap = new HashMap<>(); - + ArrayList measurementList = new ArrayList<>(); List diskStores = hardwareAbstractionLayer.getDiskStores(); + for(HWDiskStore store : diskStores) { + String name = store.getName(); if (name.matches("hdisk[0-9]+") || name.matches("/dev/x?[sv]d[a-z]") || name.matches("/dev/nvme[0-9]n[0-9]")) { - log.debug("Using device: " + name); - writeBytes += store.getWriteBytes(); - readBytes += store.getReadBytes(); - transferTime += store.getTransferTime(); - queueLength = store.getCurrentQueueLength(); + + HashMap tagsMap = new HashMap() {{ + put("name", name); + }}; + + HashMap fieldsMap = new HashMap() {{ + put("read", store.getReadBytes()); + put("write", store.getWriteBytes()); + put("iotime", store.getTransferTime()); + put("queue", store.getCurrentQueueLength()); + }}; + + measurementList.add(new Measurement(tagsMap, fieldsMap)); } + } - fieldsMap.put("reads", readBytes); - fieldsMap.put("writes", writeBytes); - fieldsMap.put("iotime", transferTime); - fieldsMap.put("queue", queueLength); + return new MetricResult(name, measurementList); - log.debug(fieldsMap.toString()); - return new MetricResult(name, new Measurement(tagsMap, fieldsMap)); } } \ No newline at end of file diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseFilesystemExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseFilesystemExtension.java new file mode 100644 index 0000000..384cf7a --- /dev/null +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseFilesystemExtension.java @@ -0,0 +1,132 @@ +package sysmon.plugins.os_base; + +import org.pf4j.Extension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import oshi.SystemInfo; +import oshi.hardware.HardwareAbstractionLayer; +import oshi.software.os.OSFileStore; +import sysmon.shared.Measurement; +import sysmon.shared.MetricExtension; +import sysmon.shared.MetricResult; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Extension +public class BaseFilesystemExtension implements MetricExtension { + + private static final Logger log = LoggerFactory.getLogger(BaseDiskExtension.class); + + // Extension details + private final String name = "base_filesystem"; + private final String provides = "filesystem"; + private final String description = "Base Filesystem Metrics"; + + // Configuration / Options + private boolean enabled = true; + private List excludeType = new ArrayList() {{ + add("tmpfs"); + add("ahafs"); + }}; + private List excludeMount = new ArrayList() {{ + add("/boot/efi"); + }}; + + private HardwareAbstractionLayer hardwareAbstractionLayer; + private SystemInfo systemInfo; + + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public boolean isSupported() { + systemInfo = BasePlugin.getSystemInfo(); + //hardwareAbstractionLayer = BasePlugin.getHardwareAbstractionLayer(); + return systemInfo != null; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getProvides() { + return provides; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public void setConfiguration(Map map) { + if (map.containsKey("enabled")) { + enabled = (boolean) map.get("enabled"); + } + + if(map.containsKey("exclude_type")) { + excludeType = (List) map.get("exclude_type"); + } + + if(map.containsKey("exclude_mount")) { + excludeMount = (List) map.get("exclude_mount"); + } + } + + @Override + public MetricResult getMetrics() { + + ArrayList alreadyProcessed = new ArrayList<>(); + ArrayList measurementList = new ArrayList<>(); + List fileStores = systemInfo.getOperatingSystem().getFileSystem().getFileStores(true); + + for(OSFileStore store : fileStores) { + + String name = store.getName(); + String type = store.getType(); + String mount = store.getMount(); + + if(excludeType.contains(type)) { + log.debug("Excluding type: " + type); + continue; + } + + if(excludeMount.contains(mount)) { + log.debug("Excluding mount: " + mount); + continue; + } + + if(alreadyProcessed.contains(name)) { + log.debug("Skipping name: " + name); + continue; + } + alreadyProcessed.add(name); + + HashMap tagsMap = new HashMap() {{ + put("name", name); + put("type", type); + put("mount", mount); + }}; + + HashMap fieldsMap = new HashMap() {{ + put("free_bytes", store.getFreeSpace()); + put("total_bytes", store.getTotalSpace()); + put("free_inodes", store.getFreeInodes()); + put("total_inodes", store.getTotalInodes()); + }}; + + measurementList.add(new Measurement(tagsMap, fieldsMap)); + } + + return new MetricResult(name, measurementList); + } + +} \ No newline at end of file diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseNetworkExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseNetworkExtension.java index a8780b6..3380851 100644 --- a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseNetworkExtension.java +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseNetworkExtension.java @@ -9,6 +9,7 @@ import sysmon.shared.Measurement; import sysmon.shared.MetricExtension; import sysmon.shared.MetricResult; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -65,37 +66,29 @@ public class BaseNetworkExtension implements MetricExtension { @Override public MetricResult getMetrics() { - long rxBytes = 0L; - long rxPackets = 0L; - long rxErrs = 0L; - long txBytes = 0L; - long txPackets = 0L; - long txErrs = 0L; - - HashMap tagsMap = new HashMap<>(); - HashMap fieldsMap = new HashMap<>(); + ArrayList measurementList = new ArrayList<>(); List interfaces = hardwareAbstractionLayer.getNetworkIFs(); for(NetworkIF netif : interfaces) { - //String name = netif.getName(); - //log.warn("Device: " + name); - rxPackets += netif.getPacketsRecv(); - txPackets += netif.getPacketsSent(); - rxBytes += netif.getBytesRecv(); - txBytes += netif.getBytesSent(); - rxErrs += netif.getInErrors(); - txErrs += netif.getOutErrors(); + + HashMap tagsMap = new HashMap() {{ + put("name", netif.getName()); + }}; + + HashMap fieldsMap = new HashMap() {{ + put("rx_pkts", netif.getPacketsRecv()); + put("tx_pkts", netif.getPacketsSent()); + put("rx_bytes", netif.getBytesRecv()); + put("tx_bytes", netif.getBytesSent()); + put("rx_errs", netif.getInErrors()); + put("tx_errs", netif.getOutErrors()); + }}; + + measurementList.add(new Measurement(tagsMap, fieldsMap)); } - fieldsMap.put("rxPackets", rxPackets); - fieldsMap.put("txPackets", txPackets); - fieldsMap.put("rxBytes", rxBytes); - fieldsMap.put("txBytes", txBytes); - fieldsMap.put("rxErrors", rxErrs); - fieldsMap.put("txErrors", txErrs); - log.debug(fieldsMap.toString()); - return new MetricResult(name, new Measurement(tagsMap, fieldsMap)); + return new MetricResult(name, measurementList); } } diff --git a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxSockstatExtension.java b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxSockstatExtension.java index adfc8dc..311a625 100644 --- a/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxSockstatExtension.java +++ b/plugins/os-linux/src/main/java/sysmon/plugins/os_linux/LinuxSockstatExtension.java @@ -35,7 +35,7 @@ public class LinuxSockstatExtension implements MetricExtension { public boolean isSupported() { if(!System.getProperty("os.name").toLowerCase().contains("linux")) { - log.warn("Requires Linux."); + log.debug("Requires Linux."); return false; } diff --git a/server/build.gradle b/server/build.gradle index 3816f9e..fd13fff 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -28,7 +28,7 @@ def projectName = "sysmon-server" application { // Define the main class for the application. mainClass.set('sysmon.server.Application') - applicationDefaultJvmArgs = [ "-server", "-Xms64m", "-Xmx128m", "-XX:+UseG1GC" ] + applicationDefaultJvmArgs = [ "-server", "-Xmx128m", "-XX:+UseG1GC" ] } tasks.named('test') { From ea5d17bc5c8147ee7ac8fa5e66a28a9670b6d6aa Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Mon, 13 Sep 2021 17:13:58 +0200 Subject: [PATCH 2/2] Cleanup and option for debug logging. --- client/doc/sysmon-client.toml | 15 ++++++-- .../main/java/sysmon/client/Application.java | 6 +-- .../sysmon/client/ClientRouteBuilder.java | 5 ++- .../src/main/resources/application.properties | 12 ------ .../main/resources/simplelogger.properties | 2 +- .../plugins/os_base/BaseProcessExtension.java | 38 ++++++++++--------- .../main/java/sysmon/server/Application.java | 11 +++++- .../sysmon/server/ServerRouteBuilder.java | 1 + .../src/main/resources/application.properties | 13 ------- .../main/resources/simplelogger.properties | 2 +- .../main/java/sysmon/shared/MetricResult.java | 24 +++++------- 11 files changed, 61 insertions(+), 68 deletions(-) diff --git a/client/doc/sysmon-client.toml b/client/doc/sysmon-client.toml index f7bebea..60bb7c3 100644 --- a/client/doc/sysmon-client.toml +++ b/client/doc/sysmon-client.toml @@ -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" ] diff --git a/client/src/main/java/sysmon/client/Application.java b/client/src/main/java/sysmon/client/Application.java index 7a73b52..45fe046 100644 --- a/client/src/main/java/sysmon/client/Application.java +++ b/client/src/main/java/sysmon/client/Application.java @@ -42,12 +42,12 @@ public class Application implements Callable { @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(); diff --git a/client/src/main/java/sysmon/client/ClientRouteBuilder.java b/client/src/main/java/sysmon/client/ClientRouteBuilder.java index ea06665..f586c76 100644 --- a/client/src/main/java/sysmon/client/ClientRouteBuilder.java +++ b/client/src/main/java/sysmon/client/ClientRouteBuilder.java @@ -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(); diff --git a/client/src/main/resources/application.properties b/client/src/main/resources/application.properties index ef85751..4e881d2 100644 --- a/client/src/main/resources/application.properties +++ b/client/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/client/src/main/resources/simplelogger.properties b/client/src/main/resources/simplelogger.properties index df664d0..a2f88ce 100644 --- a/client/src/main/resources/simplelogger.properties +++ b/client/src/main/resources/simplelogger.properties @@ -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 diff --git a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessExtension.java b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessExtension.java index bdff0e4..e6e9317 100644 --- a/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessExtension.java +++ b/plugins/os-base/src/main/java/sysmon/plugins/os_base/BaseProcessExtension.java @@ -25,6 +25,9 @@ public class BaseProcessExtension implements MetricExtension { private boolean enabled = true; private List includeList = new ArrayList() {{ 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 tagsMap = new HashMap<>(); - HashMap fieldsMap = new HashMap<>(); + HashMap tagsMap = new HashMap() {{ + 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 fieldsMap = new HashMap() {{ + 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)); } diff --git a/server/src/main/java/sysmon/server/Application.java b/server/src/main/java/sysmon/server/Application.java index 450dd76..b8b0c16 100644 --- a/server/src/main/java/sysmon/server/Application.java +++ b/server/src/main/java/sysmon/server/Application.java @@ -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 { @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 = "sysmon", paramLabel = "") + @CommandLine.Option(names = { "-n", "--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 = "") @@ -33,6 +34,10 @@ public class Application implements Callable { @CommandLine.Option(names = { "-t", "--threads" }, description = "Threads for processing inbound metrics(default: ${DEFAULT-VALUE}).", paramLabel = "") 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 { @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 { diff --git a/server/src/main/java/sysmon/server/ServerRouteBuilder.java b/server/src/main/java/sysmon/server/ServerRouteBuilder.java index 985f33d..149441f 100644 --- a/server/src/main/java/sysmon/server/ServerRouteBuilder.java +++ b/server/src/main/java/sysmon/server/ServerRouteBuilder.java @@ -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; diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties index f9f82ea..cfdc8be 100644 --- a/server/src/main/resources/application.properties +++ b/server/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/server/src/main/resources/simplelogger.properties b/server/src/main/resources/simplelogger.properties index df664d0..a2f88ce 100644 --- a/server/src/main/resources/simplelogger.properties +++ b/server/src/main/resources/simplelogger.properties @@ -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 diff --git a/shared/src/main/java/sysmon/shared/MetricResult.java b/shared/src/main/java/sysmon/shared/MetricResult.java index eb94c1a..9e92e94 100644 --- a/shared/src/main/java/sysmon/shared/MetricResult.java +++ b/shared/src/main/java/sysmon/shared/MetricResult.java @@ -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 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 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 entry : m.getFields().entrySet()) - sb.append(" [").append(entry.getKey()).append(": ").append(entry.getValue()).append("]"); + sb.append(entry.getKey()).append(": ").append(entry.getValue()).append(", "); } + sb.append("] "); + */ } - sb.append("},"); } - return sb.append(" }").toString(); + return sb.toString(); } }