8.1_springboot2.x之Actuator应用监控
1、监管端点测试
引入依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>springboot-08-actuator</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-08-actuator</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.yml
server:
port: 8080
# actuator监控
management:
server:
# 设置监控服务端口
port: 8081
endpoints:
# 设置端点是否可用 默认只有shutdown可用
enabled-by-default: true
web:
# 设置是否暴露端点 默认只有health和info可见
exposure:
# 包括所有端点
include: "*" # 注意需要添加引号
# 排除端点
exclude: shutdown
Spring Boot内置端点(和1.x版本相比,不少端点名称发生改变)
官方链接:https://docs.spring.io/spring-boot/docs/2.2.0.RELEASE/reference/htmlsingle/#production-ready
每个端点可以启用或禁用。创建此控件是否终结点存在于应用程序上下文。要远程访问端点也必须通过JMX或HTTP公开。大多数应用程序选择HTTP,在那里随着/执行器的前缀端点的ID映射到URL。例如,默认情况下,/actuator/health.

| 端点名 | 描述 |
|---|---|
| conditions | 所有自动配置信息 |
| auditevents | 审计事件 |
| beans | 所有Bean的信息 |
| configprops | 所有自动化配置属性 |
| threaddump | 线程状态信息 |
| env | 当前环境信息 |
| health | 应用健康状况 |
| info | 当前应用信息 |
| metrics | 应用的各项指标 |
| mappings | 应用@RequestMapping映射路径 |
| shutdown | 关闭当前应用(默认关闭) |
| httptrace | 追踪信息(最新的http请求) |
启动测试
例如浏览器输入:http://localhost:8081/actuator/configprops
运行结果:

2、定制端点信息
**启用端点:**默认情况下,启用除shutdown 之外的所有端点。要配置端点的启用,请使用其management.endpoint..enabled 属性。以下示例启用shutdown 端点:
management.endpoint.shutdown.enabled=true
如果您希望端点启用是选择加入而不是选择退出,请将management.endpoints.enabled-by-default 属性设置为false 并使用单个端点enabled 属性重新加入。以下示例启用info endpoint并禁用所有其他端点:
management.endpoints.enabled-by-default=false
management.endpoint.info.enabled=true
配置端点:端点自动缓存对不带任何参数的读取操作的响应。要配置端点缓存响应的时间量,请使用其cache.time-to-live 属性。以下示例将beans 端点缓存的生存时间设置为10秒:
management.endpoint.beans.cache.time-to-live=10s
更多内容请查看官方文档。
3、健康信息
您可以使用运行状况信息来检查正在运行的应用程序的状态。监视软件经常使用它来在生产系统出现故障时向某人发出警报。health 端点公开的信息取决于management.endpoint.health.show-details 属性,该属性可以使用以下值之一进行配置:
| never | 细节永远不会显示 |
|---|---|
| when-authorized | 详细信息仅向授权用户显示。可以使用management.endpoint.health.roles 配置授权角色 |
| always | 详细信息显示给所有用户 |
默认值为never 。当用户处于一个或多个端点的角色时,将被视为已获得授权。如果端点没有配置角色(默认值),则认为所有经过身份验证的用户都已获得授权。可以使用management.endpoint.health.roles 属性配置角色。
自定义健康指示器
package com.example.springboot08actuator.health;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class MyHealthIndicator implements HealthIndicator {
@Override
public Health health() {
/*
* 自定义健康
* Health.up().build() 代表健康
* */
return Health.down().withDetail("msg","服务异常").build();
}
}
这里本地环境没有安装redis,启动程序查看健康信息:

