springboot 2.3_Spring Boot 应用监控,早发现早

小Hub领读:

服务都需要监控,SpringBoot项目中,你常用哪些监控模块呢?actuator?admin?


作者:小小____

https://segmentfault.com/a/1190000022945443

当一个 Spring Boot 应用运行的时候,开发者需要对 Spring Boot 应用进行实时监控,获得项目的报警需求,Spring Boot 提供了,actuator 来帮助开发者获取应用程序运行时的数据。

在 Spring Boot 中添加端点配置相当的简单。
只需要添加 spring-boot-starter-actuator
添加相关的依赖

org.springframework.bootspring-boot-starter-actuator2.3.1.RELEASE

常用的端点如下:

常用端点列举如下,可以一个个详细试一下:

/info        应用基本信息
/health       健康度信息
/metrics      运行指标
/env        环境变量信息
/loggers      日志相关
/dump       线程相关信息
/trace       请求调用轨迹

这些端点大都是默认开启的,如果想要开启一个端点,需要在配置文件中,配置以下内容。

endpoints:
metrics:
sensitive: false

此时 sensitive 是关闭的。

举个例子:
这里举个例子,访问是否在线的接口

localhost:8080/actuator/health

此时浏览器的输出结果为:

b5c0c35aa42a1682afa8a9a7953a8ff6.png

端点响应缓存

对于一些不带参数的端点将会进行缓存。搜索公众号:MarkerHub,关注回复[vue]获取前后端入门教程!

management:
endpoint:
auditevents:
cache:
time-to-live: 100s

上方的配置说明了缓存达到 100s

路径映射

可以对访问的路径进行映射。

management:
endpoints:
web:
base-path: /
path-mapping:
health: healthcheck

此时访问路径由原先的 localhost:8080/actuator/health 转变为 localhost:8080/healthcheck

CORS

进行跨域操作。
可以通过配置文件,快速的开启 CORS 支持。

management:
endpoints:
web:
cors:
allowed-origins: http:
allowed-methods: *

在上方中,允许处理,来自 http://localhost:8091 的任何请求,允许的方法任意。

添加相关的依赖。

de.codecentricspring-boot-admin-starter-server2.2.3

在启动类上增加相关的注解:

package com.example.demo;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAdminServer
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

}

配置完成以后,输入链接,进行访问。

http:

92e049d87f7071133cbd83adca54296a.png

再次添加 client 端

de.codecentricspring-boot-admin-starter-client2.2.3

书写配置文件

spring:
boot:
admin:
client:
url: http:

此时查看 adminb540588787c7e193a81d09805cb60477.png

81c2f51f5e5bfc165b0c08c72b3dfa0e.png
查看其健康度

2009a9e542542f71dbcf91dd758ba368.png


(完)

好文章!点个在看!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值