Netflix之Actuator

发布时间 2023-10-07 15:49:47作者: -Lucas

一、Actuator简介

监控应用,上报状态信息

二、开启监控

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

三、端点

Spring Boot 2.0的Actuator默认只暴露了health和info端点

1、开启其他端点

management:
  server:
    port: 8001
  #开启所有端点
  endpoints:
    web:
      exposure:
        include: '*'
  # 开启shutdown端点 调用关闭服务
  endpoint:
    shutdown:
      enabled: true

2、查看所有端点请求路径 http://localhost:8001/actuator/

{
    "_links": {
        "self": {
            "href": "http://localhost:8001/actuator",
            "templated": false
        },
        "archaius": {
            "href": "http://localhost:8001/actuator/archaius",
            "templated": false
        },
        "beans": {
            "href": "http://localhost:8001/actuator/beans",
            "templated": false
        },
        "caches-cache": {
            "href": "http://localhost:8001/actuator/caches/{cache}",
            "templated": true
        },
        "caches": {
            "href": "http://localhost:8001/actuator/caches",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8001/actuator/health",
            "templated": false
        },
        "health-path": {
            "href": "http://localhost:8001/actuator/health/{*path}",
            "templated": true
        },
        "info": {
            "href": "http://localhost:8001/actuator/info",
            "templated": false
        },
        "conditions": {
            "href": "http://localhost:8001/actuator/conditions",
            "templated": false
        },
        "shutdown": {
            "href": "http://localhost:8001/actuator/shutdown",
            "templated": false
        },
        "configprops": {
            "href": "http://localhost:8001/actuator/configprops",
            "templated": false
        },
        "env": {
            "href": "http://localhost:8001/actuator/env",
            "templated": false
        },
        "env-toMatch": {
            "href": "http://localhost:8001/actuator/env/{toMatch}",
            "templated": true
        },
        "loggers": {
            "href": "http://localhost:8001/actuator/loggers",
            "templated": false
        },
        "loggers-name": {
            "href": "http://localhost:8001/actuator/loggers/{name}",
            "templated": true
        },
        "heapdump": {
            "href": "http://localhost:8001/actuator/heapdump",
            "templated": false
        },
        "threaddump": {
            "href": "http://localhost:8001/actuator/threaddump",
            "templated": false
        },
        "metrics-requiredMetricName": {
            "href": "http://localhost:8001/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://localhost:8001/actuator/metrics",
            "templated": false
        },
        "scheduledtasks": {
            "href": "http://localhost:8001/actuator/scheduledtasks",
            "templated": false
        },
        "mappings": {
            "href": "http://localhost:8001/actuator/mappings",
            "templated": false
        },
        "refresh": {
            "href": "http://localhost:8001/actuator/refresh",
            "templated": false
        },
        "features": {
            "href": "http://localhost:8001/actuator/features",
            "templated": false
        },
        "service-registry": {
            "href": "http://localhost:8001/actuator/service-registry",
            "templated": false
        }
    }
}

3、功能

//Health  显示系统状态
{"status":"UP"}

//shutdown  关闭服务
//使用Post方式请求端点
{
  "message": "Shutting down, bye..."
}

//autoconfig  获取应用的自动化报告

//beans  获取应用上下文中创建的所有Bean

//configprops  获取应用中配置的属性信息报告

//env  获取应用所有可用的环境属性报告

//mappings  获取应用所有Spring Web的控制器映射关系报告

//info  获取应用自定义的信息 

//metrics  返回应用的各类重要度量指标信息 
//metrics节点并没有返回全量信息,我们可以通过不同的key去加载我们想要的值metrics/jvm.memory.max

//threaddump  返回程序运行中的线程信息