Commit 21a0b054 authored by Johnny Lim's avatar Johnny Lim Committed by Stephane Nicoll

Add descriptions for data source pool metrics

See gh-20354
parent c71ed407
......@@ -22,6 +22,7 @@ import java.util.function.Function;
import javax.sql.DataSource;
import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
......@@ -65,23 +66,27 @@ public class DataSourcePoolMetrics implements MeterBinder {
@Override
public void bindTo(MeterRegistry registry) {
if (this.metadataProvider.getDataSourcePoolMetadata(this.dataSource) != null) {
bindPoolMetadata(registry, "active", DataSourcePoolMetadata::getActive);
bindPoolMetadata(registry, "idle", DataSourcePoolMetadata::getIdle);
bindPoolMetadata(registry, "max", DataSourcePoolMetadata::getMax);
bindPoolMetadata(registry, "min", DataSourcePoolMetadata::getMin);
bindPoolMetadata(registry, "active", DataSourcePoolMetadata::getActive,
"Current number of active connections that have been allocated from the data source.");
bindPoolMetadata(registry, "idle", DataSourcePoolMetadata::getIdle,
"Number of established but idle connections.");
bindPoolMetadata(registry, "max", DataSourcePoolMetadata::getMax,
"Maximum number of active connections that can be allocated at the same time.");
bindPoolMetadata(registry, "min", DataSourcePoolMetadata::getMin,
"Minimum number of idle connections in the pool.");
}
}
private <N extends Number> void bindPoolMetadata(MeterRegistry registry, String metricName,
Function<DataSourcePoolMetadata, N> function) {
bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function));
Function<DataSourcePoolMetadata, N> function, String description) {
bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function), description);
}
private <N extends Number> void bindDataSource(MeterRegistry registry, String metricName,
Function<DataSource, N> function) {
Function<DataSource, N> function, String description) {
if (function.apply(this.dataSource) != null) {
registry.gauge("jdbc.connections." + metricName, this.tags, this.dataSource,
(m) -> function.apply(m).doubleValue());
Gauge.builder("jdbc.connections." + metricName, this.dataSource, (m) -> function.apply(m).doubleValue())
.tags(this.tags).description(description).register(registry);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment