springboot actuator监控是什么?类似php的phpinfor()函数,不过actuator更强大,可以查看的数据、状态更多。Actuator是Spring Boot提供的对应用系统的监控和管理的集成功能,可以查看应用配置的详细信息,例如自动化配置信息、创建的Spring beans信息、系统环境变量的配置信以及Web请求的详细信息等。如果使用不当或者一些不经意的疏忽,可能造成信息泄露等严重的安全隐患。

使用

pom加入依赖

<!--actuator模块为SpringBoot提供一系列用于监控的端点-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

pom加入依赖(安全版)

<dependencies>
<!-- 如果使用http调用的方式,还需要这个依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 必须的 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 安全需要,为了保证actuator暴露的监控接口的安全性,需要添加安全控制的依赖spring-boot-start-security依赖,访问应用监控端点时,都需要输入验证信息。-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>

properties配置文件

在application.properties核心配置文件中除了定义数据源外,还需要添加 management.security.enabled=false 配置。

不加的话,访问监控路径会报401。

#########################################################
### Actuator Monitor -- Actuator configuration ###
#########################################################
management.security.enabled=false

在SpringBoot的application.yml配置文件中加入

# ============================= actuator监控 ============================= #
management:
server:
port: 1234 # 管理的端口调整成1234
address: 127.0.0.1 # 只允许127.0.0.1访问
servlet:
context-path: /monitor # actuator的访问路径
endpoint:
shutdown:
enabled: true # 启用shutdown功能
beans.cache.time-to-live: 10s
env.enabled: true # 启用端点 env
endpoints:
enabled-by-default: true # 设置端点是否可用 默认只有shutdown可用
web:
# 设置是否暴露端点 默认只有health和info可见
exposure:
# include: env # 方式1: 暴露端点 env 配置多个,隔开
include: "*" # 方式2: 包括所有端点, 注意需要添加引号
# 排除端点
exclude: shutdown

注意:若在核心配置文件中未添加 management.security.enabled=false 配置,将会导致用户在访问部分监控地址时访问受限,报401未授权错误。

常见的监控项目

方法 路径 描述
GET /autoconfig 查看自动配置的使用情况
GET /conditions 提供了一份自动配置报告,记录哪些自动配置条件通过了,哪些没通过
GET /configprops 描述配置属性(包含默认值)如何注入Bean
GET /beans 描述应用程序上下文里全部的Bean,以及它们的关系
GET /dump 打印线程栈
GET /heapdump 获取堆的快照
GET /threaddump 获取线程活动的快照
GET /env 获取全部环境属性
GET /env/{name} 根据名称获取特定的环境属性值
GET /health 报告应用程序的健康指标,这些值由HealthIndicator的实现类提供
GET /info 获取应用程序的定制信息,这些信息由info打头的属性提供
GET /mappings 描述全部的URI路径,以及它们和控制器(包含Actuator端点)的映射关系
GET /metrics 报告各种应用程序度量信息,比如内存用量和HTTP请求计数
GET /metrics/{name} 报告指定名称的应用程序度量值
POST /shutdown 关闭应用程序,要求endpoints.shutdown.enabled设置为true
GET /trace 提供基本的HTTP请求跟踪信息(时间戳、HTTP头等)

加入了依赖之后,在外部是可以访问到如下路径的:

# 加入上述依赖后,默认可以访问的url
http://localhost:8080/actuator
http://localhost:8080/actuator/info
http://localhost:8080/actuator/health

有敏感数据的接口可以自己测试一下:

/autoconfig
/conditions
/configprops
/beans
/heapdump
/threaddump
/env
/info
/mappings
/metrics
/trace

参考

https://xz.aliyun.com/t/2233

https://www.freebuf.com/news/193509.html

https://blog.csdn.net/qq_29668759/article/details/98672900

springboot actuator 配置安全的更多相关文章

  1. SpringBoot Actuator

    SpringBoot Actuator 提供了检查项目内部信息的一整套API,通常在项目启动时可以看到. 1.引入依赖包 <dependency> <groupId>org.s ...

  2. SpringBoot actuator 应用监控。

    前言 : 今天在阅读 <SpringCloud微服务实战>一书时看到了SpringBoot actuator相关知识,并且自己也本地调试实践.觉得SpringBoot这一套监控还是挺有意思 ...

  3. springcloud(九) springboot Actuator + admin 监控

    前一章讲的都是Feign项目(调用方)的监控.接下来讲的是服务提供方的监控 一.springboot actuator + springboot admin Spring Boot Admin 是一个 ...

  4. springboot Actuator健康检查

    通过情况下,如我们想在系统中添加一个健康检查的接口,我们怎么做呢? 我们会新建一个类,或在已存在类的基础上添加检测接口. package com.crhms.medicareopinion; impo ...

  5. Springboot Actuator之八:actuator的执行原理

    本文接着<Springboot Actuator之七:actuator 中原生endpoint源码解析1>,前面主要分析了原生endpoint的作用. 现在着重了解actuator的执行原 ...

  6. SpringBoot Actuator监控【转】

    springboot actuator 监控 springboot1.5和springboot2.0 的actuator在启动日志上的差异就很大了. springboot1.5在启动时会打印很多/XX ...

  7. SpringBoot Actuator — 埋点和监控

    项目中看到了有埋点监控.报表.日志分析,有点兴趣想慢慢捣鼓一下 1. 数据埋点 监控机器环境的性能和业务流程或逻辑等各项数据,并根据这些数据生成对应的指标,那么我们就称为数据埋点.比如我们想知道某个接 ...

  8. SpringBoot常用配置简介

    SpringBoot常用配置简介 1. SpringBoot中几个常用的配置的简单介绍 一个简单的Spring.factories # Bootstrap components org.springf ...

  9. 在SpringBoot中配置aop

    前言 aop作为spring的一个强大的功能经常被使用,aop的应用场景有很多,但是实际的应用还是需要根据实际的业务来进行实现.这里就以打印日志作为例子,在SpringBoot中配置aop 已经加入我 ...

随机推荐

  1. django 从零开始 2迁移模型数据到数据库中和admin初识

    和flask 一样 如果模型models 发生改动,则需要进行一个迁移数据库,但是我还没有想讲到那么深入,现在模型是django自带的一些sessiong,damin之类的模型 所以如果你想进去adm ...

  2. 等宽字体的妙用-loading 点点点动画

    原理 ch等宽字体 + text-indent 动画负缩进 显示效果如 loading . loading .. loading ... loading . loading .. loading .. ...

  3. Java多线程并发01——线程的创建与终止,你会几种方式

    本文开始将开始介绍 Java 多线程与并发相关的知识,多谢各位一直以来的关注与支持.关注我的公众号「Java面典」了解更多 Java 相关知识点. 线程的创建方式 在 Java 中,用户常用的主动创建 ...

  4. python获取群成员信息

    #coding: utf-8 import itchat,datetime from itchat.content import TEXT itchat.auto_login(hotReload=Tr ...

  5. search(3)- elastic4s-QueryDSL

    elastic4s是elasticsearch一个第三方开发的scala语言终端工具库(Elastic4s is a concise, idiomatic, reactive, type safe S ...

  6. 在linux系统中安装LANMP

    1.安装LANMP步骤 root@kali:~# wget http://dl.wdlinux.cn/files/lanmp_v3.tar.gz #下载 root@kali:~# tar xzvf l ...

  7. Kubernetes实战总结 - 系统初始化

    设置系统主机名以及Host文件的相互解析 hostnamectl set-hostname k8s-master01 cat >> /etc/hosts <<EOF 192.1 ...

  8. jsp(3,6,9) EL表达式及JSTL

    1. jsp 1.1jsp是什么 全称: Java Server Pages,java服务器页面.和Servlet一样,是sun公司定义的一种动态网页开发技术.    特点:基于html模版,可以在h ...

  9. 手写简单IOC

    ReflectUtils.java (反射工具类) package top.icss.ioc; import java.io.File; import java.io.FileFilter; impo ...

  10. 洛谷3372线段树模板题 对区间+k或者查询区间和

    #include<bits/stdc++.h> using namespace std; typedef unsigned int ui; typedef long long ll; ty ...