Skip to content

Commit

Permalink
Merge pull request #112 from rabbitmq/rabbitmq-perf-test-101-metrics-jmx
Browse files Browse the repository at this point in the history
Support metrics with JMX
  • Loading branch information
michaelklishin authored Aug 1, 2018
2 parents d536349 + 5a2da35 commit cf354a1
Show file tree
Hide file tree
Showing 12 changed files with 466 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ run: compile ## Run PerfTest, pass exec arguments via ARGS, e.g. ARGS="-x 1 -y 1
signed-binary: clean ## Build a GPG signed binary
@mvnw package -P assemblies

doc: clean ## Generate PerfTest documentation
@mvnw asciidoctor:process-asciidoc

.PHONY: binary help clean compile jar run signed-binary
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

<rabbitmq.version>5.3.0</rabbitmq.version>
<commons-cli.version>1.1</commons-cli.version>
<metrics.version>4.0.3</metrics.version>
<metrics.version>3.2.6</metrics.version>
<micrometer.version>1.0.6</micrometer.version>
<logback.version>1.2.3</logback.version>
<jetty.version>9.4.11.v20180605</jetty.version>
Expand Down Expand Up @@ -121,11 +121,22 @@
<artifactId>micrometer-core</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-datadog</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-jmx</artifactId>
<version>${micrometer.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer.version}</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down
33 changes: 29 additions & 4 deletions src/docs/asciidoc/monitoring.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,37 @@ for more information about tags and dimensions.
=== Supported Monitoring Systems

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

==== Datadog

The API key is the only required option to send metrics to Datadog:

```
./runjava com.rabbitmq.perf.PerfTest --metrics-datadog-api-key YOUR_API_KEY
```

Another useful option is the step size or reporting frequency. The default value is
10 seconds.

```
./runjava com.rabbitmq.perf.PerfTest --metrics-datadog-api-key YOUR_API_KEY \
--metrics-datadog-step-size 20
```

==== JMX

JMX support provides a simple way to view metrics locally. Use the `--metrics-jmx` flag to
export metrics to JMX:

```
./runjava com.rabbitmq.perf.PerfTest --metrics-jmx
```

==== Prometheus

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



2 changes: 2 additions & 0 deletions src/main/java/com/rabbitmq/perf/CompositeMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class CompositeMetrics implements Metrics {
public CompositeMetrics() {
metrics.add(new BaseMetrics());
metrics.add(new PrometheusMetrics());
metrics.add(new DatadogMetrics());
metrics.add(new JmxMetrics());
}

@Override
Expand Down
97 changes: 97 additions & 0 deletions src/main/java/com/rabbitmq/perf/DatadogMetrics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) 2018 Pivotal Software, Inc. All rights reserved.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
// please see LICENSE-APACHE2.
//
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
// either express or implied. See the LICENSE file for specific language governing
// rights and limitations of this software.
//
// If you have any questions regarding licensing, please contact us at
// [email protected].

package com.rabbitmq.perf;

import com.rabbitmq.client.ConnectionFactory;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.datadog.DatadogConfig;
import io.micrometer.datadog.DatadogMeterRegistry;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

import static com.rabbitmq.perf.PerfTest.hasOption;
import static com.rabbitmq.perf.PerfTest.strArg;
import static java.lang.Boolean.valueOf;

