Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for per-query metrics in Hibernate statistics #1006

Closed
jfougere opened this issue Nov 14, 2018 · 3 comments · Fixed by #1461
Closed

Add support for per-query metrics in Hibernate statistics #1006

jfougere opened this issue Nov 14, 2018 · 3 comments · Fixed by #1461
Labels
enhancement A general enhancement
Milestone

Comments

@jfougere
Copy link

Current implementation of HibernateMetrics exposed counters & also time gauges for max execution queries, however no tags are provided in order to know about which query those metrics are related.

I believe this could be very useful and could be done using current Hibernate Statistics class implementation.

For example the TimeGauge hibernate.query.executions.max could be tag with a query tag and the value could be provided by Statistics.getQueryExecutionMaxTimeQueryString().

Also the other counter metrics could be retrieved by query using:

  • Statistics.getQueries()
  • Statistics.getQueryStatistics(String query)

What do u think ?

@jkschneider jkschneider added this to the 1.2.0 milestone Dec 1, 2018
@jkschneider
Copy link
Contributor

Sounds great. A PR would be welcome!

@shakuzen shakuzen added enhancement A general enhancement help wanted An issue that a contributor can help us with labels Jun 17, 2019
@shakuzen shakuzen modified the milestones: 1.2.0 (non-LTS), 1.x Jun 17, 2019
@shakuzen shakuzen modified the milestones: 1.x, 1.3.0 Jun 29, 2019
@shakuzen shakuzen modified the milestones: 1.3.0, 1.4.0 Oct 1, 2019
shakuzen pushed a commit that referenced this issue Mar 19, 2020
Adds a new MeterBinder for metrics on Hibernate queries when Hibernate statistics are enabled.
@shakuzen shakuzen removed the help wanted An issue that a contributor can help us with label Mar 19, 2020
@chrisatrotter
Copy link

Could you provide an example of how to use the per-query metric support in Hibernate statistics? I've tried to find out how to have this functionality work with Spring boot through the spring-actuator to expose hibernate statistics with per-query metrics. I've had little success until i found this great change! 🙌

@shakuzen
Copy link
Member

shakuzen commented Mar 3, 2022

Note that Hibernate metrics have moved to the Hibernate project, in the hibernate-micrometer module.

You need to enable statistics for Hibernate by setting the hibernate.generate_statistics configuration to true, which can be done with Spring Boot application properties like spring.jpa.properties.hibernate.generate_statistics=true. See the Spring Boot documentation. You will need to provide an instance of HibernateQueryMetrics as a bean or bind it yourself, since Spring Boot does not currently auto-configure it. You can do that in a @Configuration class, for example, like the following:

@Bean
MeterBinder hibernateQueryMetrics(EntityManagerFactory entityManager) {
    return new HibernateQueryMetrics(entityManager.unwrap(SessionFactoryImplementor.class), "mySess", Tags.empty());
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants