spring-boot-starter-actuator(健康监控)配置和使用

315 阅读2分钟

1 pom 添加

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

2.配置文件添加

      endpoints:
        web:
          exposure:
            include: "*"

3.打开http://localhost:9300/actuator 可看到

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


/autoconfig 查看自动配置的使用情况 true

/configprops 查看配置属性,包括默认配置 true

/beans 查看bean及其关系列表 true

/dump 打印线程栈 true

/env 查看所有环境变量 true

/env/{name} 查看具体变量值 true

/health 查看应用健康指标 false

/info 查看应用信息(需要自己在application.properties里头添加信息,比如info.contact.email=easonjim@163.com) false

/mappings 查看所有url映射 true

/metrics 查看应用基本指标 true

/metrics/{name} 查看具体指标 true

/shutdown 关闭应用(要真正生效,得配置文件开启endpoints.shutdown.enabled: true) true

/trace 查看基本追踪信息 true