8.1_springboot2.x之Actuator应用监控的更多相关文章
- SpringBoot actuator 应用监控。
前言 : 今天在阅读 <SpringCloud微服务实战>一书时看到了SpringBoot actuator相关知识,并且自己也本地调试实践.觉得SpringBoot这一套监控还是挺有意思 ...
- springcloud(九) springboot Actuator + admin 监控
前一章讲的都是Feign项目(调用方)的监控.接下来讲的是服务提供方的监控 一.springboot actuator + springboot admin Spring Boot Admin 是一个 ...
- Spring Boot (27) actuator服务监控与管理
actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...
- spring boot 2.x 系列 —— actuator 服务监控与管理
文章目录 一.概念综述 1.1 端点 1.2 启用端点 1.3 暴露端点 1.4 健康检查信息 二.项目说明 1.1 项目结构说明 1.2 主要依赖 1.3 项目配置 1.4 查看监控状态 三.自定义 ...
- Spring Boot整合actuator实现监控管理
Spring Boot使用actuator监控管理 1.在pom文件中导入相关的依赖 <dependency> <groupId>org.springframework.boo ...
- 强大的 actuator 服务监控与管理
SpringBoot 是为了简化 Spring 应用的创建.运行.调试.部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖 ...
- SpringBoot如何利用Actuator来监控应用?
目录 Actuator是什么? 快速开始 引入依赖 yml与自动配置 主程序类 测试 Endpoints 官方列举的所有端点列表 启动端点 暴露端点 配置端点 发现页面 跨域支持 实现一个定义的端点 ...
- spring boot actuator服务监控与管理
1.引入actuator所需要的jar包 <dependency> <groupId>org.springframework.boot</groupId> < ...
- [转]Eureka自我保护机制、健康检查的作用、actuator模块监控
Eureka自我保护机制 接着以上篇文章建立的三个工程为基础(eureka-server,uerreg,myweb),默认Eureka是开启自我保护的.我们来做个测试,我们先启动三个工程,我们访问注册 ...
随机推荐
- UVA11054_Wine trading in Gergovia
大致题意: 直线上有n个村庄,要么买酒要么卖酒,运酒到隔壁村庄需要这个酒的权值个劳动力 问你至少需要多少劳动力 题目保证了所有权值和为0!!!!!!!!!!!!这个意义重大,表示这是一个封闭的群体 这 ...
- JSON Web Token (JWT),服务端信息传输安全解决方案。
JWT介绍 JSON Web Token(JWT)是一种开放标准(RFC 7519),它定义了一种紧凑独立的基于JSON对象在各方之间安全地传输信息的方式.这些信息可以被验证和信任,因为它是数字签名的 ...
- linux/unix下setuid/seteuid/setreuid/setresuid
其中setresuid()具有最清晰的语法: setresuid()被执行的条件有: ①当前进程的euid是root ②三个参数,每一个等于原来某个id中的一个 如果满足以上条件的任意一个,setre ...
- application/json和application/x-www-form-urlencoded参数接收
application/json ajax请求中content-type:application/json代表参数以json字符串传递给后台,controller接收需要@RequestBody 接收 ...
- 如何取消IDEA的自动删除行尾空格?
使用IDEA,添加注释的时候敲空格,总是会把行尾空格删除导致代码跑到注释行,很不爽~~ 取消这个不爽的功能:File--Settings--Editor--General--Other--Strip ...
- Django rest_framework 自动生成接口文档
自动生成接口文档 REST framework可以自动帮助我们生成接口文档. 接口文档以网页的方式呈现. 自动接口文档能生成的是继承自APIView及其子类的视图. 1. 安装依赖 REST fram ...
- cenos7 下数据库相关操作
1.Linux Centos7下如何确认MySQL服务已经启动 https://www.cnblogs.com/qianzf/p/7082484.html 2.CentOS 7上安装MySQL并配置远 ...
- Dubbo面试常见问题
一.dubbo是什么? dubbo是⼀个分布式服务框架,提供⾼性能和透明化的RPC远程服务调⽤⽅案,以及SOA服务治理方案.说白了其实dubbo就是一个远程调用的分布式框架. 二.dubbo的核心服务 ...
- Jmeter请求非Json格式的参数如何添加
Step1: 可以先在用户自定义变量中加入你需要添加的请求类型,具体参考图片 Step2: 在线程组下请求之前添加HTTP信息头管理器
- 深入理解zabbix(二)
深入理解zabbix(二) 链接:https://pan.baidu.com/s/1q5YwJMTcZLcS5OQ0iOu44A 提取码:8gdi 复制这段内容后打开百度网盘手机App,操作更方便哦 ...