0

I'm using Spring Boot with a pooled datasorce

datasource:
  type: org.apache.tomcat.jdbc.pool.DataSource
  driverClassName: com.mysql.jdbc.Driver
  url:  ...
  username: ...
  password: ...
  tomcat:
    max-active: 50
    max-idle: 50
    testOnBorrow: true
    validationQuery: select 1;
    validationInterval: 30000

This configuration is properly taken as the logfile contains 10x the following line:

16:27:52.191 [] [  restartedMain] DEBUG g.apache.tomcat.jdbc.pool.PooledConnection - Instantiating driver using class: com.mysql.jdbc.Driver [url=...]

After that, I start using the application and made some database requests. The DAO implementation is using JPAContext und EntityManager, autowired by Spring and works perfectly returning the expected results from the database.

@Autowired
private JpaContext jpaContext;

@Autowired
private EntityManager em;

EntityManager em = jpaContext.getEntityManagerByManagedType(DownloadHistoryItemCustomEntity.class);
Query q = em.createNativeQuery(query, DownloadHistoryItemCustomEntity.class);

However, the Spring Boot metrics doesn't show any usage for that single datasource

http://localhost:8080/metrics    
  "datasource.primary.active": 0,
  "datasource.primary.usage": 0.0

Why there aren't values > 0 ?
I would expect values greater then zero !
Isn't 'primary' the right datasource ?

Dominik

Dominik
  • 1,332
  • 1
  • 15
  • 28

1 Answers1

0

datasource.primary.active is the current number of active connections. datasource.primary.usage is a value between 0 and 1 where 0 indicates that there are no active connections and 1 indicates that every connection in the pool is active. For the values to be non-zero, a database connection will have to be active when you make the request to the /metrics endpoint.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • 1
    While I made the requests in one browser window, the counter in the other browser window (refreshed 1/2 second later) shows zero. At least the number of active connections should be greater than zero because the connection isn't closed/removed right after the requests, isn't it ? – Dominik Aug 31 '16 at 07:59
  • It is. The connection is returned to the pool as soon as the work has completed, typically when the transaction that's coordinating the work is committed. That'll happen before the response is sent. – Andy Wilkinson Aug 31 '16 at 08:45