Skip to content

Commit 62e30f6

Browse files
authored
Add support for OpenTelemetry (#995)
* Added support for OpenTelemetry Signed-off-by: dhoard <[email protected]>
1 parent 2abec75 commit 62e30f6

File tree

340 files changed

+4628
-1281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

340 files changed

+4628
-1281
lines changed

.gitignore

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ target/
1010
.settings/
1111
.classpath
1212
dependency-reduced-pom.xml
13-
output.txt
1413
pom.xml.versionsBackup
1514
integration_test_suite/integration_tests/src/test/resources/common/**.jar
16-
output.log
17-
stress-test.log
18-
test.sh
19-
test.log
20-
verify-full.sh
21-
verify-full.log
15+
smoke-test.log
16+
regression-test.log

MAINTAINER_NOTES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ Example
5757

5858
```shell
5959
/home/dhoard/Downloads/jmx_prometheus_javaagent-0.20.0.jar
60-
/home/dhoard/Downloads/jmx_prometheus_httpserver-0.20.0.jar
60+
/home/dhoard/Downloads/jmx_prometheus_standalone-0.20.0.jar
6161
```
6262

6363
Command
6464

6565
```shell
66-
./tools/patch-and-run-integration-test-suite.sh <javaagent.jar> <httpserver.jar>
66+
./tools/patch-and-run-integration-test-suite.sh <javaagent.jar> <standalone.jar>
6767
```
6868

6969
Example
7070

7171
```shell
72-
./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
72+
./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
7373
```
7474

7575
### Step 3

collector/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@
4040
<compilerArgument>-Xbootclasspath/a:${env.JAVA_HOME}/lib/</compilerArgument>
4141
</configuration>
4242
</plugin>
43+
<plugin>
44+
<groupId>com.diffplug.spotless</groupId>
45+
<artifactId>spotless-maven-plugin</artifactId>
46+
<configuration>
47+
<java>
48+
<googleJavaFormat>
49+
<version>1.24.0</version>
50+
<style>AOSP</style>
51+
<reflowLongStrings>true</reflowLongStrings>
52+
</googleJavaFormat>
53+
</java>
54+
</configuration>
55+
<executions>
56+
<execution>
57+
<goals>
58+
<goal>apply</goal>
59+
</goals>
60+
<phase>compile</phase>
61+
</execution>
62+
</executions>
63+
</plugin>
4364
<plugin>
4465
<artifactId>maven-surefire-plugin</artifactId>
4566
<version>3.5.2</version>

collector/src/main/java/io/prometheus/jmx/BuildInfoMetrics.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
* Metrics being exported:
3232
*
3333
* <pre>
34-
* jmx_exporter_build_info{version="3.2.0",name="jmx_prometheus_httpserver",} 1.0
34+
* jmx_exporter_build_info{version="3.2.0",name="jmx_prometheus_javaagent",} 1.0
35+
* </pre>
36+
*
37+
* or
38+
*
39+
* <pre>
40+
* jmx_exporter_build_info{version="3.2.0",name="jmx_prometheus_standalone",} 1.0
3541
* </pre>
3642
*/
3743
public class BuildInfoMetrics {

collector/src/main/java/io/prometheus/jmx/JmxCollector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private void exitOnConfigError() {
181181
LOGGER.log(
182182
SEVERE,
183183
"Configuration error: When running jmx_exporter in standalone mode (using"
184-
+ " jmx_prometheus_httpserver-*.jar) you must configure 'jmxUrl' or"
184+
+ " jmx_prometheus_standalone-*.jar) you must configure 'jmxUrl' or"
185185
+ " 'hostPort'.");
186186
System.exit(-1);
187187
}

collector/src/main/java/io/prometheus/jmx/JmxScraper.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,23 @@
2222
import io.prometheus.jmx.logger.LoggerFactory;
2323
import java.io.IOException;
2424
import java.lang.management.ManagementFactory;
25-
import java.util.*;
26-
import javax.management.*;
25+
import java.util.HashMap;
26+
import java.util.HashSet;
27+
import java.util.LinkedHashMap;
28+
import java.util.LinkedList;
29+
import java.util.List;
30+
import java.util.Map;
31+
import java.util.Optional;
32+
import java.util.Set;
33+
import java.util.TreeSet;
34+
import javax.management.Attribute;
35+
import javax.management.AttributeList;
36+
import javax.management.JMException;
37+
import javax.management.MBeanAttributeInfo;
38+
import javax.management.MBeanInfo;
39+
import javax.management.MBeanServerConnection;
40+
import javax.management.ObjectInstance;
41+
import javax.management.ObjectName;
2742
import javax.management.openmbean.CompositeData;
2843
import javax.management.openmbean.CompositeType;
2944
import javax.management.openmbean.TabularData;

collector/src/main/java/io/prometheus/jmx/MatchedRuleToMetricSnapshotsConverter.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@
1818

1919
import io.prometheus.jmx.logger.Logger;
2020
import io.prometheus.jmx.logger.LoggerFactory;
21-
import io.prometheus.metrics.model.snapshots.*;
22-
import java.util.*;
21+
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
22+
import io.prometheus.metrics.model.snapshots.GaugeSnapshot;
23+
import io.prometheus.metrics.model.snapshots.Labels;
24+
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
25+
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
26+
import io.prometheus.metrics.model.snapshots.UnknownSnapshot;
27+
import java.util.ArrayList;
28+
import java.util.HashMap;
29+
import java.util.HashSet;
30+
import java.util.List;
31+
import java.util.Map;
32+
import java.util.Set;
2333
import java.util.logging.Level;
2434

2535
public class MatchedRuleToMetricSnapshotsConverter {

collector/src/main/java/io/prometheus/jmx/logger/Logger.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package io.prometheus.jmx.logger;
1818

19+
import static java.lang.String.format;
20+
1921
import java.util.logging.Level;
2022

2123
/** Class to implement a Logger */
@@ -55,13 +57,11 @@ public boolean isLoggable(Level level) {
5557
*/
5658
public void log(Level level, String message, Object... objects) {
5759
if (LOGGER.isLoggable(level)) {
58-
LOGGER.log(level, String.format(message, objects));
60+
LOGGER.log(level, format(message, objects));
5961
}
6062

6163
if (JMX_PROMETHEUS_EXPORTER_DEVELOPER_DEBUG) {
62-
System.out
63-
.format("[%s] %s %s", level, LOGGER.getName(), String.format(message, objects))
64-
.println();
64+
System.out.printf("[%s] %s %s%n", level, LOGGER.getName(), format(message, objects));
6565
}
6666
}
6767
}

collector/src/test/java/io/prometheus/jmx/ObjectNameAttributeFilterTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616

1717
package io.prometheus.jmx;
1818

19-
import static org.junit.Assert.*;
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertTrue;
2022

2123
import java.lang.reflect.Field;
22-
import java.util.*;
24+
import java.util.Arrays;
25+
import java.util.Collections;
26+
import java.util.HashSet;
27+
import java.util.Iterator;
28+
import java.util.Map;
29+
import java.util.Set;
2330
import javax.management.MalformedObjectNameException;
2431
import javax.management.ObjectName;
2532
import org.junit.Test;

docs/README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55
JMX Exporter
66
=====
77

8-
JMX to Prometheus exporter: a collector that can configurable scrape and
9-
expose mBeans of a JMX target.
8+
JMX to Prometheus exporter:
109

11-
This exporter is intended to be run as a Java Agent, exposing a HTTP server
12-
and serving metrics of the local JVM. It can be also run as a standalone
13-
HTTP server and scrape remote JMX targets, but this has various
10+
A collector that can configurable scrape and expose MBeans of a JMX target.
11+
12+
This exporter is intended to be run as a Java Agent, exposing either
13+
an HTTP endpoint or pushing Open Telemetry metrics of the local JVM.
14+
15+
It can be also run as a standalone server and scrape remote JMX targets, but this has various
1416
disadvantages, such as being harder to configure and being unable to expose
15-
process metrics (e.g., memory and CPU usage). In particular all the
16-
`jvm_*` metrics like `jvm_classes_loaded_total`, `jvm_threads_current`,
17-
`jvm_threads_daemon` and `jvm_memory_bytes_used` won't be availabe if
18-
using the standalone http server.
17+
process metrics (e.g., memory and CPU usage).
18+
19+
In particular all the `jvm_*` metrics like `jvm_classes_loaded_total`, `jvm_threads_current`,
20+
`jvm_threads_daemon` and `jvm_memory_bytes_used` won't be available when
21+
using the standalone server.
22+
23+
**Running the exporter as a Java agent is strongly encouraged.**
1924

2025
### **NOTES**
2126

@@ -52,21 +57,21 @@ rules:
5257
5358
Example configurations can be found in the `example_configs/` directory.
5459

55-
## Running the Standalone HTTP Server
60+
## Running the Standalone Server
5661

57-
- [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)
62+
- [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)
5863

59-
To run the standalone HTTP server, download one of the JARs and run:
64+
To run the standalone server, download one of the JARs and run:
6065

6166
```
62-
java -jar jmx_prometheus_httpserver-1.0.1.jar 12345 config.yaml
67+
java -jar jmx_prometheus_standalone-1.0.1.jar 12345 config.yaml
6368
```
6469

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

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

7176
A minimal `config.yaml` looks like this:
7277

@@ -76,7 +81,7 @@ rules:
7681
- pattern: ".*"
7782
```
7883

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

8186
**NOTES**
8287

0 commit comments

Comments
 (0)