Hikari ActiveConnections & TotalConnections not shown in JMX bean - java

I am trying to get properties like ActiveConnections & TotalConnections from hikaricp using Visual VM. But am unable to view it in JMX bean. Below are the details of my app.
Spring boot 1.5.9
Java 8
gradle 6.6
HikariCP 3.3.1
What I have already tried in configuring.
spring:
profiles:
active: dev
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:teradata://****
username: ****
password: "****"
jmx-enabled: true
maximum-pool-size: 20
minimum-idle: 5
hikari:
poolName: mypool
register-mbeans: true
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
I am trying to configure it just by changing the app yml file. Is that possible?
Below is the screenshot of Visual VM. I have also checked this in jconsole but the metrics doesn't show up.
One this to notice here is that the pool name is not changing as per my parameter
[1]: https://i.stack.imgur.com/2qa8r.png
Please tell me what am I doing wrong here?

Related

Issue in Running Jar file of Spring boot Gradle

I am not able to run the jar file of Spring Boot Gradle which I had created with ./gradlew clean bootJar jacocoMergeAll
and when I run in intellij with run button, I am able to run it.
and below is my commands which I had ran with intellij VM options which ran successfully but with jar this command does not work when I run the Jar file.
Below vm option is working one
-Dspring.profiles.active=local -Dserver.port=8080 -Dajp.port=0 -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc -Dspring.datasource.username=system -Dspring.datasource.password=MyPasswd123 -Dspring.config.additional-location=file:/Users/myUser/codebase/config/ -Dlogging.config=file:/Users/myUser/codebase/config/logback-spring.xml
Below running jar is not Working
java -Dspring.profiles.active=local -jar demo-0.1.0-SNAPSHOT.jar -Dserver.port=8080 -Dajp.port=0 -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc -Dspring.datasource.username=system -Dspring.datasource.password=MyPasswd123 -Dspring.config.additional-location=file:/Users/myUser/codebase/config/ -Dlogging.config=file:/Users/myUser/codebase/config/logback-spring.xml
I have tried with both -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521:OraDoc and -Dspring.datasource.url=jdbc:oracle:thin:#localhost:1521/OraDoc but none of this worked
when I run above jar command I get below error of not find the url
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (the profiles local are currently active).
my config file are under this directoy:
/Users/myUser/codebase/config/application.yml
/Users/myUser/codebase/config/application-local.yml
content of application.yml
server:
tomcat:
connectionTimeout: 300000
management:
endpoint:
mappings:
enabled: true
spring:
liquibase:
change-log: classpath:/db/changelog/db.changelog-master.xml
datasource:
driver-class-name: oracle.jdbc.driver.OracleDriver
hikari:
minimum-idle: 5
maximumPoolSize: 20
idleTimeout: 30000
maxLifetime: 2000000
connectionTimeout: 30000
poolName: factory-data-pool
jpa:
hibernate:
use-new-id-generator-mappings: false
ddl-auto: none
database-platform: org.hibernate.dialect.Oracle12cDialect
content of application-local.yml
server:
port: 8080
spring:
datasource:
url: jdbc:oracle:thin:#localhost:1521:OraDoc
username: system
password: MyPasswd123
liquibase:
contexts: local
Can someone please guide me on what wrong I am doing here?

Profiles ordering in migration from Spring Boot 2.3 to 2.4

I’m migrating an application from Spring Boot 2.3 to Spring Boot 2.4, I have some problems with profiles order loading.
In my application, I have some profiles :
default (application-default.yml) : default values for the application. There is a lot of default values, the goal is not to complicate the file application.yml, so it's very important to have this file
quality (application-quality.yml) : quality profile
environment profile (for example application-Dev.yml) : profile of the current environment. It must override application.yml and application-default.yml values
database profile for the environment (for example application-databaseDev.yml) : profile for the database connection for the current environment
In Spring Boot 2.3, configuration is :
application.yml
spring:
profiles:
include:
- default
redis:
jedis:
pool:
max-active: 4
application-default.yml
spring:
profiles:
include:
- quality
myApplication:
vcs:
url: https://default.url
cache:
enabled: true
application-Dev.yml
spring:
profiles:
include:
- databaseDev
myApplication:
cache:
enabled: false
I'm starting application with parameter --spring.profiles.active=Dev
In this case, here is the order of the active profile The following profiles are active: default,quality,Dev,databaseDev
This is order I want. For exemple value for key myApplication.cache.enabled is false
I read the documentation to migrate to Spring Boot 2.4, so my configuration is now :
application.yml
spring:
profiles:
group:
"Dev": "default, quality, databaseDev"
redis:
jedis:
pool:
max-active: 4
application-default.yml
myApplication:
vcs:
url: https://default.url
cache:
enabled: true
application-Dev.yml
myApplication:
cache:
enabled: false
But now I have the active profile The following profiles are active: Dev,default,quality,databaseDev
In this case the value for key myApplication.cache.enabled is true
Now profile Dev doesn't override default profile as 2.3 but inversely default profile override Dev profile.
Is there a way to modify the configuration to work as 2.3 (without using use-legacy-processing: true)? Did I make a mistake somewhere?
I found a solution that works :
Rename the profile Dev to dev and create a group named Dev
Here is the result :
application.yml
spring:
config:
import: classpath:application-groups.yml
redis:
jedis:
pool:
max-active: 4
application-groups.yml
spring:
profiles:
group:
"base": "default, quality"
"Dev": "base, databaseDev"
application-default.yml
myApplication:
vcs:
url: https://default.url
cache:
enabled: true
application-dev.yml
myApplication:
cache:
enabled: false
Starting with parameter --spring.profiles.active=Dev
The following profiles are active: Dev,base,default,quality,databaseDev
What do you think about this solution ?

