diff --git a/host/build.gradle b/host/build.gradle index 1e2195a..33fa3a9 100644 --- a/host/build.gradle +++ b/host/build.gradle @@ -4,7 +4,7 @@ plugins { } group = "com.instana.dc" -version = "0.1.4" +version = "0.1.5" repositories { mavenCentral() diff --git a/host/src/main/java/com/instana/dc/host/impl/mqappliance/MqApplianceDc.java b/host/src/main/java/com/instana/dc/host/impl/mqappliance/MqApplianceDc.java index 44cb964..5eb11f7 100644 --- a/host/src/main/java/com/instana/dc/host/impl/mqappliance/MqApplianceDc.java +++ b/host/src/main/java/com/instana/dc/host/impl/mqappliance/MqApplianceDc.java @@ -5,8 +5,6 @@ package com.instana.dc.host.impl.mqappliance; import com.instana.dc.host.AbstractHostDc; -import com.instana.dc.host.HostDcUtil; -import io.opentelemetry.api.OpenTelemetry; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.semconv.ResourceAttributes; @@ -33,6 +31,9 @@ public class MqApplianceDc extends AbstractHostDc { private Process process; protected BufferedReader bufferedReader; + private long cpuTime = 0; + private long cpuTimeIdle = 0; + public MqApplianceDc(Map properties, String applianceSystem) { super(properties, applianceSystem); applianceHost = (String) properties.get(APPLIANCE_HOST); @@ -102,7 +103,19 @@ public void collectData() { if (tokens.length >= 7) { String[] systemMetricsTokens = tokens[0].split(":"); if (systemMetricsTokens.length == 6) { - getRawMetric(SYSTEM_CPU_TIME_NAME).setValue(MqApplianceUtil.getApplianceCpuUsageResults(Long.parseLong(systemMetricsTokens[0]))); + long cpuUsage = Long.parseLong(systemMetricsTokens[0]); + if (cpuUsage >= 0) { + long cpuTime1 = cpuTime + cpuUsage; + long cpuTimeIdle1 = cpuTimeIdle + (100 - cpuUsage); + if (cpuTime1 >= 0 && cpuTimeIdle1 >= 0) { + cpuTime = cpuTime1; + cpuTimeIdle = cpuTimeIdle1; + } else { //Reset + cpuTime = 0; + cpuTimeIdle = 0; + } + getRawMetric(SYSTEM_CPU_TIME_NAME).setValue(MqApplianceUtil.getApplianceCpuUsageResults(cpuTime, cpuTimeIdle)); + } getRawMetric(SYSTEM_CPU_LOAD1_NAME).setValue(Double.parseDouble(systemMetricsTokens[1])); getRawMetric(SYSTEM_CPU_LOAD5_NAME).setValue(Double.parseDouble(systemMetricsTokens[2])); getRawMetric(SYSTEM_CPU_LOAD15_NAME).setValue(Double.parseDouble(systemMetricsTokens[3])); diff --git a/host/src/main/java/com/instana/dc/host/impl/mqappliance/MqApplianceUtil.java b/host/src/main/java/com/instana/dc/host/impl/mqappliance/MqApplianceUtil.java index 7762604..a434fbc 100644 --- a/host/src/main/java/com/instana/dc/host/impl/mqappliance/MqApplianceUtil.java +++ b/host/src/main/java/com/instana/dc/host/impl/mqappliance/MqApplianceUtil.java @@ -13,22 +13,19 @@ public class MqApplianceUtil { private static final Logger logger = Logger.getLogger(MqApplianceUtil.class.getName()); - public static List getApplianceCpuUsageResults(Long cpuUsage) { + public static List getApplianceCpuUsageResults(long cpuTime, long cpuTimeIdle) { List results = new ArrayList(2); - if (cpuUsage != null) { - SimpleQueryResult resultUser = new SimpleQueryResult(cpuUsage); - resultUser.setKey("user"); - resultUser.setAttribute("cpu", "cpu"); - resultUser.setAttribute("state", "user"); - results.add(resultUser); - SimpleQueryResult resultIdle = new SimpleQueryResult(100 - cpuUsage); - resultIdle.setKey("idle"); - resultIdle.setAttribute("cpu", "cpu"); - resultIdle.setAttribute("state", "idle"); - results.add(resultIdle); - return results; - } - return null; + SimpleQueryResult resultUser = new SimpleQueryResult(cpuTime); + resultUser.setKey("user"); + resultUser.setAttribute("cpu", "cpu"); + resultUser.setAttribute("state", "user"); + results.add(resultUser); + SimpleQueryResult resultIdle = new SimpleQueryResult(cpuTimeIdle); + resultIdle.setKey("idle"); + resultIdle.setAttribute("cpu", "cpu"); + resultIdle.setAttribute("state", "idle"); + results.add(resultIdle); + return results; } public static List getApplianceMemUsageResults(Long usedMem, Long freeMem) {