Springboot Actuator监控实现 Admin-UI 管理——SpringBoot学习

  SpringBoot 提供 Actuator 进行监控管理,Actuator 能够使开发者在项目生产时监视和管理应用程序,可使用 HTTP 的各种请求来监管,审计,收集应用的运行情况,此举对于微服务管理意义重大,但是缺点是没有可视化界面。

  使用其也是非常简单,只需要导入 pom 依赖即可。

<!-- Actuator 依赖 -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

  基于 SpringBoot 2.0 的 Actuator 常用访问 URL 统计:

URL路径说明
/actuator/beans显示应用程序中所有Spring bean的完整列表
/actuator/configprops显示所有配置信息
/actuator/env列出所有的环境变量
/actuator/mappings显示所有@RequestMapping的url整理列表
/actuator/health显示应用程序运行状况信息 up表示成功 down失败
/actuator/info查看自定义应用信息

其他 URL 可参考文章 :

SpringBoot四大神器之Actuator https://www.cnblogs.com/baidawei/p/9183531.html
Spring Boot (27) actuator服务监控与管理 https://www.cnblogs.com/austinspark-jessylu/p/8065284.html

  为了能够有可视化的监控界面,可通过使用 Admin-UI 改进 Actuator 的缺点,因为 Admin-UI 基于 Actuator 实现提供了可视化监控管理界面。接下来简单介绍 Admin-UI 的使用。

  Admin-UI 的 Server 端 需要新建项目,添加 pom 依赖,可修改端口,例如修改端口为 80 ,则访问路径为 http://localhost/#/applications

<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>spring-boot-admin-starter-server</artifactId>
	<version>2.0.0</version>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<!-- Spring Boot Actuator对外暴露应用的监控信息,Jolokia提供使用HTTP接口获取JSON格式 的数据 -->
<dependency>
	<groupId>org.jolokia</groupId>
	<artifactId>jolokia-core</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
	<groupId>com.googlecode.json-simple</groupId>
	<artifactId>json-simple</artifactId>
	<version>1.1</version>
</dependency>

  Admin-UI 的 Client端 需要新建项目,添加 pom 依赖,注册到 Server 端。

  第一步,添加 pom 依赖

<dependency>
	<groupId>de.codecentric</groupId>
	<artifactId>spring-boot-admin-starter-client</artifactId>
	<version>2.0.0</version>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
	<groupId>org.jolokia</groupId>
	<artifactId>jolokia-core</artifactId>
</dependency>
<dependency>
	<groupId>com.googlecode.json-simple</groupId>
	<artifactId>json-simple</artifactId>
</dependency>

  第二步,注册 Client 到 Server 端,在 application.yml 或 application.properties 中加入配置:

application.yml 文件配置:

## 注册到服务端
spring:
  boot:
    admin:
      client:
        url: http://localhost:80
        
### 开启客户端Actuator的权限
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS

application.properties 文件配置:

# 注册到服务端
spring.application.name=spring-boot-admin-client
spring.boot.admin.client.url=http://localhost:80

# 开启客户端Actuator的权限
management.endpoints.web.exposure.exclude="*"
management.endpoint.health.show-details=always

  第三步,先启动 Server 端服务,再启动 Client 端服务,访问 Servlet 端 URL 即可,简单的使用 Admin-UI 就完成了。最后来两张效果图。

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lytao123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值