23

spring-boot-route(十九)spring-boot-admin监控服务

 3 years ago
source link: https://segmentfault.com/a/1190000037521165
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

SpringBootAdmin 不是Spring官方提供的模块,它包含了 ClientServer 两部分。server部分提供了用户管理界面,client即为被监控的服务。client需要注册到server端。

SpringBootAdmin提供了很少的几个监控服务端点,需要依赖SpringBootActuator丰富监控功能。

server端配置

server端的配置很简单,无需任何开发。

第一步:引入依赖

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-server</artifactId>
    <version>2.3.0</version>
</dependency>

第二步:在启动类上增加@EnableAdminServer注解,开启对spring-boot-admin的支持。

@SpringBootApplication
@EnableAdminServer
public class SpringBootAdminApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminApplication.class, args);
    }
}

做好以上配置,然后访问 http://ip :port;效果如下

ZzYNZ3J.png!mobile

目前还没有客户端注册到服务端,所以看不到任何监控的内容,接下来我们创建一个客户端并且注册到服务端后再来看看效果。

Client端配置

这里使用上一章的演示项目——spring-boot-actuator做为客户端。

第一步:引入依赖

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.3.0</version>
</dependency>

第二部:将客户端注册到服务器端,

spring:
  boot:
    admin:
      client:
        # 服务端地址
        url: http://localhost:7019

效果如下:

3QreyiU.png!mobile

为了监控更多的状态信息,我们在客户端引入 spring-boot-actuator 依赖。

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

由于actuator默认只开启了health和info两个web端口,如果想要在server端页面看到所有的监控信息,需要开启其他接口的web端口。

management:
  endpoints:
    web:
      exposure:
        include: "*"

现在的效果如下:

aQJvumi.png!mobile

spring-boot-admin的应用就简单介绍完了。spring-boot-admin配合spring-boot-actuator实现多服务监控,不仅能提供查看服务监控信息的ui,而且可以监控更加全面的内容。

此是spring-boot-route系列的第十九篇文章,这个系列的文章都比较简单,主要目的就是为了帮助初次接触Spring Boot 的同学有一个系统的认识。本文已收录至我的 github ,欢迎各位小伙伴 star

github: https://github.com/binzh303/s...

点关注、不迷路

如果觉得文章不错,欢迎 关注点赞收藏 ,你们的支持是我创作的动力,感谢大家。

如果文章写的有问题,请不要吝啬,欢迎留言指出,我会及时核查修改。

如果你还想更加深入的了解我,可以微信搜索「 Java旅途 」进行关注。回复「 1024 」即可获得学习视频及精美电子书。每天7:30准时推送技术文章,让你的上班路不在孤独,而且每月还有送书活动,助你提升硬实力!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK