Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting custom prefix in InstrumentedQueuedThreadPool #947

Merged
merged 1 commit into from
Jan 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

public class InstrumentedQueuedThreadPool extends QueuedThreadPool {
private final MetricRegistry metricRegistry;
private String prefix;

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry) {
this(registry, 200);
Expand Down Expand Up @@ -40,32 +41,53 @@ public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue) {
this(registry, maxThreads, minThreads, idleTimeout, queue, null);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("prefix") String prefix) {
super(maxThreads, minThreads, idleTimeout, queue);
this.metricRegistry = registry;
this.prefix = prefix;
}

public String getPrefix() {
return prefix;
}

public void setPrefix(String prefix) {
this.prefix = prefix;
}

@Override
protected void doStart() throws Exception {
super.doStart();
metricRegistry.register(name(QueuedThreadPool.class, getName(), "utilization"), new RatioGauge() {

final String prefix = this.prefix == null ? name(QueuedThreadPool.class, getName()) : name(this.prefix, getName());

metricRegistry.register(name(prefix, "utilization"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(getThreads() - getIdleThreads(), getThreads());
}
});
metricRegistry.register(name(QueuedThreadPool.class, getName(), "utilization-max"), new RatioGauge() {
metricRegistry.register(name(prefix, "utilization-max"), new RatioGauge() {
@Override
protected Ratio getRatio() {
return Ratio.of(getThreads() - getIdleThreads(), getMaxThreads());
}
});
metricRegistry.register(name(QueuedThreadPool.class, getName(), "size"), new Gauge<Integer>() {
metricRegistry.register(name(prefix, "size"), new Gauge<Integer>() {
@Override
public Integer getValue() {
return getThreads();
}
});
metricRegistry.register(name(QueuedThreadPool.class, getName(), "jobs"), new Gauge<Integer>() {
metricRegistry.register(name(prefix, "jobs"), new Gauge<Integer>() {
@Override
public Integer getValue() {
// This assumes the QueuedThreadPool is using a BlockingArrayQueue or
Expand Down