Skip to content

Commit 21a0b05

Browse files
izeyesnicoll
authored andcommitted
Add descriptions for data source pool metrics
See gh-20354
1 parent c71ed40 commit 21a0b05

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/jdbc/DataSourcePoolMetrics.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import javax.sql.DataSource;
2424

25+
import io.micrometer.core.instrument.Gauge;
2526
import io.micrometer.core.instrument.MeterRegistry;
2627
import io.micrometer.core.instrument.Tag;
2728
import io.micrometer.core.instrument.Tags;
@@ -65,23 +66,27 @@ public DataSourcePoolMetrics(DataSource dataSource, DataSourcePoolMetadataProvid
6566
@Override
6667
public void bindTo(MeterRegistry registry) {
6768
if (this.metadataProvider.getDataSourcePoolMetadata(this.dataSource) != null) {
68-
bindPoolMetadata(registry, "active", DataSourcePoolMetadata::getActive);
69-
bindPoolMetadata(registry, "idle", DataSourcePoolMetadata::getIdle);
70-
bindPoolMetadata(registry, "max", DataSourcePoolMetadata::getMax);
71-
bindPoolMetadata(registry, "min", DataSourcePoolMetadata::getMin);
69+
bindPoolMetadata(registry, "active", DataSourcePoolMetadata::getActive,
70+
"Current number of active connections that have been allocated from the data source.");
71+
bindPoolMetadata(registry, "idle", DataSourcePoolMetadata::getIdle,
72+
"Number of established but idle connections.");
73+
bindPoolMetadata(registry, "max", DataSourcePoolMetadata::getMax,
74+
"Maximum number of active connections that can be allocated at the same time.");
75+
bindPoolMetadata(registry, "min", DataSourcePoolMetadata::getMin,
76+
"Minimum number of idle connections in the pool.");
7277
}
7378
}
7479

7580
private <N extends Number> void bindPoolMetadata(MeterRegistry registry, String metricName,
76-
Function<DataSourcePoolMetadata, N> function) {
77-
bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function));
81+
Function<DataSourcePoolMetadata, N> function, String description) {
82+
bindDataSource(registry, metricName, this.metadataProvider.getValueFunction(function), description);
7883
}
7984

8085
private <N extends Number> void bindDataSource(MeterRegistry registry, String metricName,
81-
Function<DataSource, N> function) {
86+
Function<DataSource, N> function, String description) {
8287
if (function.apply(this.dataSource) != null) {
83-
registry.gauge("jdbc.connections." + metricName, this.tags, this.dataSource,
84-
(m) -> function.apply(m).doubleValue());
88+
Gauge.builder("jdbc.connections." + metricName, this.dataSource, (m) -> function.apply(m).doubleValue())
89+
.tags(this.tags).description(description).register(registry);
8590
}
8691
}
8792

0 commit comments

Comments
 (0)