实时监控 spring-boot-starter-actuator的整理

简介: 实时监控 spring-boot-starter-actuator的整理

一、接入

1、依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2、常用actuator endpoints列表

GET /autoconfig 查看自动配置的使用情况 true 
GET /configprops 查看配置属性,包括默认配置 true 
GET /beans 查看bean及其关系列表 true 
GET /dump 打印线程栈 true 
GET /env 查看所有环境变量 true 
GET /env/{
   name} 查看具体变量值 true 
GET /health 查看应用健康指标 false 
GET /info 查看应用信息 false 
GET /mappings 查看所有url映射 true 
GET /metrics 查看应用基本指标 true 
GET /metrics/{
   name} 查看具体指标 true 
POST /shutdown 关闭应用 true 
GET /trace 查看基本追踪信息 true

二、暴露Actuator Endpoints

默认配置:

  • 通过HTTP暴露Actuator endpoints。

    # Use "*" to expose all endpoints, or a comma-separated list to expose selected ones
    management.endpoints.web.exposure.include=health,info       # 一般此处改为 *
    management.endpoints.web.exposure.exclude=
    
  • 通过JMX暴露Actuator endpoints。

    # Use "*" to expose all endpoints, or a comma-separated list to expose selected ones
    management.endpoints.jmx.exposure.include=*
    management.endpoints.jmx.exposure.exclude=
    

三、/health endpoint

health endpoint只展示了简单的UPDOWN状态。为了获得健康检查中所有指标的详细信息,你可以通过在application.yaml中增加如下内容:

management:
  endpoint:
    health:
      show-details: always

四、/info endpoint

info endpoint展示了应用的基本信息。它通过META-INF/build-info.properties来获得编译信息,通过git.properties来获得Git信息。它同时可以展示任何其他信息,只要这个环境property中含有infokey。

你可以增加properties到application.yaml中,比如:

# INFO ENDPOINT CONFIGURATION
info:
  app:
    name: @project.name@
    description: @project.description@
    version: @project.version@
    encoding: @project.build.sourceEncoding@
    java:
      version: @java.version@

五、自定义访问地址

management.endpoints.web.base-path=/     # 默认为/actuator
management.endpoints.web.path-mapping.health:=/healthcheck     # 默认为/health
management.endpoints.web.path-mapping.info:=/infocheck     # 默认为/info

六、打开和关闭Actuator Endpoints

默认,上述所有的endpints都是打开的,除了shutdown endpoint。

你可以通过设置management.endpoint.<id>.enabled to true or false(id是endpoint的id)来决定打开还是关闭一个actuator endpoint。

举个例子,要想打开shutdown endpoint,增加以下内容在你的application.properties文件中:

management.endpoint.shutdown.enabled=true

七、使用Spring Security保证Actuator Endpoints安全

Actuator endpoints是敏感的,必须保障进入是被授权的。如果Spring Security是包含在你的应用中,那么endpoint是通过HTTP认证被保护起来的。

如果没有, 你可以增加以下以来到你的应用中去:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

配置中增加spring security用户

# Spring Security Default user name and password
spring:
  security:
    user:
      name: actuator
      password: actuator

注意:这种用法会对全局接口请求要求登陆

相关文章
|
5天前
|
运维 Prometheus 监控
Spring Boot中使用Actuator监控应用状态
Spring Boot中使用Actuator监控应用状态
|
5天前
|
监控 Java Spring
Spring Boot中使用Actuator进行监控
Spring Boot中使用Actuator进行监控
|
2月前
|
Prometheus 监控 Cloud Native
spring boot 监控
spring boot 监控
35 0
|
SQL 监控 druid
【Spring Boot 快速入门】十、Spring Boot集成Druid数据监控
【Spring Boot 快速入门】十、Spring Boot集成Druid数据监控
587 0
【Spring Boot 快速入门】十、Spring Boot集成Druid数据监控
|
JSON 缓存 监控
Spring Boot Actuator集成,难的是灵活运用!
Spring Boot Actuator集成,难的是灵活运用!
679 0
Spring Boot Actuator集成,难的是灵活运用!
|
Prometheus 监控 Cloud Native
极简教程 | 使用Actuator 实现Spring Boot 应用监控
我们知道Spring Boot 提供了Actuator组件,方便我们对应用程序进行监控和维护。接下来,就来介绍Actuator到底是什么? 如何在Spring Boot项目中快速集成Actuator?
极简教程 | 使用Actuator 实现Spring Boot 应用监控
|
存储 监控 安全
Spring Boot Actuator监控使用详解
Spring Boot Actuator监控使用详解
374 0
|
监控 Java 数据库连接
Spring Boot日志管理
Spring Boot日志管理
139 0
|
缓存 监控 数据可视化
Spring Boot 应用监控
当一个Spring Boot 应用运行的时候,开发者需要对Spring Boot应用进行实时监控,获得项目的报警需求,Spring Boot 提供了,actuator 来帮助开发者获取应用程序运行时的数据。
1190 0