Search in sources :

Example 1 with DataSourcePoolMetadata

use of org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata in project spring-boot by spring-projects.

the class DataSourcePublicMetrics method initialize.

@PostConstruct
public void initialize() {
    DataSource primaryDataSource = getPrimaryDataSource();
    DataSourcePoolMetadataProvider provider = new DataSourcePoolMetadataProviders(this.providers);
    for (Map.Entry<String, DataSource> entry : this.applicationContext.getBeansOfType(DataSource.class).entrySet()) {
        String beanName = entry.getKey();
        DataSource bean = entry.getValue();
        String prefix = createPrefix(beanName, bean, bean.equals(primaryDataSource));
        DataSourcePoolMetadata poolMetadata = provider.getDataSourcePoolMetadata(bean);
        if (poolMetadata != null) {
            this.metadataByPrefix.put(prefix, poolMetadata);
        }
    }
}
Also used : DataSourcePoolMetadataProviders(org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProviders) DataSourcePoolMetadata(org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata) DataSourcePoolMetadataProvider(org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider) HashMap(java.util.HashMap) Map(java.util.Map) DataSource(javax.sql.DataSource) PostConstruct(javax.annotation.PostConstruct)

Example 2 with DataSourcePoolMetadata

use of org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata in project spring-boot by spring-projects.

the class DataSourcePublicMetrics method metrics.

@Override
public Collection<Metric<?>> metrics() {
    Set<Metric<?>> metrics = new LinkedHashSet<>();
    for (Map.Entry<String, DataSourcePoolMetadata> entry : this.metadataByPrefix.entrySet()) {
        String prefix = entry.getKey();
        prefix = (prefix.endsWith(".") ? prefix : prefix + ".");
        DataSourcePoolMetadata metadata = entry.getValue();
        addMetric(metrics, prefix + "active", metadata.getActive());
        addMetric(metrics, prefix + "usage", metadata.getUsage());
    }
    return metrics;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataSourcePoolMetadata(org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata) Metric(org.springframework.boot.actuate.metrics.Metric) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 DataSourcePoolMetadata (org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata)2 LinkedHashSet (java.util.LinkedHashSet)1 PostConstruct (javax.annotation.PostConstruct)1 DataSource (javax.sql.DataSource)1 Metric (org.springframework.boot.actuate.metrics.Metric)1 DataSourcePoolMetadataProvider (org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider)1 DataSourcePoolMetadataProviders (org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProviders)1