Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 对于带有camunda bpm spring boot starter rest hibernate属性的项目,其指标会受到影响,输出工作不正常(仅部分)_Spring Boot_Hibernate_Spring Boot Actuator_Camunda_Spring Micrometer - Fatal编程技术网

Spring boot 对于带有camunda bpm spring boot starter rest hibernate属性的项目,其指标会受到影响,输出工作不正常(仅部分)

Spring boot 对于带有camunda bpm spring boot starter rest hibernate属性的项目,其指标会受到影响,输出工作不正常(仅部分),spring-boot,hibernate,spring-boot-actuator,camunda,spring-micrometer,Spring Boot,Hibernate,Spring Boot Actuator,Camunda,Spring Micrometer,Spring Boot应用程序使用为应用程序提供Hibernate/Entity Manager的camunda bpm Spring Boot starter rest。为了设置Spring Boot Actuator Prometheus(Actuator)指标,我们在应用程序中添加了这一行。properties: spring.jpa.properties.hibernate.generate_statistics=true 之后,以下详细信息开始输出到标准输出: 2020-11-16

Spring Boot应用程序使用为应用程序提供Hibernate/Entity Manager的
camunda bpm Spring Boot starter rest
。为了设置Spring Boot Actuator Prometheus(Actuator)指标,我们在
应用程序中添加了这一行。properties

spring.jpa.properties.hibernate.generate_statistics=true
之后,以下详细信息开始输出到标准输出:

2020-11-16 16:14:49.923  INFO 1345328 --- [ingJobExecutor]] i.StatisticalLoggingSessionEventListener : Session Metrics {
    547400 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    0 nanoseconds spent preparing 0 JDBC statements;
    0 nanoseconds spent executing 0 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0 collections);
    0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0 collections)
}
除了获取非零的JDBC连接外,它们都不包含其他内容的统计信息,而JDBC语句实际上是准备和执行的。那么,触发此类日志的事件是什么,而实际上从未写入执行的jdbc语句的CONU

在正确配置的Spring Boot应用程序中,这些内容会按照预期进行记录,如:

