Skip to content

Commit cf354a1

Browse files
Merge pull request #112 from rabbitmq/rabbitmq-perf-test-101-metrics-jmx
Support metrics with JMX
2 parents d536349 + 5a2da35 commit cf354a1

File tree

12 files changed

+466
-14
lines changed

12 files changed

+466
-14
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ run: compile ## Run PerfTest, pass exec arguments via ARGS, e.g. ARGS="-x 1 -y 1
3333
signed-binary: clean ## Build a GPG signed binary
3434
@mvnw package -P assemblies
3535

36+
doc: clean ## Generate PerfTest documentation
37+
@mvnw asciidoctor:process-asciidoc
38+
3639
.PHONY: binary help clean compile jar run signed-binary

pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<rabbitmq.version>5.3.0</rabbitmq.version>
5858
<commons-cli.version>1.1</commons-cli.version>
59-
<metrics.version>4.0.3</metrics.version>
59+
<metrics.version>3.2.6</metrics.version>
6060
<micrometer.version>1.0.6</micrometer.version>
6161
<logback.version>1.2.3</logback.version>
6262
<jetty.version>9.4.11.v20180605</jetty.version>
@@ -121,11 +121,22 @@
121121
<artifactId>micrometer-core</artifactId>
122122
<version>${micrometer.version}</version>
123123
</dependency>
124+
<dependency>
125+
<groupId>io.micrometer</groupId>
126+
<artifactId>micrometer-registry-datadog</artifactId>
127+
<version>${micrometer.version}</version>
128+
</dependency>
129+
<dependency>
130+
<groupId>io.micrometer</groupId>
131+
<artifactId>micrometer-registry-jmx</artifactId>
132+
<version>${micrometer.version}</version>
133+
</dependency>
124134
<dependency>
125135
<groupId>io.micrometer</groupId>
126136
<artifactId>micrometer-registry-prometheus</artifactId>
127137
<version>${micrometer.version}</version>
128138
</dependency>
139+
129140
<dependency>
130141
<groupId>ch.qos.logback</groupId>
131142
<artifactId>logback-classic</artifactId>

src/docs/asciidoc/monitoring.adoc

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,37 @@ for more information about tags and dimensions.
5555
=== Supported Monitoring Systems
5656

5757
PerfTest builds on top https://micrometer.io[Micrometer] to report gathered metrics to various monitoring systems.
58-
Nevertheless, not all systems supported by Micrometer are actually supported by PerfTest. The only metrics
59-
system currently supported is https://prometheus.io/[Prometheus]. Don't hesitate to
58+
Nevertheless, not all systems supported by Micrometer are actually supported by PerfTest.
59+
PerfTest currently supports https://www.datadoghq.com/[Datadog], https://en.wikipedia.org/wiki/Java_Management_Extensions[JMX],
60+
and https://prometheus.io/[Prometheus].
61+
Don't hesitate to
6062
https://github.com/rabbitmq/rabbitmq-perf-test/issues[request support for other monitoring systems].
6163

64+
==== Datadog
65+
66+
The API key is the only required option to send metrics to Datadog:
67+
68+
```
69+
./runjava com.rabbitmq.perf.PerfTest --metrics-datadog-api-key YOUR_API_KEY
70+
```
71+
72+
Another useful option is the step size or reporting frequency. The default value is
73+
10 seconds.
74+
75+
```
76+
./runjava com.rabbitmq.perf.PerfTest --metrics-datadog-api-key YOUR_API_KEY \
77+
--metrics-datadog-step-size 20
78+
```
79+
80+
==== JMX
81+
82+
JMX support provides a simple way to view metrics locally. Use the `--metrics-jmx` flag to
83+
export metrics to JMX:
84+
85+
```
86+
./runjava com.rabbitmq.perf.PerfTest --metrics-jmx
87+
```
88+
6289
==== Prometheus
6390

