More work on processor metrics.

This commit is contained in:
Mark Nellemann 2021-05-31 14:44:48 +02:00
parent 25e3640790
commit 3a4a4bdb8a
6 changed files with 30 additions and 36 deletions

View file

@ -52,7 +52,7 @@ public class ClientRouteBuilder extends RouteBuilder {
//.doTry()
.process(new MetricEnrichProcessor(registry))
.choice().when(exchangeProperty("skip").isEqualTo(true))
.log("Skipping empty: ${body}")
.log("Skipping empty measurement.")
.stop()
.otherwise()
.to("seda:metrics");

View file

@ -81,6 +81,7 @@ public class BaseDiskExtension implements MetricExtension {
fieldsMap.put("iotime", transferTime);
fieldsMap.put("queue", queueLength);
log.debug(fieldsMap.toString());
return new MetricResult("disk", new Measurement(tagsMap, fieldsMap));
}

View file

@ -65,6 +65,7 @@ public class BaseMemoryExtension implements MetricExtension {
fieldsMap.put("paged", hardwareAbstractionLayer.getMemory().getPageSize());
fieldsMap.put("virtual", hardwareAbstractionLayer.getMemory().getVirtualMemory().getVirtualInUse());
log.debug(fieldsMap.toString());
return new MetricResult("memory", new Measurement(tagsMap, fieldsMap));
}

View file

@ -83,6 +83,7 @@ public class BaseNetworkExtension implements MetricExtension {
fieldsMap.put("rxErrors", rxErrs);
fieldsMap.put("txErrors", txErrs);
log.debug(fieldsMap.toString());
return new MetricResult("network", new Measurement(tagsMap, fieldsMap));
}

View file

@ -26,6 +26,7 @@ public class BaseProcessorExtension implements MetricExtension {
private SystemInfo systemInfo;
private HardwareAbstractionLayer hardwareAbstractionLayer;
private long[] oldTicks;
@Override
public boolean isSupported() {
@ -63,48 +64,37 @@ public class BaseProcessorExtension implements MetricExtension {
Map<String, String> tagsMap = new HashMap<>();
Map<String, Object> fieldsMap = new HashMap<>();
long user = 0L;
long system = 0L;
long steal = 0L;
long irq = 0L;
long softirq = 0L;
long nice = 0L;
long idle = 0L;
long iowait = 0L;
long[][] ticks = hardwareAbstractionLayer.getProcessor().getProcessorCpuLoadTicks();
int cores = ticks.length;
//log.warn("Cores: " + cores);
for (long[] tick : ticks) {
nice += tick[CentralProcessor.TickType.NICE.getIndex()];
user += tick[CentralProcessor.TickType.USER.getIndex()];
system += tick[CentralProcessor.TickType.SYSTEM.getIndex()];
steal += tick[CentralProcessor.TickType.STEAL.getIndex()];
irq += tick[CentralProcessor.TickType.IRQ.getIndex()];
softirq += tick[CentralProcessor.TickType.SOFTIRQ.getIndex()];
idle += tick[CentralProcessor.TickType.IDLE.getIndex()];
iowait += tick[CentralProcessor.TickType.IOWAIT.getIndex()];
long[] ticks = hardwareAbstractionLayer.getProcessor().getSystemCpuLoadTicks();
if(oldTicks == null || oldTicks.length != ticks.length) {
oldTicks = ticks;
return null;
}
long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - oldTicks[CentralProcessor.TickType.NICE.getIndex()];
long user = ticks[CentralProcessor.TickType.USER.getIndex()] - oldTicks[CentralProcessor.TickType.USER.getIndex()];
long system = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - oldTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - oldTicks[CentralProcessor.TickType.STEAL.getIndex()];
long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - oldTicks[CentralProcessor.TickType.IRQ.getIndex()];
long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - oldTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - oldTicks[CentralProcessor.TickType.IDLE.getIndex()];
long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - oldTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
long busy = nice + user + system + steal + irq + softirq;
long nonBusy = idle + iowait;
long total = busy + nonBusy;
/*
log.info("idle: " + idle);
log.info("iowait: " + iowait);
log.info("busy: " + busy);
log.info("nonBusy: " + nonBusy);
log.info("total: " + total);
*/
fieldsMap.put("system", ((float) system / (float) total) * 100);
fieldsMap.put("user", ((float) user / (float) total) * 100);
fieldsMap.put("nice", ((float) nice / (float) total) * 100);
fieldsMap.put("iowait", ((float) iowait / (float) total) * 100);
fieldsMap.put("steal", ((float) steal / (float) total) * 100);
fieldsMap.put("irq", ((float) irq / (float) total) * 100);
fieldsMap.put("softirq", ((float) softirq / (float) total) * 100);
fieldsMap.put("idle", ((float) idle / (float) total) * 100);
fieldsMap.put("busy", ((float) busy / (float) total) * 100);
fieldsMap.put("user", (float) user / (float) total);
fieldsMap.put("iowait", (float) iowait / (float) total);
fieldsMap.put("idle", (float) nonBusy / (float) total);
fieldsMap.put("busy", (float) busy / (float) total);
fieldsMap.put("system", (float) system / (float) total);
//log.info(fieldsMap.toString());
oldTicks = ticks;
log.debug(fieldsMap.toString());
return new MetricResult("processor", new Measurement(tagsMap, fieldsMap));
}

View file

@ -50,6 +50,7 @@ public class LinuxNetworkExtension implements MetricExtension {
Map<String, String> tagsMap = sockStat.getTags();
Map<String, Object> fieldsMap = sockStat.getFields();
log.debug(fieldsMap.toString());
return new MetricResult("network_sockets", new Measurement(tagsMap, fieldsMap));
}