首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Springboot的监控Springboot Actuator

Springboot的监控Springboot Actuator

作者头像
别先生
发布2021-03-18 11:11:20
5290
发布2021-03-18 11:11:20
举报
文章被收录于专栏:别先生别先生

1、Springboot版本2.3.9,引入Actuator的maven依赖,如下所示:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <parent>
 6         <groupId>org.springframework.boot</groupId>
 7         <artifactId>spring-boot-starter-parent</artifactId>
 8         <version>2.3.9.RELEASE</version>
 9         <relativePath/> <!-- lookup parent from repository -->
10     </parent>
11     <groupId>com.bie</groupId>
12     <artifactId>springboot</artifactId>
13     <version>0.0.1-SNAPSHOT</version>
14     <name>springboot</name>
15     <description>Demo project for Spring Boot</description>
16     <properties>
17         <java.version>1.8</java.version>
18     </properties>
19     <dependencies>
20         <dependency>
21             <groupId>org.springframework.boot</groupId>
22             <artifactId>spring-boot-starter-web</artifactId>
23         </dependency>
24 
25         <dependency>
26             <groupId>org.springframework.boot</groupId>
27             <artifactId>spring-boot-starter-test</artifactId>
28             <scope>test</scope>
29             <exclusions>
30                 <exclusion>
31                     <groupId>org.junit.vintage</groupId>
32                     <artifactId>junit-vintage-engine</artifactId>
33                 </exclusion>
34             </exclusions>
35         </dependency>
36 
37         <dependency>
38             <groupId>org.springframework.boot</groupId>
39             <artifactId>spring-boot-starter-actuator</artifactId>
40         </dependency>
41     </dependencies>
42 
43     <build>
44         <plugins>
45             <plugin>
46                 <groupId>org.springframework.boot</groupId>
47                 <artifactId>spring-boot-maven-plugin</artifactId>
48             </plugin>
49         </plugins>
50     </build>
51 
52 </project>

访问:http://127.0.0.1:8080/actuator,可以发现如下信息:

该信息列出了Springboot的所有endpoint端点,可以访问上面列出的地址信息。其中该端点http://127.0.0.1:8080/actuator/health的作用是进行健康检查,检查应用的资源。在application.properties中新增如下配置,可以展示health的详情,如下所示:

1 # 将health的详情展示出来
2 management.endpoint.health.show-details=always

访问:http://127.0.0.1:8080/actuator/health,可以展示磁盘资源。

健康检查的status的四种状态,第一种是UP,表示正常,第二种是Down,表示遇到了问题,不正常,第三种是Out_Of_service,资源未在使用,或者不该去使用,第四种是unkonwn,表示不知道。

http://127.0.0.1:8080/actuator/info,该端点是描述性端点,在application.properties中可以进行配置,如下所示:

1 # 描述性端点,建议描述应用,可以书写应用的名称、作者、邮箱等等信息
2 info.springboot=springboot info
3 info.author=biehl
4 info.email=biehl@qq.com

访问路径之后,如下所示:

2、Springboot的常见端点,默认只有health和info是开放的,如下所示:

具体可以参考官网:https://docs.spring.io/spring-boot/docs/2.3.9.RELEASE/reference/htmlsingle/

参考官网,如下所示:

如何暴漏其他端点呢,如下所示:

1 # 激活所有的actuator端点,如果只想激活部分端点,只需要将*替换成自己的端点,如果是多个端点以逗号分隔。

2 management.endpoints.web.exposure.include=*

再次访问,http://127.0.0.1:8080/actuator,如下所示:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-03-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档