6491
Use the `-mpr` or `--metrics-prometheus` flag to enable metrics reporting to Prometheus:
@@ -76,5 +103,3 @@ can be changed:
76103
--metrics-prometheus-port 8090 --metrics-prometheus-endpoint perf-test-metrics
77104
```
78105

79-
80-

src/main/java/com/rabbitmq/perf/CompositeMetrics.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class CompositeMetrics implements Metrics {
3838
public CompositeMetrics() {
3939
metrics.add(new BaseMetrics());
4040
metrics.add(new PrometheusMetrics());
41+
metrics.add(new DatadogMetrics());
42+
metrics.add(new JmxMetrics());
4143
}
4244

4345
@Override
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Copyright (c) 2018 Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
15+
16+
package com.rabbitmq.perf;
17+
18+
import com.rabbitmq.client.ConnectionFactory;
19+
import io.micrometer.core.instrument.Clock;
20+
import io.micrometer.core.instrument.MeterRegistry;
21+
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
22+
import io.micrometer.datadog.DatadogConfig;
23+
import io.micrometer.datadog.DatadogMeterRegistry;
24+
import org.apache.commons.cli.Option;
25+
import org.apache.commons.cli.Options;
26+
27+
import java.time.Duration;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
31+
import static com.rabbitmq.perf.PerfTest.hasOption;
32+
import static com.rabbitmq.perf.PerfTest.strArg;
33+
import static java.lang.Boolean.valueOf;
34+
35+
/**
36+
*
37+
*/
38+
public class DatadogMetrics implements Metrics {
39+
40+
private volatile MeterRegistry registry;
41+
42+
public Options options() {
43+
Options options = new Options();
44+
options.addOption(new Option("mda", "metrics-datadog", false, "enable Datadog metrics"));
45+
options.addOption(new Option("mdk", "metrics-datadog-api-key", true, "Datadog API key"));
46+
options.addOption(new Option("mds", "metrics-datadog-step-size", true, "step size (reporting frequency) to use "
47+
+ "in seconds, default is 10 seconds"));
48+
options.addOption(new Option("mdak", "metrics-datadog-application-key", true, "Datadog application key"));
49+
options.addOption(new Option("mdh", "metrics-datadog-host-tag", true, "tag that will be mapped to \"host\" when shipping metrics to datadog"));
50+
options.addOption(new Option("mdd", "metrics-datadog-descriptions", false, "if meter descriptions should be sent to Datadog"));
51+
options.addOption(new Option("mdu", "metrics-datadog-uri", true, "URI to ship metrics, useful when using "
52+
+ "a proxy, default is https://app.datadoghq.com"));
53+
return options;
54+
}
55+
56+
public void configure(CommandLineProxy cmd, CompositeMeterRegistry meterRegistry, ConnectionFactory factory) throws Exception {
57+
if (isEnabled(cmd)) {
58+
Map<String, String> dataCfg = new HashMap<>();
59+
dataCfg.put("datadog.apiKey", strArg(cmd, "mdk", null));
60+
dataCfg.put("datadog.step", strArg(cmd, "mds", "10"));
61+
dataCfg.put("datadog.applicationKey", strArg(cmd, "mdak", null));
62+
dataCfg.put("datadog.hostTag", strArg(cmd, "mdh", null));
63+
dataCfg.put("datadog.descriptions", valueOf(hasOption(cmd, "mdd")).toString());
64+
dataCfg.put("datadog.uri", strArg(cmd, "mdu", null));
65+
66+
DatadogConfig config = new DatadogConfig() {
67+
68+
@Override
69+
public Duration step() {
70+
return Duration.ofSeconds(Integer.valueOf(dataCfg.get("datadog.step")));
71+
}
72+
73+
@Override
74+
public String get(String k) {
75+
return dataCfg.get(k);
76+
}
77+
};
78+
registry = new DatadogMeterRegistry(
79+
config,
80+
Clock.SYSTEM,
81+
new NamedThreadFactory("perf-test-metrics-datadog-")
82+
);
83+
meterRegistry.add(registry);
84+
}
85+
}
86+
87+
public void close() {
88+
if (registry != null) {
89+
registry.close();
90+
}
91+
}
92+
93+
@Override
94+
public String toString() {
95+
return "Datadog Metrics";
96+
}
97+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2018 Pivotal Software, Inc. All rights reserved.
2+
//
3+
// This software, the RabbitMQ Java client library, is triple-licensed under the
4+
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
5+
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6+
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7+
// please see LICENSE-APACHE2.
8+
//
9+
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10+
// either express or implied. See the LICENSE file for specific language governing
11+
// rights and limitations of this software.
12+
//
13+
// If you have any questions regarding licensing, please contact us at
14+
15+
16+
package com.rabbitmq.perf;
17+
18+
import com.rabbitmq.client.ConnectionFactory;
19+
import io.micrometer.core.instrument.Clock;
20+
import io.micrometer.core.instrument.MeterRegistry;
21+
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
22+
import io.micrometer.jmx.JmxConfig;
23+
import io.micrometer.jmx.JmxMeterRegistry;
24+
import org.apache.commons.cli.Option;
25+
import org.apache.commons.cli.Options;
26+
27+
/**
28+
*
29+
*/
30+
public class JmxMetrics implements Metrics {
31+
32+
private volatile MeterRegistry registry;
33+
34+
public Options options() {
35+
Options options = new Options();
36+
options.addOption(new Option("mjx", "metrics-jmx", false, "enable JMX metrics"));
37+
return options;
38+
}
39+
40+
public void configure(CommandLineProxy cmd, CompositeMeterRegistry meterRegistry, ConnectionFactory factory) throws Exception {
41+
if (isEnabled(cmd)) {
42+
registry = new JmxMeterRegistry(
43+
JmxConfig.DEFAULT,
44+
Clock.SYSTEM
45+
);
46+
meterRegistry.add(registry);
47+
}
48+
}
49+
50+
public void close() {
51+
if (registry!= null) {
52+
registry.close();
53+
}
54+
}
55+
56+
@Override
57+
public String toString() {
58+
return "JMX Metrics";
59+
}
60+
}

src/main/java/com/rabbitmq/perf/PrometheusMetrics.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class PrometheusMetrics implements Metrics {
4343

4444
private volatile Server server;
4545

46+
private volatile PrometheusMeterRegistry registry;
47+
4648
public Options options() {
4749
Options options = new Options();
4850
options.addOption(new Option("mpr", "metrics-prometheus", false, "enable Prometheus metrics"));
@@ -53,7 +55,7 @@ public Options options() {
5355

5456
public void configure(CommandLineProxy cmd, CompositeMeterRegistry meterRegistry, ConnectionFactory factory) throws Exception {
5557
if (isEnabled(cmd)) {
56-
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
58+
registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
5759
meterRegistry.add(registry);
5860
int prometheusHttpEndpointPort = intArg(cmd, "mpp", 8080);
5961
String prometheusHttpEndpoint = strArg(cmd, "mpe", "metrics");
@@ -97,6 +99,9 @@ public void close() throws Exception {
9799
if (server != null) {
98100
server.stop();
99101
}
102+
if (registry != null) {
103+
registry.close();
104+
}
100105
}
101106

102107
@Override

0 commit comments

Comments
 (0)