WIP on lists of measurements in results

This commit is contained in:
Mark Nellemann 2021-09-01 16:16:47 +02:00
parent 9fd29e0f21
commit d102d2f9fc
2 changed files with 51 additions and 12 deletions

View file

@ -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());

View file

@ -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<Measurement> 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<Measurement>() {{
add(measurement);
}};
}
public MetricResult(String name, List<Measurement> measurements) {
this.name = name;
this.timestamp = Instant.now().toEpochMilli();
this.measurements = measurements;
}
public void setMeasurement(Measurement measurement) {
this.measurement = measurement;
this.measurements = new ArrayList<Measurement>() {{
add(measurement);
}};
}
public void setMeasurements(List<Measurement> measurements) {
this.measurements = measurements;
}
public void setHostname(String hostname) {
@ -56,22 +72,44 @@ public class MetricResult implements Serializable {
}
public Measurement getMeasurement() {
return measurement;
if(measurements != null && measurements.size() > 0) {
return measurements.get(0);
}
return null;
}
public List<Measurement> 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<String, String> entry : measurement.getTags().entrySet())
if(measurements != null && measurements.size() > 0) {
sb.append("{");
for(Measurement m : measurements) {
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("]");
}
if(measurement != null && measurement.getFields() != null) {
for (Map.Entry<String,Object> entry : measurement.getFields().entrySet())
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();
}