美文网首页
Spring Boot整合Actuator

Spring Boot整合Actuator

作者: 你慧快乐 | 来源:发表于2019-03-27 21:06 被阅读0次

SpringBoot Actuator是SpringBoot生态中一个用于监控项目到工程,提供了多个监控点,可通过http://{ip}:{port}/{endpoint}的形式访问这些端点,从而了解应用的运行状况。
Acturator提供的监控点:

端点 描述 HTTP方法
autoconfig 显示自动配置的信息 GET
beans 显示应用程序上下文所有的Spring Bean GET
configprops 显示所有@ConfigurationProperties的配置属性列表 GET
dump 显示线程活动快照 GET
env 显示应用的环境变量 GET
health 显示应用程序的监控指标,这些值由HealthIndicator的实现类提供 GET
info 显示应用的信息,可使用info.*属性自定义info端点公开的数据 GET
mappings 显示所有的URL路径 GET
metrics 显示应用的度量标准信息 GET
shutdown 关闭应用,默认不启用,通过设置endpoints.shutdown.enabled=true启用 GET
trace 显示跟踪信息,默认最近100个请求 GET

集成

为项目添加以下依赖:

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

访问http://localhost:8040/health

{
  "status": "UP",
  "configServer": {
    "status": "UP",
    "repositories": [
      {
        "name": "app",
        "profiles": [
          "default"
        ],
        "label": "master"
      }
    ]
  },
  "discoveryComposite": {
    "description": "Spring Cloud Eureka Discovery Client",
    "status": "UP",
    "discoveryClient": {
      "description": "Spring Cloud Eureka Discovery Client",
      "status": "UP",
      "services": [
        
      ]
    },
    "eureka": {
      "description": "Remote status from Eureka server",
      "status": "UNKNOWN",
      "applications": {
        
      }
    }
  },
  "diskSpace": {
    "status": "UP",
    "total": 200000118784,
    "free": 97056731136,
    "threshold": 10485760
  },
  "refreshScope": {
    "status": "UP"
  },
  "hystrix": {
    "status": "UP"
  }
}

访问http://localhost:8040/info
返回:

{}

在项目properties.yml中配置以下信息:

info:
  name: @project.artifactId@
  encoding: @project.build.sourceEncoding@
  java:
    source: @java.version@
    target: @java.version@

重启后再访问http://localhost:8040/info

{
  "name": "microservice-configserver",
  "encoding": "UTF-8",
  "java": {
    "source": "1.8.0_191",
    "target": "1.8.0_191"
  }
}

相关文章

网友评论

      本文标题:Spring Boot整合Actuator

      本文链接:https://www.haomeiwen.com/subject/ceotbqtx.html