Note
|
OASP has been superseded by devonfw, the Open Source Standard Software Development Platform for state of the art Cloud Native Micro Service and Multi Platform Rich Web Apps, supported by Capgemini. See http://devonfw.com and on Github http://github.com/devonfw Individual products within OASP have been renamed to a corresponding one in devonfw. For example:
devonfw® is an exclusive and registered (European Trademark) product of Capgemini. Capgemini reserves all intellectual and industrial property rights over devonfw but publishes it under the Apache License, Version 2 – like OASP- which makes devonfw 100% Open Source. See: https://tldrlegal.com/license/apache-license-2.0-(apache-2.0) |
Spring Boot Admin is an application to manage and monitor your Spring Boot Applications.
To run the spring boot admin. First, you need to setup admin server. To do this create the spring.io project and follow the below steps.
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
<version>1.5.3</version>
</dependency>
Add the Spring Boot Admin Server configuration via adding @EnableAdminServer to your spring boot class.
@Configuration
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootApp{
public static void main(String[] args) {
SpringApplication.run(SpringBootAdminApplication.class, args);
}
}
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui-login</artifactId>
<version>1.5.3</version>
</dependency>
spring.application.name=Admin-Application
server.port=1111
management.security.enabled=false
security.user.name=admin
security.user.password=admin123
Since there are several approaches on solving authentication and authorization in distributed web applications Spring Boot Admin doesn’t ship a default one. If you include the spring-boot-admin-server-ui-login in your dependencies it will provide a login page and a logout button.
Add the below configuration.
@Configuration
public static class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// Page with login form is served as /login.html and does a POST on /login
http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll();
// The UI does a POST on /logout on logout
http.logout().logoutUrl("/logout");
// The ui currently doesn't support csrf
http.csrf().disable();
// Requests for the login page and the static assets are allowed
http.authorizeRequests()
.antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**")
.permitAll();
// ... and any other request needs to be authorized
http.authorizeRequests().antMatchers("/**").authenticated();
// Enable so that the clients can authenticate via HTTP basic for registering
http.httpBasic();
}
}
Spring boot admin gives the monitoring status of multiple [[ spring.io|http://start.spring.io]] application.These applications are registered as the client application to spring boot admin server.You can register the application with the spring-boot-admin-client or use [[ Spring Cloud Discovery|http://projects.spring.io/spring-cloud/spring-cloud.html]] (e.g. Eureka, Consul, …).
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>1.5.3</version>
</dependency>
If you already use Spring Cloud Discovery for your applications you don’t need the SBA Client. Just make the Spring Boot Admin Server a DiscoveryClient, the rest is done by our AutoConfiguration.
The following steps are for using Eureka, but other Spring Cloud Discovery implementations are supported as well. There are examples using [[ Consul |https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-consul/]] and [[ Zookeeper |https://github.com/codecentric/spring-boot-admin/tree/master/spring-boot-admin-samples/spring-boot-admin-sample-zookeeper/]].
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
Add the Spring Boot Admin Server configuration via adding @EnableDiscoveryClient to your spring boot class
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableAdminServer
public class SpringBootApp {
/**
* Entry point for spring-boot based app
*
* @param args - arguments
*/
public static void main(String[] args) {
SpringApplication.run(SpringBootApp.class, args);
}
}
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8180/eureka}
spring.boot.admin.url=http://localhost:1111
management.security.enabled=false
spring.boot.admin.username=admin
spring.boot.admin.password=admin123
logging.file=target/${spring.application.name}.log
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
health.config.enabled=true
For applications using Spring Boot 1.5.x (or later) you can manage loglevels out-of-the-box. For applications using older versions of Spring Boot the loglevel management is only available for Logback. It is accessed via JMX so include Jolokia in your application. In addition you have configure Logback’s JMXConfigurator:
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>
Now we will see another feature called notifications from Spring Boot Admin. This will notify the administrators when the application status is DOWN or an application status is coming UP. Spring Boot admin supports the below channels to notify the user.
-
Email Notifications
-
Pagerduty Notifications
-
Hipchat Notifications
-
Slack Notifications
-
Let’s Chat Notifications
Here, we will configure Slack notifications. Add the below properties to the Spring Boot Admin Server’s application.properties file.To enable Slack notifications you need to add an incoming Webhook under custom integrations on your Slack account and configure it appropriately.
spring.boot.admin.notify.slack.enabled=true
spring.boot.admin.notify.slack.username=user123
spring.boot.admin.notify.slack.channel=general
spring.boot.admin.notify.slack.webhook-url=https://hooks.slack.com/services/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
spring.boot.admin.notify.slack.message="#{application.name} (#{application.id}) is #{to.status}"
Please follow the below steps to configure the spring boot admin module to OASP4J app.
Check out the Spring boot Admin server from this repository.
Add the dependency in pom.xml file
<dependency>
<groupId>com.capgemini.devonfw.modules</groupId>
<artifactId>devonfw-springbootadminclient</artifactId>
<version>2.2.0</version>
</dependency>
Add the below property to application.properties file and change the values as per the spring boot admin server configuration like admin.url, username, password:
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://localhost:8180/eureka}
spring.boot.admin.url=http://localhost:1111
management.security.enabled=false
spring.boot.admin.username=admin
spring.boot.admin.password=admin123
logging.file=target/${spring.application.name}.log
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
health.config.enabled=true