第11章 Spring Boot使用Actuator

 

  在生产环境中,须要实时或按期监控服务的可用性,spring-Boot的Actuator 功能提供了不少监控所需的接口。node

Actuator是Spring Boot提供的对应用系统的自省和监控的集成功能,能够对应用系统进行配置查看、健康检查、相关功能统计等,通常运维人员使用多些。web

11.1 使用该功能步骤

咱们这里监控03-springboot-web程序spring

11.1.1        在项目的pom.xml中添加以下依赖

<!--Spring Boot Actuator依赖-->
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

11.1.2        在application.properties或application.yml配置文件中指定监控的HTTP端口及路径

我这里没有进行配置json

  • #服务运行的端口

  server.port=8080浏览器

  server.servlet.context-path=/03-springboot-webspringboot

  • #actuator监控的端口(端口可配可不配,若是不配置,则使用和server.port相同的端口)

  management.server.port=8100app

  • #actuator监控的访问上下文根路径(路径可配可不配,若是不配置,则使用和server.context-path相同的路径)

  management.server.servlet.context-path=/03-springboot-web运维

 

11.1.3        在application.properties或application.yml配置文件中设置开启全部的端口

#默认只开启了health和info,设置为*,则包含全部的web入口端点 management.endpoints.web.exposure.include=*

11.1.4        启动MySQL

11.1.5        启动Redis

 

11.1.7       启动03-springboot-web

 

(1)   浏览器访问http://localhost:8080/actuator/health

 

(2)浏览器访问http://localhost:8080/actuator/info

默认没有内容spring-boot

 

 

须要本身在application.properties配置文件中添加信息,须要以info开头,后面的内容能够本身设定,通常配置项目的版权等信息,例如url

 

#配置项目版权相关信息 info.contact.email=bjpowernode@163.com info.contact.phone=010-84846003

配置完毕后,重启项目再进行访问

 

 

 

11.2 Actuator 提供的主要功能

 

HTTP方法

路径

描述

GET

/configprops

查看配置属性,包括默认配置
http://www.haojson.com对json进行格式化

GET

/beans

查看Spring容器目前初始化的bean及其关系列表

GET

/env

查看全部环境变量

GET

/mappings

查看全部url映射

GET

/health

查看应用健康指标

GET

       /info

查看应用信息

GET

/metrics

查看应用基本指标

GET

/metrics/{name}

查看具体指标

JMX

/shutdown

关闭应用

 

 

shutdown的使用

注意:/shutdown不能直接在浏览器中访问

  • 先在application.properties文件中配置
# 启用关闭springboot的服务 management.endpoint.shutdown.enabled=true
  • 双击打开jconsole

 

 

  • 选择Spring Boot进程,进行链接管理

 

  • 点击shutdown,可关闭Spring Boot服务
相关文章
相关标签/搜索