DataSource metrics
This commit adds an abstraction that provides a standard manner to retrieve various metadata that are shared by most data sources. DataSourceMetadata is implemented by the three data source implementations that boot supports out-of-the-box: Tomcat, Hikari and Commons dbcp. This abstraction is used to provide two additional metrics per data source defined in the application: the number of allocated connection(s) (.active) and the current usage of the connection pool (.usage). All such metrics share the 'datasource.' prefix. The prefix is further qualified for each data source: * If the data source is the primary data source (that is either the only available data source or the one flagged @Primary amongst the existing ones), the prefix is "datasource.primary" * If the data source bean name ends with "dataSource", the prefix is the name of the bean without it (i.e. batchDataSource becomes batch) * In all other cases, the name of the bean is used It is possible to override part or all of those defaults by registering a bean with a customized version of DataSourcePublicMetrics. Additional DataSourceMetadata implementations for other data source types can be added very easily, check DataourceMetadataProvidersConfiguration for more details. Fixes gh-1013
This commit is contained in:
committed by
Stephane Nicoll
parent
85c95744f9
commit
3dc932db88
@@ -615,7 +615,10 @@ endpoint you should see a response similar to this:
|
||||
"threads": 15,
|
||||
"threads.daemon": 11,
|
||||
"threads.peak": 15,
|
||||
"uptime": 494836
|
||||
"uptime": 494836,
|
||||
"instance.uptime": 489782,
|
||||
"datasource.primary.active": 5,
|
||||
"datasource.primary.usage": 0.25
|
||||
}
|
||||
----
|
||||
|
||||
@@ -631,7 +634,26 @@ The `gauge` shows the last response time for a request. So the last request to `
|
||||
NOTE: In this example we are actually accessing the endpoint over HTTP using the
|
||||
`/metrics` URL, this explains why `metrics` appears in the response.
|
||||
|
||||
[[production-ready-datasource-metrics]]
|
||||
=== DataSource metrics
|
||||
|
||||
The following metrics are available for each data source defined in the application: the
|
||||
number of allocated connection(s) (`.active`) and the current usage of the connection
|
||||
pool (`.usage`).
|
||||
|
||||
All data source metrics share the `datasource.` prefix. The prefix is further qualified for
|
||||
each data source:
|
||||
|
||||
* If the data source is the primary data source (that is either the only available data
|
||||
source or the one flagged `@Primary` amongst the existing ones), the prefix is `datasource.primary`
|
||||
* If the data source bean name ends with `dataSource`, the prefix is the name of the bean without
|
||||
it (i.e. `datasource.batch` for `batchDataSource`)
|
||||
* In all other cases, the name of the bean is used
|
||||
|
||||
It is possible to override part or all of those defaults by registering a bean with a customized
|
||||
version of `DataSourcePublicMetrics`. Spring Boot provides those metadata for all supported
|
||||
datasource; you can provide a `DataSourceMetadata` implementation for your favorite data source,
|
||||
check `DatasourceMetadataProvidersConfiguration` for more details.
|
||||
|
||||
[[production-ready-recording-metrics]]
|
||||
=== Recording your own metrics
|
||||
|
||||
Reference in New Issue
Block a user