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

SQL graphs not recording sql queries on Spring Boot Application, Tomcat 10 #1155

Open
ProgrammingPete opened this issue Apr 11, 2023 · 7 comments

Comments

@ProgrammingPete
Copy link

ProgrammingPete commented Apr 11, 2023

Versions:
JavaMelody 1.92.0
Tomcat 10.1.5
OpenJDK Runtime Environment, 17.0.6+10-LTS

Hello,

I have and application that is used within Tomcat, that has its datasources stored within a context.xml file. The application is Spring Boot, and for some reason the sql queries after hitting an endpoint is not being shown on the graph. There is no indication of errors in the debug logs of Java Melody. I have a Config class within my Spring application.

Tue Apr 11 14:24:26 EDT 2023     DEBUG     Spring JNDI factory wrapped: jee:jndi-lookup#3502e5e6
Tue Apr 11 14:24:26 EDT 2023     DEBUG     Spring JNDI factory wrapped: jee:jndi-lookup#66690250
Tue Apr 11 14:24:26 EDT 2023     DEBUG     Spring JNDI factory wrapped: jee:jndi-lookup#4a5f2bf9
Tue Apr 11 14:24:26 EDT 2023     DEBUG     Spring JNDI factory wrapped: jee:jndi-lookup#1cfebeaf
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody listener init started
Tue Apr 11 14:24:27 EDT 2023     DEBUG     datasources found in JNDI: [java:comp/env/jdbc/DataSource1, java:comp/env/jdbc/DataSource2, java:comp/env/jdbc/DataSource3, java:comp/env/jdbc/DataSource4]
Tue Apr 11 14:24:27 EDT 2023     DEBUG     datasource rebinded: java:comp/env/jdbc/DataSource1 from class org.apache.tomcat.jdbc.pool.DataSource to class jdk.proxy2.$Proxy99
Tue Apr 11 14:24:27 EDT 2023     DEBUG     datasource rebinded: java:comp/env/jdbc/DataSource2 from class org.apache.tomcat.jdbc.pool.DataSource to class jdk.proxy2.$Proxy99
Tue Apr 11 14:24:27 EDT 2023     DEBUG     datasource rebinded: java:comp/env/jdbc/DataSource3 from class org.apache.tomcat.jdbc.pool.DataSource to class jdk.proxy2.$Proxy99
Tue Apr 11 14:24:27 EDT 2023     DEBUG     datasource rebinded: java:comp/env/jdbc/DataSource4 from class org.apache.tomcat.jdbc.pool.DataSource to class jdk.proxy2.$Proxy99
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody listener init done in 7 ms
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody filter init started
Tue Apr 11 14:24:27 EDT 2023     DEBUG     OS: Windows 10 , amd64/64
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Java: OpenJDK Runtime Environment, 17.0.6+10-LTS
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Server: Apache Tomcat/10.1.5
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Webapp context: /search-services-v2
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody version: 1.92.0
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody classes loaded from: file:/C:/Melody/NGPUB/lib/javamelody-core-1.92.0.jar
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Application type: Classic
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Application version: null
Tue Apr 11 14:24:27 EDT 2023     DEBUG     log listeners initialized
Tue Apr 11 14:24:27 EDT 2023     DEBUG     datasources found in JNDI: [java:comp/env/jdbc/datasource1, java:comp/env/jdbc/datasource2, java:comp/env/jdbc/datasource3, java:comp/env/jdbc/datasource4]
Tue Apr 11 14:24:27 EDT 2023     DEBUG     counters initialized
Tue Apr 11 14:24:27 EDT 2023     DEBUG     counters data read from files in C:\SS\temp\javamelody\search-services-v2_<REDACTED>
Tue Apr 11 14:24:27 EDT 2023     DEBUG     collect task scheduled every 60s
Tue Apr 11 14:24:27 EDT 2023     DEBUG     first collect of data done
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody filter init done in 643 ms
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody filter init started
Tue Apr 11 14:24:27 EDT 2023     DEBUG     OS: Windows 10 , amd64/64
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Java: OpenJDK Runtime Environment, 17.0.6+10-LTS
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Server: Apache Tomcat/10.1.5
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Webapp context: /search-services-v2
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody version: 1.92.0
Tue Apr 11 14:24:27 EDT 2023     DEBUG     JavaMelody classes loaded from: file:/C:/Melody/NGPUB/lib/javamelody-core-1.92.0.jar
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Application type: Classic
Tue Apr 11 14:24:27 EDT 2023     DEBUG     Application version: null
Tue Apr 11 14:24:27 EDT 2023     DEBUG     log listeners initialized
Tue Apr 11 14:24:27 EDT 2023     DEBUG     datasources found in JNDI: [java:comp/env/jdbc/DataSource1, java:comp/env/jdbc/DataSource2, java:comp/env/jdbc/DataSource3, java:comp/env/jdbc/DataSource4]
Tue Apr 11 14:24:27 EDT 2023     DEBUG     counters initialized
Tue Apr 11 14:24:27 EDT 2023     DEBUG     counters data read from files in C:\SS\temp\javamelody\search-services-<REDACTED>
Tue Apr 11 14:24:27 EDT 2023     INFO     Do not use the same storage directory with multiple instances or it will cause data loss. Configure the storage-directory parameter if needed.
Tue Apr 11 14:24:27 EDT 2023     DEBUG     collect task scheduled every 60s
Tue Apr 11 14:24:28 EDT 2023     DEBUG     first collect of data done
Tue Apr 11 14:24:28 EDT 2023     DEBUG     JavaMelody filter init done in 154 ms

