Skip to content

Commit

Permalink
Modify the JMXReporter so that the Throughput beans are dealt with as…
Browse files Browse the repository at this point in the history
… meter and timer objects, rather than gauges
  • Loading branch information
JohnWarnerEF committed May 18, 2015
1 parent a08abbd commit e26bb52
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
4 changes: 1 addition & 3 deletions src/main/java/io/vertx/ext/dropwizard/ThroughputMeter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.vertx.ext.dropwizard;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import io.vertx.ext.dropwizard.impl.InstantThroughput;

Expand All @@ -10,11 +9,10 @@
*
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class ThroughputMeter extends Meter implements Gauge<Long> {
public class ThroughputMeter extends Meter {

private final InstantThroughput instantThroughput = new InstantThroughput();

@Override
public Long getValue() {
return instantThroughput.count();
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/io/vertx/ext/dropwizard/ThroughputTimer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.vertx.ext.dropwizard;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Timer;
import io.vertx.ext.dropwizard.impl.InstantThroughput;
Expand All @@ -13,11 +12,10 @@
*
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
*/
public class ThroughputTimer extends Timer implements Gauge<Long> {
public class ThroughputTimer extends Timer {

private final InstantThroughput instantThroughput = new InstantThroughput();

@Override
public Long getValue() {
return instantThroughput.count();
}
Expand Down
85 changes: 67 additions & 18 deletions src/main/java/io/vertx/ext/dropwizard/reporters/JmxReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,13 @@

package io.vertx.ext.dropwizard.reporters;

import com.codahale.metrics.Counter;
import com.codahale.metrics.Gauge;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.Meter;
import com.codahale.metrics.Metered;
import com.codahale.metrics.MetricFilter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.MetricRegistryListener;
import com.codahale.metrics.Timer;
import com.codahale.metrics.*;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.impl.LoggerFactory;
import io.vertx.ext.dropwizard.ThroughputMeter;
import io.vertx.ext.dropwizard.ThroughputTimer;

import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.JMException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.*;
import java.io.Closeable;
import java.lang.management.ManagementFactory;
import java.util.Collections;
Expand Down Expand Up @@ -341,6 +329,14 @@ public interface JmxMeterMBean extends MetricMBean {
}
//CHECKSTYLE:ON

//CHECKSTYLE:OFF
@SuppressWarnings("UnusedDeclaration")
public interface JmxThroughputMeterMBean extends JmxMeterMBean {
double getInstantThroughput();
}
//CHECKSTYLE:ON


private static class JmxMeter extends AbstractBean implements JmxMeterMBean {
private final Metered metric;
private final double rateFactor;
Expand Down Expand Up @@ -389,6 +385,21 @@ private String calculateRateUnit(TimeUnit unit) {
}
}

private static class JmxThroughputMeter extends JmxMeter implements JmxThroughputMeterMBean {

private ThroughputMeter metric;

private JmxThroughputMeter(Metered metric, ObjectName objectName, TimeUnit rateUnit) {
super(metric, objectName, rateUnit);
this.metric = (ThroughputMeter) metric;
}

@Override
public double getInstantThroughput() {
return metric.getValue();
}
}

// CHECKSTYLE:OFF
@SuppressWarnings("UnusedDeclaration")
public interface JmxTimerMBean extends JmxMeterMBean {
Expand All @@ -413,10 +424,19 @@ public interface JmxTimerMBean extends JmxMeterMBean {
double get999thPercentile();

long[] values();

String getDurationUnit();
}
// CHECKSTYLE:ON

// CHECKSTYLE:OFF
@SuppressWarnings("UnusedDeclaration")
public interface JmxThroughputTimerMBean extends JmxTimerMBean {
double getInstantThroughput();
}
// CHECKSTYLE:ON


static class JmxTimer extends JmxMeter implements JmxTimerMBean {
private final Timer metric;
private final double durationFactor;
Expand Down Expand Up @@ -493,6 +513,23 @@ public String getDurationUnit() {
}
}

static class JmxThroughputTimer extends JmxTimer implements JmxThroughputTimerMBean {
private final ThroughputTimer metric;

private JmxThroughputTimer(Timer metric,
ObjectName objectName,
TimeUnit rateUnit,
TimeUnit durationUnit) {
super(metric, objectName, rateUnit, durationUnit);
this.metric = (ThroughputTimer) metric;
}

@Override
public double getInstantThroughput() {
return metric.getValue();
}
}

private static class JmxListener implements MetricRegistryListener {
private final String name;
private final MBeanServer mBeanServer;
Expand Down Expand Up @@ -597,7 +634,13 @@ public void onMeterAdded(String name, Meter meter) {
try {
if (filter.matches(name, meter)) {
final ObjectName objectName = createName("meters", name);
mBeanServer.registerMBean(new JmxMeter(meter, objectName, timeUnits.rateFor(name)), objectName);

if (meter instanceof ThroughputMeter) {
mBeanServer.registerMBean(new JmxThroughputMeter(meter, objectName, timeUnits.rateFor(name)), objectName);
} else {
mBeanServer.registerMBean(new JmxMeter(meter, objectName, timeUnits.rateFor(name)), objectName);
}

registered.add(objectName);
}
} catch (InstanceAlreadyExistsException e) {
Expand Down Expand Up @@ -625,7 +668,13 @@ public void onTimerAdded(String name, Timer timer) {
try {
if (filter.matches(name, timer)) {
final ObjectName objectName = createName("timers", name);
mBeanServer.registerMBean(new JmxTimer(timer, objectName, timeUnits.rateFor(name), timeUnits.durationFor(name)), objectName);

if (timer instanceof ThroughputTimer) {
mBeanServer.registerMBean(new JmxThroughputTimer(timer, objectName, timeUnits.rateFor(name), timeUnits.durationFor(name)), objectName);
} else {
mBeanServer.registerMBean(new JmxTimer(timer, objectName, timeUnits.rateFor(name), timeUnits.durationFor(name)), objectName);
}

registered.add(objectName);
}
} catch (InstanceAlreadyExistsException e) {
Expand Down

0 comments on commit e26bb52

Please sign in to comment.