This version is still in development and is not considered stable yet. For the latest stable version, please use Micrometer 1.14.3! |
Apache Commons Pool Instrumentation
Apache Commons Pool is an open source software library provides an object-pooling API and a number of object pool implementations.
Below you can find an example of how to instrument Apache Commons Pool with Micrometer.
// Setting up instrumentation
private final CommonsObjectPool2Metrics commonsObjectPool2Metrics = new CommonsObjectPool2Metrics(tags);
// Generic Pool instrumentation (with examples of created meters)
try (GenericObjectPool<Object> ignored = createGenericObjectPool()) {
commonsObjectPool2Metrics.bindTo(registry);
Tags tagsToMatch = tags.and("name", "pool", "type", "GenericObjectPool", "factoryType",
"io.micrometer.core.instrument.binder.commonspool2.CommonsObjectPool2MetricsTest$1<java.lang.Object>");
registry.get("commons.pool2.num.idle").tags(tagsToMatch).gauge();
registry.get("commons.pool2.num.waiters").tags(tagsToMatch).gauge();
Arrays
.asList("commons.pool2.created", "commons.pool2.borrowed", "commons.pool2.returned",
"commons.pool2.destroyed", "commons.pool2.destroyed.by.evictor",
"commons.pool2.destroyed.by.borrow.validation")
.forEach(name -> registry.get(name).tags(tagsToMatch).functionCounter());
Arrays
.asList("commons.pool2.max.borrow.wait", "commons.pool2.mean.active", "commons.pool2.mean.idle",
"commons.pool2.mean.borrow.wait")
.forEach(name -> registry.get(name).tags(tagsToMatch).timeGauge());
}
// Generic Keyed Pool instrumentation (with examples of created meters)
try (GenericKeyedObjectPool<Object, Object> ignored = createGenericKeyedObjectPool()) {
commonsObjectPool2Metrics.bindTo(registry);
Tags tagsToMatch = tags.and("name", "pool", "type", "GenericKeyedObjectPool", "factoryType", "none");
Arrays.asList("commons.pool2.num.idle", "commons.pool2.num.waiters")
.forEach(name -> registry.get(name).tags(tagsToMatch).gauge());
Arrays
.asList("commons.pool2.created", "commons.pool2.borrowed", "commons.pool2.returned",
"commons.pool2.destroyed", "commons.pool2.destroyed.by.evictor",
"commons.pool2.destroyed.by.borrow.validation")
.forEach(name -> registry.get(name).tags(tagsToMatch).functionCounter());
Arrays
.asList("commons.pool2.max.borrow.wait", "commons.pool2.mean.active", "commons.pool2.mean.idle",
"commons.pool2.mean.borrow.wait")
.forEach(name -> registry.get(name).tags(tagsToMatch).timeGauge());
}