2021-05-21 09:08:43 +00:00
|
|
|
package sysmon.shared;
|
2021-04-25 13:25:20 +00:00
|
|
|
|
2021-05-06 08:57:35 +00:00
|
|
|
import java.io.Serializable;
|
2021-04-25 13:25:20 +00:00
|
|
|
import java.time.Instant;
|
2021-09-01 14:16:47 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2021-05-08 16:55:37 +00:00
|
|
|
import java.util.Map;
|
2021-04-25 13:25:20 +00:00
|
|
|
|
2021-05-06 08:57:35 +00:00
|
|
|
public class MetricResult implements Serializable {
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
private String name;
|
|
|
|
private String hostname;
|
2021-05-10 14:56:56 +00:00
|
|
|
private Long timestamp; // epoch milli
|
2021-09-01 14:16:47 +00:00
|
|
|
private List<Measurement> measurements;
|
2021-05-06 08:57:35 +00:00
|
|
|
|
|
|
|
public MetricResult() {
|
|
|
|
}
|
2021-04-25 13:25:20 +00:00
|
|
|
|
|
|
|
public MetricResult(String name) {
|
|
|
|
this.name = name;
|
2021-05-06 08:57:35 +00:00
|
|
|
this.timestamp = Instant.now().toEpochMilli();
|
2021-04-25 13:25:20 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 14:56:56 +00:00
|
|
|
public MetricResult(String name, Measurement measurement) {
|
|
|
|
this.name = name;
|
|
|
|
this.timestamp = Instant.now().toEpochMilli();
|
2021-09-01 14:16:47 +00:00
|
|
|
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;
|
2021-04-25 13:25:20 +00:00
|
|
|
}
|
|
|
|
|
2021-05-10 14:56:56 +00:00
|
|
|
public void setMeasurement(Measurement measurement) {
|
2021-09-01 14:16:47 +00:00
|
|
|
this.measurements = new ArrayList<Measurement>() {{
|
|
|
|
add(measurement);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMeasurements(List<Measurement> measurements) {
|
|
|
|
this.measurements = measurements;
|
2021-05-04 10:08:24 +00:00
|
|
|
}
|
2021-04-25 13:25:20 +00:00
|
|
|
|
2021-05-06 08:57:35 +00:00
|
|
|
public void setHostname(String hostname) {
|
|
|
|
this.hostname = hostname;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setName(String name) {
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTimestamp(Long timestamp) {
|
|
|
|
this.timestamp = timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Long getTimestamp() {
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getHostname() {
|
|
|
|
return hostname;
|
|
|
|
}
|
|
|
|
|
2021-05-10 14:56:56 +00:00
|
|
|
public Measurement getMeasurement() {
|
2021-09-01 14:16:47 +00:00
|
|
|
if(measurements != null && measurements.size() > 0) {
|
|
|
|
return measurements.get(0);
|
|
|
|
}
|
|
|
|
return null;
|
2021-05-06 08:57:35 +00:00
|
|
|
}
|
|
|
|
|
2021-09-01 14:16:47 +00:00
|
|
|
public List<Measurement> getMeasurements() {
|
|
|
|
if(measurements != null && measurements.size() > 0) {
|
|
|
|
return measurements;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-25 13:25:20 +00:00
|
|
|
public String toString() {
|
2021-09-01 14:16:47 +00:00
|
|
|
StringBuilder sb = new StringBuilder(String.format("%s - %s => ", timestamp.toString(), name));
|
2021-05-08 16:55:37 +00:00
|
|
|
|
2021-09-01 14:16:47 +00:00
|
|
|
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("]");
|
|
|
|
}
|
2021-05-08 16:55:37 +00:00
|
|
|
|
2021-09-01 14:16:47 +00:00
|
|
|
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("},");
|
2021-04-25 13:25:20 +00:00
|
|
|
}
|
|
|
|
|
2021-09-01 14:16:47 +00:00
|
|
|
|
2021-05-10 14:56:56 +00:00
|
|
|
return sb.append(" }").toString();
|
2021-04-25 13:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|