Also we did have only one type of query be recorded here:
sql_stats2

This query occurs when accessing the database statistics link within the JavaMelody homepage

@evernat
Copy link
Member

evernat commented Apr 23, 2023

I see that sql queries are not monitored.

There are several strange things:

  • as seen in the logs, the javamelody filter is initialized twice for the same webapp instead of once (there is some configuration which is too much in your webapp)
  • javamelody-core jar file seems to be in some lib directory and not in your webapp (for example in WEB-INF/lib) or in your Spring-Boot app
  • you use Spring Boot, but you do not use the javamelody-spring-boot-starter which simplifies the javamelody integration: https://github.com/javamelody/javamelody/wiki/SpringBootStarter

So I suggest to use the javamelody-spring-boot-starter as a dependency of your app. Note that with the javamelody-spring-boot-starter, the datasources declared in Spring's context don't need to be declared in JNDI to be monitored. But you can still declare them in JNDI if you want.
You can use the new javamelody-spring-boot-starter v2.x for Spring Boot 3 or the javamelody-spring-boot-starter v1.x for Spring Boot 2.

Does it work for you?

Otherwise, can you give the source of a sample project using Maven to reproduce the issue?

@ProgrammingPete
Copy link
Author

ProgrammingPete commented Apr 26, 2023

Thanks for the response @evernat !

I have tried the following:

  1. I had both javamelody-core and springbootstarter in my pom.xml file. I removed one of them and now there are less logs. See below
  2. I removed the externalized jar and now it is in the WEB_IF/lib folder

I believe now it is only loaded in once.... but still the same issue. I will see if I can get a small version of the application to you

