2021-09-17 09:53:57 +00:00
|
|
|
package sysmon.server;
|
|
|
|
|
|
|
|
import org.apache.camel.Exchange;
|
|
|
|
import org.apache.camel.Processor;
|
|
|
|
import org.influxdb.dto.BatchPoints;
|
|
|
|
import org.influxdb.dto.Point;
|
|
|
|
import sysmon.shared.ComboResult;
|
|
|
|
import sysmon.shared.Measurement;
|
|
|
|
import sysmon.shared.MetricResult;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
public class ComboResultToPointProcessor implements Processor {
|
|
|
|
|
|
|
|
private static String influxDbName;
|
|
|
|
|
|
|
|
ComboResultToPointProcessor(String influxDbName) {
|
|
|
|
ComboResultToPointProcessor.influxDbName = influxDbName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-09-22 08:07:31 +00:00
|
|
|
public void process(Exchange exchange) {
|
2021-09-17 09:53:57 +00:00
|
|
|
|
|
|
|
ComboResult comboResult = exchange.getIn().getBody(ComboResult.class);
|
|
|
|
|
|
|
|
BatchPoints.Builder batchPoints = BatchPoints
|
|
|
|
.database(ComboResultToPointProcessor.influxDbName)
|
|
|
|
.precision(TimeUnit.MILLISECONDS);
|
|
|
|
|
2021-09-22 08:07:31 +00:00
|
|
|
for(MetricResult metricResult : comboResult.getMetricResults()) {
|
2021-09-17 09:53:57 +00:00
|
|
|
|
2021-09-22 08:07:31 +00:00
|
|
|
for(Measurement measurement : metricResult.getMeasurements()) {
|
2021-09-17 09:53:57 +00:00
|
|
|
|
|
|
|
Point.Builder point = Point.measurement(metricResult.getName())
|
|
|
|
.time(metricResult.getTimestamp(), TimeUnit.MILLISECONDS)
|
2022-11-07 12:33:35 +00:00
|
|
|
.tag("hostname", metricResult.getHostname())
|
|
|
|
.tag(measurement.getTags())
|
|
|
|
.fields(measurement.getFields());
|
2021-09-17 09:53:57 +00:00
|
|
|
|
2022-11-07 12:33:35 +00:00
|
|
|
/*
|
2021-09-17 09:53:57 +00:00
|
|
|
for (Map.Entry<String,String> entry : measurement.getTags().entrySet()) {
|
|
|
|
//log.info("process() - tag: " + entry.getKey() + "=" + entry.getValue());
|
|
|
|
point.tag(entry.getKey(), entry.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Map.Entry<String,Object> entry : measurement.getFields().entrySet()) {
|
|
|
|
//log.info("process() - field: " + entry.getKey() + "=" + entry.getValue());
|
|
|
|
if(entry.getValue() instanceof Number) {
|
|
|
|
Number num = (Number) entry.getValue();
|
|
|
|
point.addField(entry.getKey(), num);
|
|
|
|
} else if(entry.getValue() instanceof Boolean) {
|
|
|
|
Boolean bol = (Boolean) entry.getValue();
|
|
|
|
point.addField(entry.getKey(), bol);
|
|
|
|
} else {
|
|
|
|
String str = (String) entry.getValue();
|
|
|
|
point.addField(entry.getKey(), str);
|
|
|
|
}
|
2022-11-07 12:33:35 +00:00
|
|
|
}*/
|
2021-09-17 09:53:57 +00:00
|
|
|
batchPoints.point(point.build());
|
|
|
|
}
|
2021-09-22 08:07:31 +00:00
|
|
|
|
2021-09-17 09:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exchange.getIn().setBody(batchPoints.build());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|