Spring Boot 2.2.5 - spring.datasource.data property in yaml

Recently we upgraded to spring boot 2.2.5
We used to use the property spring.datasource.data to load SQL after "create" or "update" of the database.
Our Yaml looked like this:
--
spring:
profiles: default
application:
name:"EMBEDDED"
datasource:
url: "jdbc:postgresql://localhost/somedb"
driverClassName: org.postgresql.Driver
username: postgres
password: "some password"
data: "classpath*:data.sql"
jpa:
database: POSTGRESQL
show-sql: false
hibernate.ddl-auto: update
The important part is the "spring.datasource.data" property where we used to define a name of a SQL file that hibernate would run after updating the DB.
Note that we use the hibernate.ddl-auto to make that happen.
Now we have upgraded the spring boot and we also started using 2 data-sources as follows:
spring:
profiles: dev
application:
name:"EMBEDDED-DEV"
datasource:
src1:
jdbcUrl: "jdbc:sqlserver://localhost;databaseName=DB1"
username: user
password: password
initializationFailTimeout: 0
data: "classpath*:data.sql"
src2:
jdbcUrl: "jdbc:sqlserver://localhost;databaseName=db2"
username: user
password: password
initializationFailTimeout: 0
data: "classpath*:data.sql"
jpa:
database-platform: org.hibernate.dialect.SQLServer2012Dialect
show-sql: false
hibernate.format_sql: true
hibernate.ddl-auto: update
As you can see we have now 2 data sources, but when i try to add the "data" property as i used to do before i get this exception:
java.lang.RuntimeException: Property data does not exist on target class com.zaxxer.hikari.HikariConfig
Where should i put now the data property in order for it to work?

I need to set active profile in spring boot app though maven command but its taking default profile

I have 3 environments in my application i.e dev, prod, test i for that i separate files like application-prod.yml,application-dev.yml,applicaton-test.yml and also application.properties i am running command -> mvn spring-boot:run -Dspring.profiles.active=prod but its taking profile as a default profile
application.properties
server.port=8002
application-prod.yml
--------------------------
spring:
jpa:
show-sql: true
properties:
hibernate: dialect:org.hibernate.dialect.Oracle10gDialect
ddl-auto: update
datasource:
username: scott
password: tiger
url: jdbc:oracle:thin:#localhost:1521:xe
driver-class-name: oracle.jdbc.OracleDriver
app:
message : This for DevEnvironment connect to Oracle
logging:
level:
org:
springframework:
web: DEBUG
If you are using maven command then try the following to set the profile :
mvn spring-boot:run -Dspring-boot.run.profiles=foo,bar
The above command sets the run time spring profile through the maven plugin.
Official doc.

Spring Boot Admin does not detect service after restarting

I have an environment with different services. They all are deployed and managed by Docker images and Kubernetes. I also use spring-boot-admin in order to monitor them all and spring-cloud-kubernetes to discover all the services automatically.
This my properties file.
application.yml (In the SBA project)
server:
port: ${admin-server.port:8086}
tomcat:
remote-ip-header: x-forwarded-for
protocol-header: x-forwarded-proto
spring:
application:
name: admin-server
security:
user:
name: ${spring-security.admin.username:****}
password: ${spring-security.admin.password:****}
boot:
admin:
discovery:
ignored-services: admin-server
notify:
mail:
enabled: ${admin-mail.enabled:true}
to: ${admin-mail.recipients:******}
from: ${admin-mail.from:******}
template: classpath:/template/status-changed.html
ignore-changes: OFFLINE:UP, DOWN:UP
slack:
webhook-url: ${admin-slack.webhook:*******}
ignore-changes: OFFLINE:UP, DOWN:UP
enabled: true
mail:
test-connection: false
host: smtpjc.*****
port: 25
properties:
mail:
smtp:
connectiontimeout: 5000
timeout: 3000
writetimeout: 5000
debug: ${admin-mail.debug:true}
It works perfectly whenever I restart the SBA project, it discovers every service.
My problem comes when I restart a single project, it is shown as OFFLINE in the SBA and it does not change its status.
What am I missing?
I have found the issue and fixed it like this:
spring.cloud.kubernetes.reload.enabled: true
I should have added this line to the config file.
I've found out, that I had to use the fabric8 kubernetes-client.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-fabric8-all</artifactId>
</dependency>
I'm using these current versions:
<spring-cloud.version>2020.0.2</spring-cloud.version>
<spring-cloud-kubernetes.version>2.0.2</spring-cloud-kubernetes.version>
<spring-boot-admin.version>2.4.1</spring-boot-admin.version>
Otherwise I follow the instructions of https://piotrminkowski.com/2020/02/18/spring-boot-admin-on-kubernetes/

Categories