More work on Linux plugin.

This commit is contained in:
Mark Nellemann 2021-05-10 21:12:52 +02:00
parent a839304525
commit b1c1a2a36a
4 changed files with 30 additions and 17 deletions

View file

@ -5,28 +5,36 @@ import java.util.Map;
public class LinuxProcessorStat { public class LinuxProcessorStat {
private final String cpuName; private final float user;
//private final float user; private final float sys;
//private final float sys; private final float wait;
//private final float wait; private final float idle;
//private final float idle;
private final float busy; private final float busy;
public LinuxProcessorStat(LinuxProcessorProcLine current, LinuxProcessorProcLine previous) { public LinuxProcessorStat(LinuxProcessorProcLine current, LinuxProcessorProcLine previous) {
cpuName = current.getCpuName();
long workTimeDiff = current.getCombinedTime() - previous.getCombinedTime(); long workTime = current.getCombinedTime() - previous.getCombinedTime();
long idleTimeDiff = current.getCombinedIdleTime() - previous.getCombinedIdleTime();
float utilization = (float) (workTimeDiff - idleTimeDiff) / workTimeDiff; long busyTime = current.getCombinedIdleTime() - previous.getCombinedIdleTime();
busy = (utilization * 100); float busyDiff = (float) (workTime - busyTime) / workTime;
busy = (busyDiff * 100);
// TODO: Calculate user, system, idle and wait diff times into percentage. long userTime = current.getUserTime() - previous.getUserTime();
} float userDiff = (float) (workTime - userTime) / workTime;
user = 100 - (userDiff * 100);
long sysTime = current.getSystemTime() - previous.getSystemTime();
float sysDiff = (float) (workTime - sysTime) / workTime;
sys = 100 - (sysDiff * 100);
long waitTime = current.getIoWaitTime() - previous.getIoWaitTime();
float waitDiff = (float) (workTime - waitTime) / workTime;
wait = 100 - (waitDiff * 100);
long idleTime = current.getIdleTime() - previous.getIdleTime();
float idleDiff = (float) (workTime - idleTime) / workTime;
idle = 100 - (idleDiff * 100);
public String getName() {
return cpuName;
} }
@ -40,6 +48,10 @@ public class LinuxProcessorStat {
public Map<String, Object> getFields() { public Map<String, Object> getFields() {
Map<String, Object> fields = new HashMap<>(); Map<String, Object> fields = new HashMap<>();
fields.put("user", user);
fields.put("sys", sys);
fields.put("wait", wait);
fields.put("idle", idle);
fields.put("busy", busy); fields.put("busy", busy);
return fields; return fields;
} }

View file

@ -37,6 +37,10 @@ class LinuxProcessorTest extends Specification {
then: then:
processorStat.getBusy() == 38.001614f processorStat.getBusy() == 38.001614f
processorStat.getFields().get("user") == 35.6989f
processorStat.getFields().get("sys") == 2.2623215f
processorStat.getFields().get("idle") == 61.823322f
processorStat.getFields().get("wait") == 0.17505646f
} }

View file

@ -44,9 +44,7 @@ public class ServerRouteBuilder extends RouteBuilder {
.log("Error storing metric to InfluxDB: ${exception}") .log("Error storing metric to InfluxDB: ${exception}")
.end(); .end();
} }
} }

View file

@ -10,5 +10,4 @@ public interface MetricExtension extends ExtensionPoint {
String getDescription(); String getDescription();
MetricResult getMetrics(); MetricResult getMetrics();
} }