From 3ad33e45b3c729e7d72c5b26a991a72db4e7a5c0 Mon Sep 17 00:00:00 2001 From: YONG HU SUN Date: Fri, 14 Jun 2024 10:04:12 +0800 Subject: [PATCH 1/3] specify plugin type for mq appliance dc --- .../host/impl/mqappliance/MqApplianceDc.java | 15 +++++---------- .../impl/mqappliance/MqApplianceUtil.java | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 17 deletions(-) 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 2b79139..44cb964 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 @@ -21,6 +21,7 @@ import static com.instana.dc.DcUtil.mergeResourceAttributesFromEnv; import static com.instana.dc.host.HostDcUtil.*; +import static io.opentelemetry.api.common.AttributeKey.stringKey; public class MqApplianceDc extends AbstractHostDc { private static final Logger logger = Logger.getLogger(MqApplianceDc.class.getName()); @@ -59,6 +60,7 @@ private void closeProcess() { exec.shutdownNow(); } } + @Override public void start() { try { @@ -77,21 +79,14 @@ public String getHostName() { return applianceHost; } - public String getApplianceId() { - try { - return HostDcUtil.readFileText("/etc/machine-id"); - } catch (IOException e) { - return "UnknownID"; - } - } - @Override public Resource getResourceAttributes() { String applianceName = getHostName(); Resource resource = Resource.getDefault().merge(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, getServiceName(), ResourceAttributes.SERVICE_INSTANCE_ID, applianceName))); - resource = resource.merge(Resource.create(Attributes.of(ResourceAttributes.HOST_NAME, applianceName, ResourceAttributes.OS_TYPE, "MQ Appliance", ResourceAttributes.HOST_ID, getApplianceId()))); + resource = resource.merge(Resource.create(Attributes.of(ResourceAttributes.HOST_NAME, applianceName, ResourceAttributes.OS_TYPE, "MQ Appliance", ResourceAttributes.HOST_ID, applianceName))) + .merge(Resource.create(Attributes.of(stringKey("INSTANA_PLUGIN"), "host"))); return mergeResourceAttributesFromEnv(resource); } @@ -107,7 +102,7 @@ public void collectData() { if (tokens.length >= 7) { String[] systemMetricsTokens = tokens[0].split(":"); if (systemMetricsTokens.length == 6) { - getRawMetric(SYSTEM_CPU_TIME_NAME).setValue(MqApplianceUtil.getApplianceCpuUsageResults(Double.parseDouble(systemMetricsTokens[0]))); + getRawMetric(SYSTEM_CPU_TIME_NAME).setValue(MqApplianceUtil.getApplianceCpuUsageResults(Long.parseLong(systemMetricsTokens[0]))); 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 8b4402b..7762604 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,14 +13,19 @@ public class MqApplianceUtil { private static final Logger logger = Logger.getLogger(MqApplianceUtil.class.getName()); - public static List getApplianceCpuUsageResults(Double cpuUsage) { - List results = new ArrayList(1); + public static List getApplianceCpuUsageResults(Long cpuUsage) { + List results = new ArrayList(2); if (cpuUsage != null) { - SimpleQueryResult result = new SimpleQueryResult(cpuUsage / 100); - result.setKey("user"); - result.setAttribute("cpu", "cpu"); - result.setAttribute("state", "user"); - results.add(result); + 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; From 63a8e941b262d04542bb50cc5a89d8ae73ee22d0 Mon Sep 17 00:00:00 2001 From: liurui-1 Date: Fri, 14 Jun 2024 13:09:26 +0800 Subject: [PATCH 2/3] Change CPU code for MQAppliance to be accumulated --- host/build.gradle | 2 +- .../host/impl/mqappliance/MqApplianceDc.java | 19 ++++++++++--- .../impl/mqappliance/MqApplianceUtil.java | 27 +++++++++---------- 3 files changed, 29 insertions(+), 19 deletions(-) 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) { From 31f13157c1be70bb41ec680f36f2cc5869016ab3 Mon Sep 17 00:00:00 2001 From: YONG HU SUN Date: Tue, 25 Jun 2024 15:43:58 +0800 Subject: [PATCH 3/3] add prerequisite for mq appliance dc --- host/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/host/README.md b/host/README.md index bf6ceb5..58f5b19 100644 --- a/host/README.md +++ b/host/README.md @@ -58,6 +58,8 @@ export DC_CONFIG=config/config-mqappliance.yaml ```bash ./gradlew run ``` +*Note:* If you want to monitor IBM MQ appliance, you need to install **expect** before starting the Data Collector. You can run the command `which expect` to check if **expect** is already installed. + 5) Option-2: Find the deployment package (otel-dc-host-*.tar) generated by gradle in the "build/distributions/" directory, extract deployment files: ```bash cd build/distributions/ @@ -78,6 +80,7 @@ Run the Data Collector with following command according to your current OS: ```bash bin/otel-dc-host ``` +*Note:* If you want to monitor IBM MQ appliance, you need to install **expect** before starting the Data Collector. You can run the command `which expect` to check if **expect** is already installed. ## Create Data Collector implementation for a new type of host