Configure Spring Boot ADMIN Dashboard for Micro Services through Eureka Server

Iroshan Aberathne
3 min readNov 6, 2019

--

Spring boot admin server is a web application where all other registered micro-services can be manged and monitored. In this article we are going to discuss the way of integrating admin dashboard with the spring boot micro services through eureka server.

Prerequisites

There should be already implemented micro services with eureka server enabled. If you are not familiar with micro services please refer this article.

1.0 Admin Server Setup

1.1 POM.xml

First create a simple spring boot application with following dependencies in pom.xml. Since i’m going to implement this admin service also as a micro service but it is not mandatory that is way eureka-client dependency has been added.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.vetstoria</groupId>
<artifactId>admin-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>admin-service</name>
<description>Admin Service</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot-admin.version>2.1.5</spring-boot-admin.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-server-ui</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-dependencies</artifactId>
<version>${spring-boot-admin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<finalName>admin-service</finalName>
</build>
</project>

1.1 Main Class

The main class you have to alter the existing SpringApplication.run() method with following code block otherwise there will be some issues once you retrieve other micro services details from eureka service. If you have doubt please run the project with initial code and see the console output.

@SpringBootApplication
@EnableDiscoveryClient
@EnableAdminServer
public class AdminServiceApplication {
public static void main(String[] args) {
//SpringApplication.run(AdminServiceApplication.class, args);
new SpringApplicationBuilder(AdminServiceApplication.class)
.web(WebApplicationType.REACTIVE)
.run(args);
}
}

1.2 Application.yml

server:
port: 8765

spring:
application:
name: admin-service
boot:
admin:
discovery:
ignored-services: gateway-service

eureka:
client:
registryFetchIntervalSeconds: 5
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8761/eureka
instance:
hostname: localhost

Use above code block in your application.yml file. There are two configurations to be discussed and rest of the configuration are self explanatory.

  1. spring.boot.admin.discovery.ignored-services

you can specify micro-services those are no need to managed or monitored by admin service. In my context the micro service called gateway-service is excluded from admin service scope.

2. eureka.client.registryFetchIntervalSeconds

Admin service uses this configuration to fetch the available micro-service from eureka server in order to manage and monitored. In our example the admin service fetch micro services availability in each 5 seconds.

2.0 Enable Micro Services to Register with Admin Server

A particular micro service should add following dependencies to pom.xml in order to enable communication with Admin service.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>

3.0 Eureka Server Dashboard

In this scenario there are 7 micro services including admin service as shown in fig.1 which is a real screen shot of eureka service dashboard.

Figure.1 Eureka Service Dashboard

4.0 Admin Dashboard UI

All the micro services are registered with admin service excepts gateway-service since we disable gateway-service in admin service(refer .yml file). The user interface of the Admin dashboard is visualized in fig.2.

Figure.2. Admin Dashboard UI

Summary

In this article we discussed the implementation process of ADMIN dashboard implementation through eureka server. Admin service get all the details about micro services from eureka server so no need to register each micro-service separately with Admin service. This is the main advantage of this approach.

Thank You.!!!

--

--

No responses yet