micrometer icon indicating copy to clipboard operation
micrometer copied to clipboard

JDBC Metrics

Open cemo opened this issue 6 years ago • 18 comments

Having metrics about database is very important. JDBC level metrics would be very nice like:

The total number of database reads
The total number of database writes
Number of reads per second (per minute, 5 minutes & 15 minutes)
Number of writes per second (per minute, 5 minutes & 15 minutes)
Average/median/percentile query times for reads & for writes

cemo avatar Jun 01 '18 08:06 cemo

Here is a sample project: https://github.com/soulgalore/jdbcmetrics

This one seems also very usabe

https://github.com/gquintana/metrics-sql

cemo avatar Jun 01 '18 08:06 cemo

I like the layered approach of metrics-sql (apply at either driver, connection, or datasource level).

jkschneider avatar Jun 04 '18 22:06 jkschneider

... or https://github.com/ttddyy/datasource-proxy

ohr avatar Jun 25 '18 06:06 ohr

@ohr this is fantastic. Thanks for sharing.

cemo avatar Jun 25 '18 18:06 cemo

I have a demo that uses a forked version of the metrics-sql library mentioned above to get metrics in micrometer format. https://github.com/pjfanning/slick-micrometer

I haven't modified the metrics to use micrometer tags yet.

pjfanning avatar Jul 15 '18 14:07 pjfanning

@cemo https://spring.io/blog/2018/03/16/micrometer-spring-boot-2-s-new-application-metrics-collector - hikaricp has support for gathering micrometer metrics

pjfanning avatar Jul 15 '18 14:07 pjfanning

@pjfanning It is metrics for connection pool not JDBC.

cemo avatar Jul 15 '18 14:07 cemo

@cemo if you want jdbc metrics, see my comment about slick-micrometer sample

pjfanning avatar Jul 15 '18 14:07 pjfanning

Thanks I will take a look.

cemo avatar Jul 15 '18 14:07 cemo

@pjfanning nice job.

cemo avatar Jul 15 '18 15:07 cemo

Brave's py6spy adds some instrumentation to the DB in terms of tracing - https://github.com/openzipkin/brave/tree/master/instrumentation/p6spy

marcingrzejszczak avatar Oct 05 '18 14:10 marcingrzejszczak

FlexyPool has flexy-micrometer-metrics module. https://github.com/vladmihalcea/flexy-pool

here is a metrics list. https://github.com/vladmihalcea/flexy-pool/wiki/User-Guide#metrics

wreulicke avatar Dec 13 '19 16:12 wreulicke

Is it possible to get JDBC Metrics that show durations of each SQL query run with micrometer? Or is this something still in the making? Just came across this issue and see that it is still not resolved, so I assume this still has to be done?

chrisatrotter avatar Mar 03 '22 12:03 chrisatrotter

There is for sure a plan to add such support out of the box in Spring JDBC.

marcingrzejszczak avatar Mar 03 '22 13:03 marcingrzejszczak

I see that you've been working already been working on having this out of the box in Spring JDBC in previous milestones. Any thoughts on when this might be supported?

chrisatrotter avatar Mar 03 '22 13:03 chrisatrotter

We're planning to add it to Spring Framework 6. We've added similar support in Spring Cloud Sleuth 3.1.x but it's more about tracing than metrics.

marcingrzejszczak avatar Mar 03 '22 13:03 marcingrzejszczak

Does this feature already entered 6.0-Msomething code or at least is it still planned in 6.0-GA? If yes, what will be exactly available? (e.g. which metrics)

segaura avatar Aug 05 '22 12:08 segaura

It will be a third party project with autoconfiguration support for Spring Boot, see here: https://github.com/jdbc-observations/datasource-micrometer (work in progress).

jonatan-ivanov avatar Aug 05 '22 18:08 jonatan-ivanov

With the new Micrometer Observation API in micrometer 1.10.0, JDBC observation is supported by the datasource-micrometer library. I will make a datasource-micrometer GA release, once Spring Boot 3 goes GA.

For metrics, you can see the documentation for what metrics are available by default. However, it does not create query-type-based metrics (e.g. read/write described in this issue) because it requires query parsing. Though it is possible to customize such behavior, similar to this "How to Modify the Query in Span". Instead of modifying queries in the tag here, you can apply your query parser to detect query type, then create appropriate meters.

In light of the datasource-micrometer with Observation API, I am closing this issue.

ttddyy avatar Nov 09 '22 02:11 ttddyy