Skip to content

Commit

Permalink
Add support for OpenTelemetry (#995)
Browse files Browse the repository at this point in the history
* Added support for OpenTelemetry

Signed-off-by: dhoard <[email protected]>
  • Loading branch information
dhoard authored Nov 22, 2024
1 parent 2abec75 commit 62e30f6
Show file tree
Hide file tree
Showing 340 changed files with 4,628 additions and 1,281 deletions.
9 changes: 2 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ target/
.settings/
.classpath
dependency-reduced-pom.xml
output.txt
pom.xml.versionsBackup
integration_test_suite/integration_tests/src/test/resources/common/**.jar
output.log
stress-test.log
test.sh
test.log
verify-full.sh
verify-full.log
smoke-test.log
regression-test.log
6 changes: 3 additions & 3 deletions MAINTAINER_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ Example

```shell
/home/dhoard/Downloads/jmx_prometheus_javaagent-0.20.0.jar
/home/dhoard/Downloads/jmx_prometheus_httpserver-0.20.0.jar
/home/dhoard/Downloads/jmx_prometheus_standalone-0.20.0.jar
```

Command

```shell
./tools/patch-and-run-integration-test-suite.sh <javaagent.jar> <httpserver.jar>
./tools/patch-and-run-integration-test-suite.sh <javaagent.jar> <standalone.jar>
```

Example

```shell
./tools/patch-and-run-integration-test-suite.sh /home/dhoard/Downloads/jmx_prometheus_javaagent-0.20.0.jar /home/dhoard/Downloads/jmx_prometheus_httpserver-0.20.0.jar
./tools/patch-and-run-integration-test-suite.sh /home/dhoard/Downloads/jmx_prometheus_javaagent-0.20.0.jar /home/dhoard/Downloads/jmx_prometheus_standalone-0.20.0.jar
```

### Step 3
Expand Down
21 changes: 21 additions & 0 deletions collector/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@
<compilerArgument>-Xbootclasspath/a:${env.JAVA_HOME}/lib/</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<java>
<googleJavaFormat>
<version>1.24.0</version>
<style>AOSP</style>
<reflowLongStrings>true</reflowLongStrings>
</googleJavaFormat>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>apply</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
* Metrics being exported:
*
* <pre>
* jmx_exporter_build_info{version="3.2.0",name="jmx_prometheus_httpserver",} 1.0
* jmx_exporter_build_info{version="3.2.0",name="jmx_prometheus_javaagent",} 1.0
* </pre>
*
* or
*
* <pre>
* jmx_exporter_build_info{version="3.2.0",name="jmx_prometheus_standalone",} 1.0
* </pre>
*/
public class BuildInfoMetrics {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void exitOnConfigError() {
LOGGER.log(
SEVERE,
"Configuration error: When running jmx_exporter in standalone mode (using"
+ " jmx_prometheus_httpserver-*.jar) you must configure 'jmxUrl' or"
+ " jmx_prometheus_standalone-*.jar) you must configure 'jmxUrl' or"
+ " 'hostPort'.");
System.exit(-1);
}
Expand Down
19 changes: 17 additions & 2 deletions collector/src/main/java/io/prometheus/jmx/JmxScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,23 @@
import io.prometheus.jmx.logger.LoggerFactory;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.*;
import javax.management.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.JMException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.TabularData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@

import io.prometheus.jmx.logger.Logger;
import io.prometheus.jmx.logger.LoggerFactory;
import io.prometheus.metrics.model.snapshots.*;
import java.util.*;
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
import io.prometheus.metrics.model.snapshots.GaugeSnapshot;
import io.prometheus.metrics.model.snapshots.Labels;
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
import io.prometheus.metrics.model.snapshots.UnknownSnapshot;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;

public class MatchedRuleToMetricSnapshotsConverter {
Expand Down
8 changes: 4 additions & 4 deletions collector/src/main/java/io/prometheus/jmx/logger/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.prometheus.jmx.logger;

import static java.lang.String.format;

import java.util.logging.Level;

/** Class to implement a Logger */
Expand Down Expand Up @@ -55,13 +57,11 @@ public boolean isLoggable(Level level) {
*/
public void log(Level level, String message, Object... objects) {
if (LOGGER.isLoggable(level)) {
LOGGER.log(level, String.format(message, objects));
LOGGER.log(level, format(message, objects));
}

if (JMX_PROMETHEUS_EXPORTER_DEVELOPER_DEBUG) {
System.out
.format("[%s] %s %s", level, LOGGER.getName(), String.format(message, objects))
.println();
System.out.printf("[%s] %s %s%n", level, LOGGER.getName(), format(message, objects));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@

package io.prometheus.jmx;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.lang.reflect.Field;
import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.junit.Test;
Expand Down
37 changes: 21 additions & 16 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
JMX Exporter
=====

JMX to Prometheus exporter: a collector that can configurable scrape and
expose mBeans of a JMX target.
JMX to Prometheus exporter:

This exporter is intended to be run as a Java Agent, exposing a HTTP server
and serving metrics of the local JVM. It can be also run as a standalone
HTTP server and scrape remote JMX targets, but this has various
A collector that can configurable scrape and expose MBeans of a JMX target.

This exporter is intended to be run as a Java Agent, exposing either
an HTTP endpoint or pushing Open Telemetry metrics of the local JVM.

It can be also run as a standalone server and scrape remote JMX targets, but this has various
disadvantages, such as being harder to configure and being unable to expose
process metrics (e.g., memory and CPU usage). In particular all the
`jvm_*` metrics like `jvm_classes_loaded_total`, `jvm_threads_current`,
`jvm_threads_daemon` and `jvm_memory_bytes_used` won't be availabe if
using the standalone http server.
process metrics (e.g., memory and CPU usage).

In particular all the `jvm_*` metrics like `jvm_classes_loaded_total`, `jvm_threads_current`,
`jvm_threads_daemon` and `jvm_memory_bytes_used` won't be available when
using the standalone server.

**Running the exporter as a Java agent is strongly encouraged.**

### **NOTES**

Expand Down Expand Up @@ -52,21 +57,21 @@ rules:
Example configurations can be found in the `example_configs/` directory.

## Running the Standalone HTTP Server
## Running the Standalone Server

- [jmx_prometheus_httpserver-1.0.1.jar](https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_httpserver/1.0.1/jmx_prometheus_httpserver-1.0.1.jar)
- [jmx_prometheus_standalone-1.0.1.jar](https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_standalone/1.0.1/jmx_prometheus_standalone-1.0.1.jar)

To run the standalone HTTP server, download one of the JARs and run:
To run the standalone server, download one of the JARs and run:

```
java -jar jmx_prometheus_httpserver-1.0.1.jar 12345 config.yaml
java -jar jmx_prometheus_standalone-1.0.1.jar 12345 config.yaml
```

Metrics will now be accessible at [http://localhost:12345/metrics](http://localhost:12345/metrics).
To bind the java agent to a specific IP change the port number to `host:port`.

The standalone HTTP server will read JMX remotely over the network. Therefore, you need to specify
either `hostPort` or `jmxUrl` in `config.yaml` to tell the HTTP server where the JMX beans can be accessed.
The standalone server will read JMX remotely over the network. Therefore, you need to specify
either `hostPort` or `jmxUrl` in `config.yaml` to tell the server where the JMX beans can be accessed.

A minimal `config.yaml` looks like this:

Expand All @@ -76,7 +81,7 @@ rules:
- pattern: ".*"
```

As stated above, it is recommended to run JMX exporter as a Java agent and not as a standalone HTTP server.
As stated above, it is recommended to run JMX exporter as a Java agent and not as a standalone server.

**NOTES**

Expand Down
10 changes: 5 additions & 5 deletions integration_test_suite/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Integration Test Suite
---

### Smoke test Docker images tested
### Smoke test Java Docker images tested

[Smoke test Docker images](https://github.com/prometheus/jmx_exporter/blob/main/integration_test_suite/integration_tests/src/test/resources/smoke-test-java-docker-images.txt)

### Docker images tested (all)
### All Java Docker images tested (all)

[All Docker images](https://github.com/prometheus/jmx_exporter/blob/main/integration_test_suite/integration_tests/src/test/resources/java-docker-images.txt)

Expand All @@ -18,21 +18,21 @@ Integration Test Suite
### Run the integration test suite (all Docker images)

```shell
export DOCKER_IMAGE_NAMES=ALL
export JAVA_DOCKER_IMAGES=ALL
./mvnw clean verify
```

### Run the integration test suite on a specific Docker image

```shell
export DOCKER_IMAGE_NAMES="<your custom Docker image>"
export JAVA_DOCKER_IMAGES="<your custom Docker image>"
./mvnw clean verify
```

Example:

```shell
export DOCKER_IMAGE_NAMES="azul/zulu-openjdk:17"
export JAVA_DOCKER_IMAGES="azul/zulu-openjdk:17"
./mvnw clean verify
```

Expand Down
Loading

0 comments on commit 62e30f6

Please sign in to comment.