Monitoring jar application using Spring boot Admin - java

I have an spring boot application .jar, based on spring batch,and it is not a web application, and I'm using a ksh script to Launch it on my server side.
for some performance observation, we decide to install Spring Boot Admin for this app, using a "sba.war" that is already deployed in another web application on another server, I tried to drop the sba.war beside my applicationBatch.war after updating the application.yml file and import the SBA dependency on my build.gradle file :
spring:
datasource:
# BDD DEV
url: jdbc:oracle:thin:#xxxx:9999:AAAAA
username: xxxxxx
password: xxxxxx
# SBA DEV
boot:
admin:
client:
enabled: true
instance:
service-base-url: https://xxxxx.com
url: https://xxxxx.com/sba
username: username
password: password
so the problem is, that my application is not deployed on a tomcat server, it is runned by the ksh script on it's embeded server.
So can I anyhow use the embeded server of SBA to run it ?

Related

spring boot + docker + kubernetes

we have three environment as (dev, test and prod) and we have database configuration as below
spring:
jpa:
hibernate:
ddl-auto: update
datasource:
url: ${URL}
username: ${USERNAME}
password: ${PASSWORD}
What i am trying is that i create the jar and then build the image and when deploying in to the kubernetes , i will be using the dev , test and prod respective deployment.yaml in which i will be loading the url,username and password to env so the application will read it during prod start up
So when i am trying to build jar application try to connect to the database and it failed to create the jar.
Please let me know my understanding is wrong or right if wrong then how to correct it and just one thing is that i can't change the process i.e jar+ image + kubernetes
In Kubernetes you can put your configuration in Configmap or Secret. You can package the spring boot application and provide the Configmap entry as env variable of your container as exposed here
Using Spring Cloud Kubernetes you can also read these properties without any configuration on the container as explained in this article

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/

Fallback option in Spring application properties in AWS

I have a REST service built with Spring Boot where I'm using an application.yml file to set up environment variables. The REST service will be deployed to Amazon Elastic Beanstalk. I have set up Environment Properties in the configuration for the Environment (Configuration -> Software Configuration -> Environment Properties)
I would like for the REST service to pick up the environment variables from AWS Environment Properties when they are available and then use environment variables specified in the application.yml file when the Environment Properties are not available as a fallback.
spring:
profiles: default
datasource:
type: org.mariadb.jdbc.MariaDbDataSource
driverClassName: org.mariadb.jdbc.Driver
url: jdbc:mariadb://localhost:3306/someDB
username: someUserName
password: somePassword
What I'm trying to achieve is that I wouldn't have to change the profile used in application.yml when I deploy on AWS or do development locally.
I've tried this which doesn't work
spring:
profiles: aws
datasource:
type: org.mariadb.jdbc.MariaDbDataSource
driverClassName: org.mariadb.jdbc.Driver
url: ${ADDRESS_FOR_RDS:jdbc:mariadb://localhost:3306/someDB}
username: ${USERNAME:someUserName}
password: ${PASSWORD:somePassword}
Trying to specify as ${AWS_PROPERTY_NAME:FALLBACK_OPTION} as per this Stack Overflow answer.
I have been able to get this working using Spring profiles, per this Stack Overflow question.

Spring Boot Application Hanging When Running on Command Line

I have a Spring Boot app that can not be run with a .yml config file.Below is the command that I run:
java -jar /opt/myAppFolder/myApp.war
I have a config folder withing the same location that I run my war file. And in that config,I have a application.yml file that application needs to retrieve some config:
security:
user:
password: password
logging:
level:
org.springframework.security: DEBUG
release:
sourceDir: /$ANY_DIR
targetDir: /$ANY_DIR
users:
- name: $ANY_NAME
pwd : $ANY_NAME
- name: $ANY_NAME
pwd : $ANY_NAME
mail:
host: $ANY_NAME
recipients: $ANY_NAME
subject: $ANY_NAME
body: $ANY_NAME
server:
port: 9000
spring:
profiles:
active: prod
Problem: Once I run the app on command line,the process just hangs.No output,no logging. I have tried to enable debug via command line. No avail.
If I put a file with properties extension,it works.However I want to use .yml since it is more convenient for me to have list of dynamic properties.And why nothing is displayed anway?
Any help appreciated.
Spring Boot Version:1.5.7
OS Version:Ubuntu 3.13.0-24-generic
Finally resolved it.
So here is the story:
I have contacted Spring Boot Team and they have recommended me to upgrade to version 1.5.8.RELEASE.
Once I did that,I had a different issue;application was not hanging anymore,but shutting down without logging anything.
And eventually it turned out to be an error in my logback-spring.xml file. It was malformatted.And in its "prod" profile,I did not have any console appender.Hence no output visible. So I have fixed my file and it started working.
More on my communication with Spring Boot Team:
https://github.com/spring-projects/spring-boot/issues/10711

Spring Boot Registration Server(Eureka Server)

I am working on a Spring Boot Registration Server(Eureka Server).
Currently it is working with below configuration.
Project Name: registration-service
Inside main method: System.setProperty("spring.config.name", "registration-service");
"yml file":
file name: registration-service
content:
eureka:
instance:
hostname: eureka-server
server:
enableSelfPreservation: false
client:
register-with-eureka: false
fetch-registry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
port: 2323 # HTTP (Tomcat) port
spring:
application:
name: eureka-server
With above configuration,application start running on 2323.
But if i change spring.config.name,it does not work,start giving connection refused exception.
why it is happening? even though this spring.config.name is no where used in yml file. Should it be necessarily same as project name? or it is specific to #EnableEurekaServer enabled spring boot application.
And in yml we have to write
spring:
application:
name: eureka-server
though in other spring boot application we give name of current project(here it should be registration-service).why we have to write here eureka-server? I know,I am missing something(or a lot of things).please help me in understanding the missing part.
Spring boot by default looks for file application.yml. If u have different profiles in your application it can also look for application-{profilename}.yml. This is the default convention followed.
spring.config.name property is used to override this default behaviour. When u override this property with register-service then spring boot looks for a file register-service.yml and loads config from that.
So your eureka server url which is given in the register-service.yml file may not be available in the default application.yml file. Hence when u change the value Spring boot may not be avle to find the Eureka server url.
Keep the names unchanged, as much as possible. If u have config file as register-service.yml then keep the spring.config.name=register-service. If you change this value then u need to create the new file with config.name value and then add eureka configuration to that again.

Categories