Wed Apr 26 15:09:51 EDT 2023     DEBUG     spring interceptor initialized
Wed Apr 26 15:09:51 EDT 2023     DEBUG     spring interceptor initialized
Wed Apr 26 15:09:51 EDT 2023     DEBUG     spring interceptor initialized
Wed Apr 26 15:09:51 EDT 2023     DEBUG     spring interceptor initialized
Wed Apr 26 15:09:51 EDT 2023     DEBUG     spring interceptor initialized
Wed Apr 26 15:09:51 EDT 2023     DEBUG     spring interceptor initialized
Wed Apr 26 15:09:52 EDT 2023     DEBUG     Spring JNDI factory wrapped: jee:jndi-lookup#475d8f1b
Wed Apr 26 15:09:52 EDT 2023     DEBUG     Spring JNDI factory wrapped: jee:jndi-lookup#79424de5
Wed Apr 26 15:09:52 EDT 2023     DEBUG     Spring JNDI factory wrapped: jee:jndi-lookup#11dec6bd
Wed Apr 26 15:09:52 EDT 2023     DEBUG     Spring JNDI factory wrapped: jee:jndi-lookup#5b4374d7
Wed Apr 26 15:09:54 EDT 2023     DEBUG     JavaMelody listener init started
Wed Apr 26 15:09:54 EDT 2023     DEBUG     datasources found in JNDI: [java:comp/env/jdbc/Datasource1, java:comp/env/jdbc/Datasource2, java:comp/env/jdbc/Datasource3, java:comp/env/jdbc/Datasource4]
Wed Apr 26 15:09:54 EDT 2023     DEBUG     datasource rebinded: java:comp/env/jdbc/Datasource1 from class org.apache.tomcat.jdbc.pool.DataSource to class jdk.proxy2.$Proxy101
Wed Apr 26 15:09:54 EDT 2023     DEBUG     datasource rebinded: java:comp/env/jdbc/Datasource2 from class org.apache.tomcat.jdbc.pool.DataSource to class jdk.proxy2.$Proxy101
Wed Apr 26 15:09:54 EDT 2023     DEBUG     datasource rebinded: java:comp/env/jdbc/Datasource3 from class org.apache.tomcat.jdbc.pool.DataSource to class jdk.proxy2.$Proxy101
Wed Apr 26 15:09:54 EDT 2023     DEBUG     datasource rebinded: java:comp/env/jdbc/Datasource4 from class org.apache.tomcat.jdbc.pool.DataSource to class jdk.proxy2.$Proxy101
Wed Apr 26 15:09:54 EDT 2023     DEBUG     JavaMelody listener init done in 16 ms
Wed Apr 26 15:09:54 EDT 2023     DEBUG     JavaMelody filter init started
Wed Apr 26 15:09:54 EDT 2023     DEBUG     OS: Windows 10 , amd64/64
Wed Apr 26 15:09:54 EDT 2023     DEBUG     Java: OpenJDK Runtime Environment, 17.0.6+10-LTS
Wed Apr 26 15:09:54 EDT 2023     DEBUG     Server: Apache Tomcat/10.1.5
Wed Apr 26 15:09:54 EDT 2023     DEBUG     Webapp context: /search-services-v2
Wed Apr 26 15:09:54 EDT 2023     DEBUG     JavaMelody version: 2.0.0
Wed Apr 26 15:09:54 EDT 2023     DEBUG     JavaMelody classes loaded from: file:/C:/SS/webapps/search-services-v2/WEB-INF/lib/javamelody-core-2.0.0.jar
Wed Apr 26 15:09:54 EDT 2023     DEBUG     Application type: Classic
Wed Apr 26 15:09:54 EDT 2023     DEBUG     Application version: null
Wed Apr 26 15:09:54 EDT 2023     DEBUG     Host:<REDACTED>
Wed Apr 26 15:09:54 EDT 2023     DEBUG     log listeners initialized
Wed Apr 26 15:09:54 EDT 2023     DEBUG     datasources found in JNDI: [java:comp/env/jdbc/Datasource1, java:comp/env/jdbc/Datasource2, java:comp/env/jdbc/Datasource3, java:comp/env/jdbc/Datasource4]
Wed Apr 26 15:09:54 EDT 2023     DEBUG     counters initialized
Wed Apr 26 15:09:54 EDT 2023     DEBUG     counters data read from files in C:\SS\temp\javamelody\search-services-v2_<redacted>
Wed Apr 26 15:09:54 EDT 2023     DEBUG     collect task scheduled every 60s
Wed Apr 26 15:09:55 EDT 2023     DEBUG     first collect of data done
Wed Apr 26 15:09:55 EDT 2023     DEBUG     JavaMelody filter init done in 1058 ms

I also have a javamelodyConfig file as definded hereL
JavaMelodyConfig .java.txt

@evernat
Copy link
Member

evernat commented May 5, 2023

I believe now it is only loaded in once

yes.

And the javamelody-spring-boot-starter already has its own JavaMelodyAutoConfiguration.
So you don't need your JavaMelodyConfig class.

I will see if I can get a small version of the application to you

yes, thank you

@ProgrammingPete
Copy link
Author

ProgrammingPete commented May 9, 2023

So I am working with my team and we have a few questions to gain an understanding of the app set up with regards to Sping boot:

What all JAR files are required to make the application work?
Where should the JAR files be placed?
What are the configurations needed within the SpringBoot app to get it working?

@evernat
Copy link
Member

evernat commented May 21, 2023

What all JAR files are required to make the application work?

As said in the javamelody Spring Boot page, if you use Maven (or Gradle), then you need only one dependency on javamelody-spring-boot-starter :
https://github.com/javamelody/javamelody/wiki/SpringBootStarter
Automatically, Maven will add the following jar files in the classpath :

  • javamelody-spring-boot-starter
  • javamelody-core
  • jrobin
  • spring-boot-starter-aop

Where should the JAR files be placed?

Maven puts all dependencies in WEB-INF/lib if you make a war file. Or it puts all dependencies in BOOT-INF/lib if you make a runnable jar with Spring Boot.

What are the configurations needed within the SpringBoot app to get it working?

just the Maven dependency as said in the Spring Boot page above. It has an auto-configuration to initialize itself.
You may add javamelody properties in your application.yml or application.properties but that is not required to start, including sql monitoring. You can see an example of javamelody properties for Spring Boot at https://github.com/javamelody/javamelody/wiki/SpringBootStarter

@evernat
Copy link
Member

evernat commented Aug 2, 2023

it's ok for you now ?

@ProgrammingPete
Copy link
Author

Still having the same issue. I would love to try to reproduce it with a small build, but I have not found the time.

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

No branches or pull requests

2 participants