Skip to content

Commit

Permalink
Add SNMP support and snmphost (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Liu committed Jun 27, 2024
1 parent 7a92665 commit 523f04d
Show file tree
Hide file tree
Showing 30 changed files with 1,301 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ODCD (OpenTelemetry based Data Collector for Telemetry Data) is a collection of

##
### Requirements
- Data Collectors for Host **Java 8+**
- Data Collectors for Host **Java 11+**
- Data Collectors for Databases **Java 8+**
- Data Collectors for LLM **Java 11+**

Expand Down
6 changes: 4 additions & 2 deletions 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.5"
version = "0.1.6"

repositories {
mavenCentral()
Expand All @@ -20,7 +20,9 @@ dependencies {
implementation("io.opentelemetry:opentelemetry-exporter-sender-okhttp:1.34.1")
implementation("io.opentelemetry.semconv:opentelemetry-semconv:1.23.1-alpha")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.16.0-rc1")
implementation(files("libs/otel-dc-0.9.8.jar"))
implementation("org.snmp4j:snmp4j-agent:3.8.1")
implementation(files("libs/otel-dc-0.9.9.jar"))
implementation(files("libs/simp-snmp-0.1.0.jar"))

testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
Expand Down
8 changes: 8 additions & 0 deletions host/config/config-simphost.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
host.system: simp_host

instances:
- poll.interval: 30
callback.interval: 20
otel.backend.url: http://127.0.0.1:4317
#otel.backend.using.http: true
#otel.backend.url: http://127.0.0.1:4318/v1/metrics
11 changes: 7 additions & 4 deletions host/config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
host.system: simp_host
host.system: snmp_host

instances:
- poll.interval: 30
callback.interval: 20
- snmp.host: udp:9.112.252.102/161
poll.interval: 25
callback.interval: 30
otel.backend.url: http://127.0.0.1:4317
#otel.backend.using.http: true
#otel.backend.url: http://127.0.0.1:4318/v1/metrics
#otel.backend.url: http://9.112.252.66:4318/v1/metrics
host.name: stantest0.fyre.ibm.com
#os.type: linux
Binary file not shown.
Binary file added host/libs/simp-snmp-0.1.0.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion host/src/main/java/com/instana/dc/host/AbstractHostDc.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public abstract class AbstractHostDc extends AbstractDc implements IDc {
private final String serviceName;
public final static String INSTRUMENTATION_SCOPE_PREFIX = "otelcol/hostmetricsreceiver/";

public final static String DEFAULT_SERVICE_NAME = "otel-host";

private final ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();

public ScheduledExecutorService getExec() {
Expand All @@ -42,7 +44,7 @@ public AbstractHostDc(Map<String, Object> properties, String hostSystem) {
callbackInterval = (Integer) properties.getOrDefault(CALLBACK_INTERVAL, DEFAULT_CALLBACK_INTERVAL);
otelBackendUrl = (String) properties.get(OTEL_BACKEND_URL);
otelUsingHttp = (Boolean) properties.getOrDefault(OTEL_BACKEND_USING_HTTP, Boolean.FALSE);
serviceName = (String) properties.get(OTEL_SERVICE_NAME);
serviceName = (String) properties.getOrDefault(OTEL_SERVICE_NAME, DEFAULT_SERVICE_NAME);
}

public String getServiceName() {
Expand Down
3 changes: 2 additions & 1 deletion host/src/main/java/com/instana/dc/host/HostDcRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/
package com.instana.dc.host;

import com.instana.dc.host.AbstractHostDc;
import com.instana.dc.DcException;
import com.instana.dc.host.impl.simphost.SimpHostDc;
import com.instana.dc.host.impl.mqappliance.MqApplianceDc;
import com.instana.dc.host.impl.snmphost.SnmpHostDc;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -18,6 +18,7 @@ public class HostDcRegistry {
private final Map<String, Class<? extends AbstractHostDc>> map = new HashMap<String, Class<? extends AbstractHostDc>>() {{
put("SIMP_HOST", SimpHostDc.class);
put("MQ_APPLIANCE", MqApplianceDc.class);
put("SNMP_HOST", SnmpHostDc.class);
}};

public Class<? extends AbstractHostDc> findHostDc(String hostSystem) throws DcException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.instana.dc.host.impl.simphost;

import com.instana.dc.DcUtil;
import com.instana.dc.host.AbstractHostDc;
import com.instana.dc.host.HostDcUtil;
import io.opentelemetry.api.common.Attributes;
Expand All @@ -15,10 +16,12 @@
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import static com.instana.dc.DcUtil.mergeResourceAttributesFromEnv;
import static com.instana.dc.host.HostDcUtil.*;
import static io.opentelemetry.api.common.AttributeKey.stringKey;

public class SimpHostDc extends AbstractHostDc {
private static final Logger logger = Logger.getLogger(SimpHostDc.class.getName());
Expand Down Expand Up @@ -56,7 +59,8 @@ public Resource getResourceAttributes() {
resource = resource.merge(
Resource.create(Attributes.of(ResourceAttributes.HOST_NAME, hostName,
ResourceAttributes.OS_TYPE, "linux",
ResourceAttributes.HOST_ID, getHostId()
ResourceAttributes.HOST_ID, getHostId(),
stringKey(DcUtil.INSTANA_PLUGIN), "host"
))
);

Expand All @@ -76,7 +80,7 @@ public void collectData() {
getRawMetric(SYSTEM_CPU_LOAD5_NAME).setValue(loads.get(1));
getRawMetric(SYSTEM_CPU_LOAD15_NAME).setValue(loads.get(2));
} catch (Exception e) {
logger.severe("Cannot record loads: " + e.getMessage());
logger.log(Level.SEVERE, "Cannot record loads", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ public String toString() {
}
}

private static Pattern cpuPattern = Pattern.compile("\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)");

public static CpuTime getCpuTime() throws IOException {
String line = HostDcUtil.readFileTextLine("/proc/stat");
Pattern pattern = Pattern.compile("\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)\\D+(\\d+)");
Matcher m = pattern.matcher(line);
Matcher m = cpuPattern.matcher(line);

CpuTime cpuTime = new CpuTime();
if (m.find()) {
Expand Down Expand Up @@ -135,13 +136,13 @@ public static List<SimpleQueryResult> getCpuTimeResults() {
interrupt.setKey("interrupt");
softirq.setKey("softirq");

user.setAttribute("cpu", "cpu");
nice.setAttribute("cpu", "cpu");
system.setAttribute("cpu", "cpu");
idle.setAttribute("cpu", "cpu");
wait.setAttribute("cpu", "cpu");
interrupt.setAttribute("cpu", "cpu");
softirq.setAttribute("cpu", "cpu");
user.setAttribute("cpu", "cpu0");
nice.setAttribute("cpu", "cpu0");
system.setAttribute("cpu", "cpu0");
idle.setAttribute("cpu", "cpu0");
wait.setAttribute("cpu", "cpu0");
interrupt.setAttribute("cpu", "cpu0");
softirq.setAttribute("cpu", "cpu0");

user.setAttribute("state", "user");
nice.setAttribute("state", "nice");
Expand Down
Loading

0 comments on commit 523f04d

Please sign in to comment.