|  | 
| 22 | 22 | 
 | 
| 23 | 23 | import javax.sql.DataSource; | 
| 24 | 24 | 
 | 
|  | 25 | +import io.micrometer.core.instrument.Gauge; | 
| 25 | 26 | import io.micrometer.core.instrument.MeterRegistry; | 
| 26 | 27 | import io.micrometer.core.instrument.Tag; | 
| 27 | 28 | import io.micrometer.core.instrument.Tags; | 
| @@ -65,23 +66,27 @@ public DataSourcePoolMetrics(DataSource dataSource, DataSourcePoolMetadataProvid | 
| 65 | 66 | 	@Override | 
| 66 | 67 | 	public void bindTo(MeterRegistry registry) { | 
| 67 | 68 | 		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."); | 
| 72 | 77 | 		} | 
| 73 | 78 | 	} | 
| 74 | 79 | 
 | 
| 75 | 80 | 	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); | 
| 78 | 83 | 	} | 
| 79 | 84 | 
 | 
| 80 | 85 | 	private <N extends Number> void bindDataSource(MeterRegistry registry, String metricName, | 
| 81 |  | -			Function<DataSource, N> function) { | 
|  | 86 | +			Function<DataSource, N> function, String description) { | 
| 82 | 87 | 		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); | 
| 85 | 90 | 		} | 
| 86 | 91 | 	} | 
| 87 | 92 | 
 | 
|  | 
0 commit comments