Skip to content

Commit

Permalink
Merge pull request #39 from instana/mq_appliance_fix
Browse files Browse the repository at this point in the history
Update MQ appliance DC
  • Loading branch information
syh authored Jun 25, 2024
2 parents a0b7e17 + 31f1315 commit 7a92665
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
3 changes: 3 additions & 0 deletions host/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion host/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "com.instana.dc"
version = "0.1.4"
version = "0.1.5"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +19,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());
Expand All @@ -32,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<String, Object> properties, String applianceSystem) {
super(properties, applianceSystem);
applianceHost = (String) properties.get(APPLIANCE_HOST);
Expand Down Expand Up @@ -59,6 +61,7 @@ private void closeProcess() {
exec.shutdownNow();
}
}

@Override
public void start() {
try {
Expand All @@ -77,21 +80,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);
}
Expand All @@ -107,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(Double.parseDouble(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]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
public class MqApplianceUtil {
private static final Logger logger = Logger.getLogger(MqApplianceUtil.class.getName());

public static List<SimpleQueryResult> getApplianceCpuUsageResults(Double cpuUsage) {
List<SimpleQueryResult> results = new ArrayList<SimpleQueryResult>(1);
if (cpuUsage != null) {
SimpleQueryResult result = new SimpleQueryResult(cpuUsage / 100);
result.setKey("user");
result.setAttribute("cpu", "cpu");
result.setAttribute("state", "user");
results.add(result);
return results;
}
return null;
public static List<SimpleQueryResult> getApplianceCpuUsageResults(long cpuTime, long cpuTimeIdle) {
List<SimpleQueryResult> results = new ArrayList<SimpleQueryResult>(2);
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<SimpleQueryResult> getApplianceMemUsageResults(Long usedMem, Long freeMem) {
Expand Down

0 comments on commit 7a92665

Please sign in to comment.