From d102d2f9fc84eb73f72d5910e27ccb4ab3475b12 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Wed, 1 Sep 2021 16:16:47 +0200 Subject: [PATCH] WIP on lists of measurements in results --- .../sysmon/client/ClientRouteBuilder.java | 1 + .../main/java/sysmon/shared/MetricResult.java | 62 +++++++++++++++---- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/sysmon/client/ClientRouteBuilder.java b/client/src/main/java/sysmon/client/ClientRouteBuilder.java index ec3d62e..51683aa 100644 --- a/client/src/main/java/sysmon/client/ClientRouteBuilder.java +++ b/client/src/main/java/sysmon/client/ClientRouteBuilder.java @@ -59,6 +59,7 @@ public class ClientRouteBuilder extends RouteBuilder { .log("Skipping empty measurement.") .stop() .otherwise() + .log(">>> ${body}") .to("seda:metrics?discardWhenFull=true"); } else { log.info(">>> Skipping extension (not supported here): " + ext.getDescription()); diff --git a/shared/src/main/java/sysmon/shared/MetricResult.java b/shared/src/main/java/sysmon/shared/MetricResult.java index 14bce96..d031743 100644 --- a/shared/src/main/java/sysmon/shared/MetricResult.java +++ b/shared/src/main/java/sysmon/shared/MetricResult.java @@ -2,6 +2,8 @@ package sysmon.shared; import java.io.Serializable; import java.time.Instant; +import java.util.ArrayList; +import java.util.List; import java.util.Map; public class MetricResult implements Serializable { @@ -11,7 +13,7 @@ public class MetricResult implements Serializable { private String name; private String hostname; private Long timestamp; // epoch milli - private Measurement measurement; + private List measurements; public MetricResult() { } @@ -24,11 +26,25 @@ public class MetricResult implements Serializable { public MetricResult(String name, Measurement measurement) { this.name = name; this.timestamp = Instant.now().toEpochMilli(); - this.measurement = measurement; + this.measurements = new ArrayList() {{ + add(measurement); + }}; + } + + public MetricResult(String name, List measurements) { + this.name = name; + this.timestamp = Instant.now().toEpochMilli(); + this.measurements = measurements; } public void setMeasurement(Measurement measurement) { - this.measurement = measurement; + this.measurements = new ArrayList() {{ + add(measurement); + }}; + } + + public void setMeasurements(List measurements) { + this.measurements = measurements; } public void setHostname(String hostname) { @@ -56,21 +72,43 @@ public class MetricResult implements Serializable { } public Measurement getMeasurement() { - return measurement; + if(measurements != null && measurements.size() > 0) { + return measurements.get(0); + } + return null; } + public List getMeasurements() { + if(measurements != null && measurements.size() > 0) { + return measurements; + } + return null; + + } + + + public String toString() { - StringBuilder sb = new StringBuilder(String.format("%s - %s {", timestamp.toString(), name)); + StringBuilder sb = new StringBuilder(String.format("%s - %s => ", timestamp.toString(), name)); - if(measurement != null && measurement.getTags() != null) { - for (Map.Entry entry : measurement.getTags().entrySet()) - sb.append(" [").append(entry.getKey()).append(": ").append(entry.getValue()).append("]"); + if(measurements != null && measurements.size() > 0) { + sb.append("{"); + for(Measurement m : measurements) { + + if(m != null && m.getTags() != null) { + for (Map.Entry entry : m.getTags().entrySet()) + sb.append(" [").append(entry.getKey()).append(": ").append(entry.getValue()).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("},"); } - if(measurement != null && measurement.getFields() != null) { - for (Map.Entry entry : measurement.getFields().entrySet()) - sb.append(" [").append(entry.getKey()).append(": ").append(entry.getValue()).append("]"); - } return sb.append(" }").toString(); }