简体   繁体   English

通过 Spring 引导执行器公开 Hibernate 指标

[英]Exposing Hibernate metrics via Spring Boot Actuator

I was doing some research on how to expose Hibernate metrics via Prometheus via Spring Boot Actuator, but I was struggling to find out how to do that.我正在研究如何通过 Prometheus 通过 Spring Boot Actuator 公开 Hibernate 指标,但我一直在努力寻找如何做到这一点。

I added the following property to my Spring Boot: Application: spring.jpa.properties.hibernate.generate_statistics=true I added the following property to my Spring Boot: Application: spring.jpa.properties.hibernate.generate_statistics=true

But all that did was add logging from Hibernate.但所做的只是从 Hibernate 添加日志记录。 I found these two PRs from the Spring Boot project:我从 Spring Boot 项目中找到了这两个 PR:

but it looks like publishing Hibernate metrics via Spring Boot Actuator never made it in because of Micrometer adoption.但它看起来像通过 Spring Boot Actuator 发布 Hibernate 指标,因为采用了千分尺。

Is there a way to expose the metrics that the Hibernate EntityManagerFactory collects via Spring Boot Actuator?有没有办法公开 Hibernate EntityManagerFactory通过 Spring 引导执行器收集的指标?

Currently it is supported by Spring Boot out of the box.目前,Spring 支持开箱即用。

Besides the property, dependency org.hibernate:hibernate-micrometer has to be on classpath.除了属性,依赖org.hibernate:hibernate-micrometer必须在类路径上。 Compare Spring Actuator documentation .比较Spring 执行器文档

Previously you could create a HibernateQueryMetrics bean as described in this micrometer issue .以前,您可以创建一个HibernateQueryMetrics bean, 如此千分尺问题中所述。

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

Support for hibernate metrics has been moved from micrometer to hibernate project.对 hibernate 指标的支持已从千分尺移至 hibernate 项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM