question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spring Boot 2 not collecting DataSource metrics

See original GitHub issue

Hello,

I recently upgraded my spring boot application to 2.0.1 to make use of the new micrometer Prometheus feature. According to the documentation, micrometer should automatically instrument all available DataSource objects and output the metrics as gauges.

However, it seems like that feature isn’t working in my case. Accessing /actuator/prometheus I can see the various metrics micrometer collects, but no JDBC DataSource metrics.

My datasource is configured in its own spring configuration class (credentials omitted):


@Configuration
class DataSourceConfiguration {

    @Bean
    @Primary
    fun dataSource(): DataSource {
        val dataSource = org.apache.tomcat.jdbc.pool.DataSource()

        dataSource.driverClassName = "org.postgresql.Driver"
        dataSource.url = "jdbc:postgresql://$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB_NAME"
        dataSource.username = POSTGRES_USER
        dataSource.password = POSTGRES_PASSWORD

        dataSource.initialSize = 2
        dataSource.maxActive = 8
        dataSource.maxIdle = 4
        dataSource.minIdle = 1

        dataSource.logValidationErrors = true

        dataSource.timeBetweenEvictionRunsMillis = 34_000
        dataSource.minEvictableIdleTimeMillis = 55_000

        dataSource.maxWait = 10_000

        dataSource.isRemoveAbandoned = true
        dataSource.removeAbandonedTimeout = 60

        return dataSource
    }
}

Is there anything else I need to configure for micrometer to start collecting datasource metrics?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexLardschneidercommented, May 2, 2018

Thanks for the hints. For anyone else wondering about the solution:

val provider = DataSourcePoolMetadataProvider { TomcatDataSourcePoolMetadata(dataSource) }

DataSourcePoolMetrics(dataSource as javax.sql.DataSource, provider, POSTGRES_DB_NAME, emptyList()).bindTo(registry)
1reaction
jkschneidercommented, May 2, 2018

@AlexLardschneider Only datasources autoconfigured by Spring Boot are automatically instrumented.

However, you can wire it manually:

@Configuration
class DataSourceConfiguration {

    @Bean
    @Primary
    fun dataSource(registry: MeterRegistry): DataSource {
        val dataSource = org.apache.tomcat.jdbc.pool.DataSource()

        ...
        DataSourcePoolMetrics(dataSource, listOf({ ds -> TomcatDataSourcePoolMetadata(ds) }), "tomcatDbPool").bindTo(registry)
        return dataSource
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring boot 2 Prometheus not pulling db metrics
@Anoukh I have prometheus endpoint running but cannot find any datasource metrics.
Read more >
57. Metrics - Spring
Spring Boot provides a metrics endpoint that can be used diagnostically to examine the metrics collected by an application. The endpoint is not...
Read more >
49. Metrics - Spring
Spring Boot Actuator includes a metrics service with 'gauge' and 'counter' support. A 'gauge' records a single value; and a 'counter' records a...
Read more >
Micrometer: Spring Boot 2's new application metrics collector
Micrometer is a dimensional-first metrics collection facade whose aim is to allow you to time, count, and gauge your code with a vendor ......
Read more >
54. Metrics - Spring
54.1 Getting started. Spring Boot auto-configures a composite MeterRegistry and adds a registry to the composite for each of the supported implementations that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found