/**
*
*/
public class DatadogMetrics implements Metrics {

private volatile MeterRegistry registry;

public Options options() {
Options options = new Options();
options.addOption(new Option("mda", "metrics-datadog", false, "enable Datadog metrics"));
options.addOption(new Option("mdk", "metrics-datadog-api-key", true, "Datadog API key"));
options.addOption(new Option("mds", "metrics-datadog-step-size", true, "step size (reporting frequency) to use "
+ "in seconds, default is 10 seconds"));
options.addOption(new Option("mdak", "metrics-datadog-application-key", true, "Datadog application key"));
options.addOption(new Option("mdh", "metrics-datadog-host-tag", true, "tag that will be mapped to \"host\" when shipping metrics to datadog"));
options.addOption(new Option("mdd", "metrics-datadog-descriptions", false, "if meter descriptions should be sent to Datadog"));
options.addOption(new Option("mdu", "metrics-datadog-uri", true, "URI to ship metrics, useful when using "
+ "a proxy, default is https://app.datadoghq.com"));
return options;
}

public void configure(CommandLineProxy cmd, CompositeMeterRegistry meterRegistry, ConnectionFactory factory) throws Exception {
if (isEnabled(cmd)) {
Map<String, String> dataCfg = new HashMap<>();
dataCfg.put("datadog.apiKey", strArg(cmd, "mdk", null));
dataCfg.put("datadog.step", strArg(cmd, "mds", "10"));
dataCfg.put("datadog.applicationKey", strArg(cmd, "mdak", null));
dataCfg.put("datadog.hostTag", strArg(cmd, "mdh", null));
dataCfg.put("datadog.descriptions", valueOf(hasOption(cmd, "mdd")).toString());
dataCfg.put("datadog.uri", strArg(cmd, "mdu", null));

DatadogConfig config = new DatadogConfig() {

@Override
public Duration step() {
return Duration.ofSeconds(Integer.valueOf(dataCfg.get("datadog.step")));
}

@Override
public String get(String k) {
return dataCfg.get(k);
}
};
registry = new DatadogMeterRegistry(
config,
Clock.SYSTEM,
new NamedThreadFactory("perf-test-metrics-datadog-")
);
meterRegistry.add(registry);
}
}

public void close() {
if (registry != null) {
registry.close();
}
}

@Override
public String toString() {
return "Datadog Metrics";
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/rabbitmq/perf/JmxMetrics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2018 Pivotal Software, Inc. All rights reserved.
//
// This software, the RabbitMQ Java client library, is triple-licensed under the
// Mozilla Public License 1.1 ("MPL"), the GNU General Public License version 2
// ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
// LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
// please see LICENSE-APACHE2.
//
// This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
// either express or implied. See the LICENSE file for specific language governing
// rights and limitations of this software.
//
// If you have any questions regarding licensing, please contact us at
// [email protected].

package com.rabbitmq.perf;

import com.rabbitmq.client.ConnectionFactory;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.composite.CompositeMeterRegistry;
import io.micrometer.jmx.JmxConfig;
import io.micrometer.jmx.JmxMeterRegistry;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;

/**
*
*/
public class JmxMetrics implements Metrics {

private volatile MeterRegistry registry;

public Options options() {
Options options = new Options();
options.addOption(new Option("mjx", "metrics-jmx", false, "enable JMX metrics"));
return options;
}

public void configure(CommandLineProxy cmd, CompositeMeterRegistry meterRegistry, ConnectionFactory factory) throws Exception {
if (isEnabled(cmd)) {
registry = new JmxMeterRegistry(
JmxConfig.DEFAULT,
Clock.SYSTEM
);
meterRegistry.add(registry);
}
}

public void close() {
if (registry!= null) {
registry.close();
}
}

@Override
public String toString() {
return "JMX Metrics";
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/rabbitmq/perf/PrometheusMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class PrometheusMetrics implements Metrics {

private volatile Server server;

private volatile PrometheusMeterRegistry registry;

public Options options() {
Options options = new Options();
options.addOption(new Option("mpr", "metrics-prometheus", false, "enable Prometheus metrics"));
Expand All @@ -53,7 +55,7 @@ public Options options() {

public void configure(CommandLineProxy cmd, CompositeMeterRegistry meterRegistry, ConnectionFactory factory) throws Exception {
if (isEnabled(cmd)) {
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
meterRegistry.add(registry);
int prometheusHttpEndpointPort = intArg(cmd, "mpp", 8080);
String prometheusHttpEndpoint = strArg(cmd, "mpe", "metrics");
Expand Down Expand Up @@ -97,6 +99,9 @@ public void close() throws Exception {
if (server != null) {
server.stop();
}
if (registry != null) {
registry.close();
}
}

@Override
Expand Down
Loading

0 comments on commit cf354a1

Please sign in to comment.