17:18:59.313 [http-nio-8080-exec-3] INFO  o.h.e.i.StatisticalLoggingSessionEventListener - Session Metrics {
    1063300 nanoseconds spent acquiring 1 JDBC connections;
    0 nanoseconds spent releasing 0 JDBC connections;
    117600 nanoseconds spent preparing 1 JDBC statements;
    739400 nanoseconds spent executing 1 JDBC statements;
    0 nanoseconds spent executing 0 JDBC batches;
    0 nanoseconds spent performing 0 L2C puts;
    0 nanoseconds spent performing 0 L2C hits;
    0 nanoseconds spent performing 0 L2C misses;
    1182400 nanoseconds spent executing 1 flushes (flushing a total of 14 entities and 0 collections);
    5700 nanoseconds spent executing 1 partial-flushes (flushing a total of 0 entities and 0 collections)
至于指标,输出到/actuator/prometheus,它看起来也缺少一些细节,但根本不是空的,有一些相互矛盾的输出:

# HELP hibernate_transactions_total The number of transactions we know to have been successful
# TYPE hibernate_transactions_total counter
hibernate_transactions_total{entityManagerFactory="entityManagerFactory",result="success",} 2231.0
hibernate_transactions_total{entityManagerFactory="entityManagerFactory",result="failure",} 1.0
# HELP hibernate_collections_recreates_total The number of collections recreated
# TYPE hibernate_collections_recreates_total counter
hibernate_collections_recreates_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_cache_natural_id_puts_total The number of cacheable naturalId lookups put in cache
# TYPE hibernate_cache_natural_id_puts_total counter
hibernate_cache_natural_id_puts_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_cache_update_timestamps_requests_total The number of timestamps successfully retrieved from cache
# TYPE hibernate_cache_update_timestamps_requests_total counter
hibernate_cache_update_timestamps_requests_total{entityManagerFactory="entityManagerFactory",result="miss",} 0.0
hibernate_cache_update_timestamps_requests_total{entityManagerFactory="entityManagerFactory",result="hit",} 0.0
# HELP hibernate_sessions_open_total Sessions opened
# TYPE hibernate_sessions_open_total counter
hibernate_sessions_open_total{entityManagerFactory="entityManagerFactory",} 2232.0
# HELP hibernate_entities_inserts_total The number of entity inserts
# TYPE hibernate_entities_inserts_total counter
hibernate_entities_inserts_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_cache_update_timestamps_puts_total The number of timestamps put in cache
# TYPE hibernate_cache_update_timestamps_puts_total counter
hibernate_cache_update_timestamps_puts_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_cache_query_puts_total The number of cacheable queries put in cache
# TYPE hibernate_cache_query_puts_total counter
hibernate_cache_query_puts_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_statements_total The number of prepared statements that were acquired
# TYPE hibernate_statements_total counter
hibernate_statements_total{entityManagerFactory="entityManagerFactory",status="closed",} 0.0
hibernate_statements_total{entityManagerFactory="entityManagerFactory",status="prepared",} 0.0
# HELP hibernate_second_level_cache_puts_total The number of cacheable entities/collections put in the cache
# TYPE hibernate_second_level_cache_puts_total counter
hibernate_second_level_cache_puts_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_second_level_cache_requests_total The number of cacheable entities/collections successfully retrieved from the cache
# TYPE hibernate_second_level_cache_requests_total counter
hibernate_second_level_cache_requests_total{entityManagerFactory="entityManagerFactory",result="miss",} 0.0
hibernate_second_level_cache_requests_total{entityManagerFactory="entityManagerFactory",result="hit",} 0.0
# HELP hibernate_entities_loads_total The number of entity loads
# TYPE hibernate_entities_loads_total counter
hibernate_entities_loads_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_entities_deletes_total The number of entity deletes
# TYPE hibernate_entities_deletes_total counter
hibernate_entities_deletes_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_query_natural_id_executions_max_seconds The maximum query time for naturalId queries executed against the database
# TYPE hibernate_query_natural_id_executions_max_seconds gauge
hibernate_query_natural_id_executions_max_seconds{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_cache_natural_id_requests_total The number of cached naturalId lookups successfully retrieved from cache
# TYPE hibernate_cache_natural_id_requests_total counter
hibernate_cache_natural_id_requests_total{entityManagerFactory="entityManagerFactory",result="miss",} 0.0
hibernate_cache_natural_id_requests_total{entityManagerFactory="entityManagerFactory",result="hit",} 0.0
# HELP hibernate_sessions_closed_total Sessions closed
# TYPE hibernate_sessions_closed_total counter
hibernate_sessions_closed_total{entityManagerFactory="entityManagerFactory",} 2232.0
# HELP hibernate_flushes_total The global number of flushes executed by sessions (either implicit or explicit)
# TYPE hibernate_flushes_total counter
hibernate_flushes_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_query_executions_total The number of executed queries
# TYPE hibernate_query_executions_total counter
hibernate_query_executions_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_collections_fetches_total The number of collection fetches
# TYPE hibernate_collections_fetches_total counter
hibernate_collections_fetches_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_optimistic_failures_total The number of StaleObjectStateExceptions that have occurred
# TYPE hibernate_optimistic_failures_total counter
hibernate_optimistic_failures_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_entities_fetches_total The number of entity fetches
# TYPE hibernate_entities_fetches_total counter
hibernate_entities_fetches_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_cache_query_requests_total The number of cached queries successfully retrieved from cache
# TYPE hibernate_cache_query_requests_total counter
hibernate_cache_query_requests_total{entityManagerFactory="entityManagerFactory",result="miss",} 0.0
hibernate_cache_query_requests_total{entityManagerFactory="entityManagerFactory",result="hit",} 0.0
# HELP hibernate_collections_deletes_total The number of collection deletes
# TYPE hibernate_collections_deletes_total counter
hibernate_collections_deletes_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_query_executions_max_seconds The time of the slowest query
# TYPE hibernate_query_executions_max_seconds gauge
hibernate_query_executions_max_seconds{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_connections_obtained_total Get the global number of connections asked by the sessions (the actual number of connections used may be much smaller depending whether you use a connection pool or not)
# TYPE hibernate_connections_obtained_total counter
hibernate_connections_obtained_total{entityManagerFactory="entityManagerFactory",} 2232.0
# HELP hibernate_entities_updates_total The number of entity updates
# TYPE hibernate_entities_updates_total counter
hibernate_entities_updates_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_collections_loads_total The number of collection loads
# TYPE hibernate_collections_loads_total counter
hibernate_collections_loads_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_collections_updates_total The number of collection updates
# TYPE hibernate_collections_updates_total counter
hibernate_collections_updates_total{entityManagerFactory="entityManagerFactory",} 0.0
# HELP hibernate_query_natural_id_executions_total The number of naturalId queries executed against the database
# TYPE hibernate_query_natural_id_executions_total counter
hibernate_query_natural_id_executions_total{entityManagerFactory="entityManagerFactory",} 0.0
因此,只有sessions计数器是真实的,而其他计数器则不存在

hibernate_query_executions_max_seconds{entityManagerFactory="entityManagerFactory",} 0.0
这里看起来不一致,如果有这么多事务,那么最慢的一个怎么可能是0-long

所以,这很可能是因为
EntityManager
使用bpm camunda starter进行初始化,而不是我们的应用程序bean本身?如何解决这一问题,并让那些优秀的人才被正确地挑选出来?也许度量收集器可以以某种方式注入到那里

UPD:

我尝试检查EntitymanagerFactory中的内容,并尝试使用新值更新它。根据标准,它要求hibernate.metrics为true

package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.persistence.EntityManagerFactory;
import java.util.logging.Logger;

@Component
public class HibernatePropertiesInterceptor {

    private static final Logger LOG
            = Logger.getLogger(HibernatePropertiesInterceptor.class.getName());

    @Autowired
    private EntityManagerFactory entityManagerFactory;

    @PostConstruct
    public void init() {
        LOG.info("Changing hibernate metrics-related properties");
        LOG.info("Current hibernate properties are "+entityManagerFactory.getProperties().keySet());
        LOG.info("Current hibernate.generate_statistics value is "+entityManagerFactory.getProperties().get("hibernate.generate_statistics"));
        entityManagerFactory.getProperties().put("hibernate.generate_statistics","true");
        LOG.info("Updated hibernate properties are "+entityManagerFactory.getProperties().keySet());
        LOG.info("Updated hibernate.generate_statistics value is "+entityManagerFactory.getProperties().get("hibernate.generate_statistics"));
    }
}

事实证明,
hibernate.metrics
已经是真的了!所以,我不知道要检查什么以及如何使用仪器来显示真实的统计数据。看起来,
EntityManager
真的做到了预期的所有事情,所以这可能是因为camunda在大多数情况下都不使用实体管理器?或者什么?

我还认为这是因为
EntityManager
不是由spring上下文管理的bean。您是否可以尝试使用
EntityManager
的bean创建配置类,就像从
ProcessEngine
获取在
SpringProcessEngineServiceConfiguration
中创建的其他bean一样

如下图所示:

@Bean
public EntityManagerFactory getEntityManagerFactory(ProcessEngineConfiguration engineConfiguration) {
    return engineConfiugration.getSessionFactories().get(EntityManagerSession.class); 
}


另外,这只是一个尝试和错误,我还没有尝试过,但至少它应该给你提供
EntityManager
的bean。请参阅
ProcessEngineConfigurationImpl.java
类的
initJpa()
方法。

与camunda engine 7.13.0一样,没有
.getSessionFactorys()
那么访问会话工厂的另一种方法是什么呢?检查ProcessEngineConfigurationImpl,它应该有初始化jpa的方法和获取它的方法。只需使用getter返回bean即可。我已经尝试过这个肮脏的黑客(接口本身缺少getSessionFactory,只有impl):
@bean
公共EntityManager工厂getEntityManager工厂(ProcessEngineConfiguration engineConfiguration){return(EntityManager工厂)(ProcessEngineConfigurationImpl)engineConfiguration).GetSessionFactorys().get(EntityManagerSession.class);}
现在获取循环引用错误:为了调查历史,请保留它确定。。我们会回复您:)