SpringBoot 2.X 使用Actuator监控

1.添加POM依赖
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
二.添加配置文件
server:
  port: 8080
  servlet:
    context-path: /demo
# actuator 监控配置
management:
  #actuator端口 如果不配置做默认使用上面8080端口
  server:
    port: 9090
  endpoints:
    web:
      exposure:
        #默认值访问health,info端点  用*可以包含全部端点
        include: "*"
      #修改访问路径 2.0之前默认是/; 2.0默认是/actuator可以通过这个属性值修改
      base-path: /actuator

配置完成启动项目后就可以通过postman或者直接在预览器输入路径等方式来查看应用的运行状态了。
当项目启动时,访问http://127.0.0.1:9090/actuator地址

注意:如果没有配置 actuator端口,采用默认访问地址:http://127.0.0.1:8080/demo/actuator

如果看到类似下面的内容,说明actuator已经生效了

{
    "_links": {
        "self": {
            "href": "http://127.0.0.1:9090/actuator",
            "templated": false
        },
        "auditevents": {
            "href": "http://127.0.0.1:9090/actuator/auditevents",
            "templated": false
        },
        "beans": {
            "href": "http://127.0.0.1:9090/actuator/beans",
            "templated": false
        },
        "caches-cache": {
            "href": "http://127.0.0.1:9090/actuator/caches/{cache}",
            "templated": true
        },
        "caches": {
            "href": "http://127.0.0.1:9090/actuator/caches",
            "templated": false
        },
        "health": {
            "href": "http://127.0.0.1:9090/actuator/health",
            "templated": false
        },
        "health-component": {
            "href": "http://127.0.0.1:9090/actuator/health/{component}",
            "templated": true
        },
        "health-component-instance": {
            "href": "http://127.0.0.1:9090/actuator/health/{component}/{instance}",
            "templated": true
        },
        "conditions": {
            "href": "http://127.0.0.1:9090/actuator/conditions",
            "templated": false
        },
        "configprops": {
            "href": "http://127.0.0.1:9090/actuator/configprops",
            "templated": false
        },
        "env": {
            "href": "http://127.0.0.1:9090/actuator/env",
            "templated": false
        },
        "env-toMatch": {
            "href": "http://127.0.0.1:9090/actuator/env/{toMatch}",
            "templated": true
        },
        "info": {
            "href": "http://127.0.0.1:9090/actuator/info",
            "templated": false
        },
        "loggers": {
            "href": "http://127.0.0.1:9090/actuator/loggers",
            "templated": false
        },
        "loggers-name": {
            "href": "http://127.0.0.1:9090/actuator/loggers/{name}",
            "templated": true
        },
        "heapdump": {
            "href": "http://127.0.0.1:9090/actuator/heapdump",
            "templated": false
        },
        "threaddump": {
            "href": "http://127.0.0.1:9090/actuator/threaddump",
            "templated": false
        },
        "metrics-requiredMetricName": {
            "href": "http://127.0.0.1:9090/actuator/metrics/{requiredMetricName}",
            "templated": true
        },
        "metrics": {
            "href": "http://127.0.0.1:9090/actuator/metrics",
            "templated": false
        },
        "scheduledtasks": {
            "href": "http://127.0.0.1:9090/actuator/scheduledtasks",
            "templated": false
        },
        "httptrace": {
            "href": "http://127.0.0.1:9090/actuator/httptrace",
            "templated": false
        },
        "mappings": {
            "href": "http://127.0.0.1:9090/actuator/mappings",
            "templated": false
        }
    }
}

端点地址官网地址: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html

springboot 2 配置属性地址:https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/reference/html/common-application-properties.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容