spring-boot-admin, referred to as SBA, is a monitoring tool for UI beautification and packaging for spring-boot's actuator interface. He can: browse the basic information of all monitored spring-boot projects in the list, detailed Health information, memory information, JVM information, garbage collection information, various configuration information (such as data source, cache list and hit rate), etc., and can also directly modify the logger level.
Official website: https://github.com/codecentric/spring-boot-admin
User Guide: http://codecentric.github.io/spring-boot-admin/1.5.0/
SBA can be configured and used in just a few simple steps (divided into monitoring end and monitored end):
Monitoring end:
1. Create a project (omitted)
2. Introduce dependencies:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server</artifactId> <version>1.5.0</version> </dependency> <dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-server-ui</artifactId> <version>1.5.0</version> </dependency>
3. Configuration file (application.yml) configuration (optional):
spring: application: name: svc-monitor boot: admin: context-path: /sba # The configuration access path is: http://localhost:64000/svc-monitor/sba server: port: 64000 context-path: /svc-monitor/ #Unify the accessed url to be given a prefix
The above configuration is to specify a special access path. If this is not configured, the access path is: http://localhost:64000
4. Use the @EnableAdminServer annotation to activate SBA:
@SpringBootApplication @EnableScheduling @EnableAdminServer public class SvcMonitorApplication { public static void main(String[] args) { SpringApplication.run(SvcMonitorApplication.class, args); } }The monitored end (spring-boot project) registers itself with the monitoring end:
1. Add dependencies:
<dependency> <groupId>de.codecentric</groupId> <artifactId>spring-boot-admin-starter-client</artifactId> <version>1.5.0</version> </dependency>
2. Configuration file (application.yml) configuration:
spring: boot: admin: client: prefer-ip: true # Solve the problem that the host name cannot be recognized during running under Windows url: http://localhost:64000/svc-monitor # Address registered with the server management: port: 64001 security: enabled: false # spring-boot strictly enforce security policies after 1.5.2, so you need to configure this to false info: #Define various additional details to display the app to the server: name: "@project.name@" #Get description from pom.xml: "@project.description@" version: "@project.version@" spring-boot-version: "@project.parent.version@"
3. Other configurations:
If you need to display the project version number, you need to add this (build-info) in pom.xml:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>build-info</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
4. Problem solving:
If you find that InetAddress.getLocalHost() throws UnknownHostException error occurs when the monitored end is started, it is because the correspondence between the native machine name and ip is not configured.
Solution:
Edit the hosts file:
vi /etc/hosts
Add the association between ip and machine name: 192.168.0.31 host31 myhost-31
After both the monitoring end and the monitored end are started, visit: http://localhost:64000/svc-monitor/sba, and you can see various details of the monitored service.
The above is the active registration method of the monitored end.
Another method is: if the monitored end has already registered a service with Eureka using Spring Cloud, the monitoring end can directly discover and monitor this service in Euraka. This method is quite complicated to debug, so I won't introduce it here.
Summarize
The above is the implementation method of using spring-boot-admin to monitor spring-boot services that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!