SpringCloud入门——Actuator健康监控

SpringCloud入门——Actuator健康监控

一、开启监控

开启Actuator只需要在pom文件中,添加actuator依赖。

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

重启服务,打开对应端口/actuator路径,例如http://localhost:8082/actuator,可以看到可以访问的端点。

在这里插入图片描述

现在只开启了health节点和info节点。health里面只有status信息。UP说明这个节点是启动的。

在这里插入图片描述

二、开启监控端点信息

当前提供的监控信息无法满足我们的需求,需要我们在配置文件中进行配置。

*代表所有节点都加载/actuator返回json

#开启所有端点
management.endpoints.web.exposure.include=*

1、开启所有端点

{
  "_links": {
    "self": {
      "href": "http://localhost:8082/actuator",
      "templated": false
    },
    "archaius": {
      "href": "http://localhost:8082/actuator/archaius",
      "templated": false
    },
      //bean信息
    "beans": {
      "href": "http://localhost:8082/actuator/beans",
      "templated": false
    },
    "caches": {
      "href": "http://localhost:8082/actuator/caches",
      "templated": false
    },
    "caches-cache": {
      "href": "http://localhost:8082/actuator/caches/{cache}",
      "templated": true
    },
    "health-path": {
      "href": "http://localhost:8082/actuator/health/{*path}",
      "templated": true
    },
    "health": {
      "href": "http://localhost:8082/actuator/health",
      "templated": false
    },
      //获取应用自定义的信息 
    "info": {
      "href": "http://localhost:8082/actuator/info",
      "templated": false
    },
    "conditions": {
      "href": "http://localhost:8082/actuator/conditions",
      "templated": false
    },
     //获取应用中配置的属性信息报告 
    "configprops": {
      "href": "http://localhost:8082/actuator/configprops",
      "templated": false
    },
    "env-toMatch": {
      "href": "http://localhost:8082/actuator/env/{toMatch}",
      "templated": true
    },
      //获取应用所有可用的环境属性报告 
    "env": {
      "href": "http://localhost:8082/actuator/env",
      "templated": false
    },
    "loggers-name": {
      "href": "http://localhost:8082/actuator/loggers/{name}",
      "templated": true
    },
    "loggers": {
      "href": "http://localhost:8082/actuator/loggers",
      "templated": false
    },
    "heapdump": {
      "href": "http://localhost:8082/actuator/heapdump",
      "templated": false
    },
      //返回程序运行中的线程信息
    "threaddump": {
      "href": "http://localhost:8082/actuator/threaddump",
      "templated": false
    },
    "metrics-requiredMetricName": {
      "href": "http://localhost:8082/actuator/metrics/{requiredMetricName}",
      "templated": true
    },
      //返回应用的各类重要度量指标信息 
    "metrics": {
      "href": "http://localhost:8082/actuator/metrics",
      "templated": false
    },
    "scheduledtasks": {
      "href": "http://localhost:8082/actuator/scheduledtasks",
      "templated": false
    },
      //获取应用所有Spring Web的控制器映射关系报告
    "mappings": {
      "href": "http://localhost:8082/actuator/mappings",
      "templated": false
    },
    "refresh": {
      "href": "http://localhost:8082/actuator/refresh",
      "templated": false
    },
    "features": {
      "href": "http://localhost:8082/actuator/features",
      "templated": false
    },
    "service-registry": {
      "href": "http://localhost:8082/actuator/service-registry",
      "templated": false
    }
  }
}

2、开启shutdown端点

用来关闭服务,开启远程关闭功能。

上面开启所有端点也不会打开shutdown端点,需要配置文件单独配置。

management.endpoint.shutdown.enabled=true

/actuator/shutdown 只支持POST请求。

在这里插入图片描述

3、查看重要度量指标信息

	"metrics-requiredMetricName": {
      "href": "http://localhost:8082/actuator/metrics/{requiredMetricName}",
      "templated": true
    },
      //返回应用的各类重要度量指标信息 
    "metrics": {
      "href": "http://localhost:8082/actuator/metrics",
      "templated": false
    },

先通过http://localhost:8082/actuator/metrics应用的各类重要度量指标信息。

{
  "names": [
    "http.server.requests",
    "jvm.buffer.count",
    "jvm.buffer.memory.used",
    "jvm.buffer.total.capacity",
    "jvm.classes.loaded",
    "jvm.classes.unloaded",
    "jvm.gc.live.data.size",
    "jvm.gc.max.data.size",
    "jvm.gc.memory.allocated",
    "jvm.gc.memory.promoted",
    "jvm.gc.pause",
    "jvm.memory.committed",
    "jvm.memory.max",
    "jvm.memory.used",
    "jvm.threads.daemon",
    "jvm.threads.live",
    "jvm.threads.peak",
    "jvm.threads.states",
    "logback.events",
    "process.cpu.usage",
    "process.start.time",
    "process.uptime",
    "system.cpu.count",
    "system.cpu.usage",
    "tomcat.sessions.active.current",
    "tomcat.sessions.active.max",
    "tomcat.sessions.alive.max",
    "tomcat.sessions.created",
    "tomcat.sessions.expired",
    "tomcat.sessions.rejected"
  ]
}

然后通过http://localhost:8082/actuator/metrics/{requiredMetricName}查看对应指标详细数据,比如我们要查看jvm内存使用情况,就通过http://localhost:8082/actuator/metrics/jvm.memory.used查看。

{
  "name": "jvm.memory.used",
  "description": "The amount of used memory",
  "baseUnit": "bytes",
  "measurements": [
    {
      "statistic": "VALUE",
      "value": 63845552
    }
  ],
  "availableTags": [
    {
      "tag": "area",
      "values": [
        "heap",
        "nonheap"
      ]
    },
    {
      "tag": "id",
      "values": [
        "Survivor Space",
        "Eden Space",
        "Metaspace",
        "Code Cache",
        "Tenured Gen"
      ]
    }
  ]
}

4、系统环境变量

http://localhost:8082/actuator/env

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值