Spring Boot Actualtor 运行状态监控

Spring Boot Actualtor 运行状态监控

参考官方文档:详细可以查看官方文档

Spring Boot Actuator 可以帮助你监控和管理Spring Boot应用,监控数据可以使用 REST、 JMX或者shell来获得。 下面配置REST方式使用Actuator。

项目引入 Actuator 起步依赖

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

配置文件 application.yml 中添加 Actuator 相关配置信息。

配置 port 是为了区分项目的端口与监控的端口,若不配置默认访问的为项目端口。

# 在Spring Boot 2.0 之前版本只需要 management.port 不需要中间的 server
management:
  server:
    port: 9001 # Spring Boot 2.0 之后直接访问 localhost:9001/health 无效,需要加上/actuator localhost:9001/actuator/health
  #  Spring Boot 1.5 - 2.0 之间的版本需要设置下面的 security.enabled 为false 否则需要安全认证
  #  security:
  #    enabled: false
  endpoints:
    web:
      base-path: /manager # 默认情况下,路径为 /actuator, 所有Web端点均可用/actuator/{id},配置后更改为/manager/{id}
      exposure:
        include: health,dump, env # 设置开启端点,端点之间使用英文逗号隔开,这样只能访问当前设置的端点,若要开启所有可以使用 "*",如include: "*", yaml文件中引号是必须的,properties文件则不需要
  #        exclude: env # 排除不需要的端点
  endpoint:
    health:
      show-details: always # 展示详细 health 信息 Spring Boot 2.0 之后不直接展示详细信息需要设置此配置

以下是部分端口信息,详细可以查看官方文档 这里的版本为2.2.1,与1.x的会有差别,如autoconfig 更改为conditions,原 trace 改为 httptrace

类型端口描述
getauditevents显示应用暴露的审计事件 (比如认证进入、订单失败)
getbeans描述应用程序上下文里所有的bean以及它们的关系
getcaches检索应用程序的缓存
getconditionsconditions 端点提供有关的配置和自动配置类条件的评估信息
getconfigprops描述配置属性如何注入bean
getenv获取所有环境属性
get/env/{property.name}根据名称获取特定的环境属性值
gethealth应用程序的健康指标
gethttptrace提供关于HTTP请求-响应交换信息(时间戳,HTTP头等)
getinfo获取应用程序信息
getlogfile获取日志信息
getmappings描述全部的URI路径,以及他们和控制器(包括Actuator端点)的映射关系
getmetrics访问应用程序指标,例如内存量和HTTP请求计数
getshutdown关闭应用程序,需要设置 endpoints.shutdown.enable=true

查看开启的端点

访问 http://localhost:9001/actuator

{
    "_links": {
        "self": {
            "href": "http://localhost:9001/actuator",
            "templated": false
        },
        "env": {
            "href": "http://localhost:9001/actuator/env",
            "templated": false
        },
        "env-toMatch": {
            "href": "http://localhost:9001/actuator/env/{toMatch}",
            "templated": true
        }
    }
}

查看运行程序健康状态

访问: http://localhost:9001/manager/health

{
    "status": "UP",
    "components": {
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 215288442880,
                "free": 152013299712,
                "threshold": 10485760
            }
        },
        "ping": {
            "status": "UP"
        }
    }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值