论文转载自博客:

https://blog.csdn.net/Dreamhai/article/details/81077903

https://bigjar.github.io/2018/08/19/Spring-Boot-Actuator-%E5%81%A5%E5%BA%B7%E6%A3%80%E6%9F%A5%E3%80%81%E5%AE%A1%E8%AE%A1%E3%80%81%E7%BB%9F%E8%AE%A1%E5%92%8C%E7%9B%91%E6%8E%A7/

要求spring boot在2.0版本以上

代码如下

在之前的系列文章中我们学习了如何进行Spring Boot应用的功能开发,以及如何写单元测试、集成测试等,然而,在实际的软件开发中需要做的不仅如此:还包括对应用程序的监控和管理。

You build it,You run it, 当我们编写的项目上线后,为了能第一时间知晓该项目是否出现问题,常常对项目进行健康检查及一些指标进行监控。
Spring Boot-Actuator 就是帮助我们监控我们的Spring Boot 项目的。

使用
Spring Boot 最主要的特性就是AutoConfig(自动配置),而对于我们这些使用者来说也就是各种starter,
Spring Boot-Actuator 也提供了starter,为我们自动配置,在使用上我们只需要添加starter到我们的依赖中,然后启动项目即可。

整个pom文件依赖如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.</modelVersion>
<groupId>com.tuling.cloud</groupId>
<artifactId>microservice-consumer-order-ribbon-hystrix-fallback</artifactId>
<version>0.0.-SNAPSHOT</version>
<packaging>jar</packaging> <!-- 引入spring boot的依赖 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0..RELEASE</version>
</parent> <properties>
<project.build.sourceEncoding>UTF-</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.</version>
</dependency> <!--监控中心-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependencies> <!-- 引入spring cloud的依赖 -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Finchley.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <!-- 添加spring-boot的maven插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

spring boot 的版本是2.0版本以上

Spring Boot Actuator可以帮助你监控和管理Spring Boot应用,比如健康检查、审计、统计和HTTP追踪等。所有的这些特性可以通过JMX或者HTTP endpoints来获得。

2. 端点(Endpoints)
执行器端点(endpoints)可用于监控应用及与应用进行交互,Spring Boot包含很多内置的端点,你也可以添加自己的。例如,health端点提供了应用的基本健康信息。
每个端点都可以启用或禁用。这控制着端点是否被创建,并且它的bean是否存在于应用程序上下文中。要远程访问端点,还必须通过JMX或HTTP进行暴露,大部分应用选择HTTP,端点的ID映射到一个带/actuator前缀的URL。例如,health端点默认映射到/actuator/health。

注意:
Spring Boot 2.0的端点基础路径由“/”调整到”/actuator”下,如:/info调整为/actuator/info
可以通过以下配置改为和旧版本一致:

management.endpoints.web.base-path=/

现在我们要暴露所有的端点,配置文件如下

application.properties

management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always
通过设置management.endpoints.web.exposure.include为*,我们可以在http://localhost:8080/actuator页面看到如下内容。

看上面的一个具体的请求为

application.yml


#hystrix.command.default.execution.isolation.strategy=Semaphore
#hystrix.command.default.execution.isolation.semaphore.maxConcurrentRequests=10
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=200009
hystrix.command.default.circuitBreaker.requestVolumeThreshold=3;
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=3000
hystrix.command.default.circuitBreaker.errorThresholdPercentage=50
management.security.enabled=false
management.endpoint.shutdown.enabled=true
management.endpoint.scheduledtasks.enabled=true
management.endpoint.scheduledtasks.enabled=true
management.endpoint.scheduledtasks.enabled=true
management.endpoint.heapdump.enabled=true
management.endpoint.threaddump.enabled=true
management.endpoint.httptrace.enabled=true
# \u52A0\u8F7D\u6240\u6709\u7684\u7AEF\u70B9/\u9ED8\u8BA4\u53EA\u52A0\u8F7D\u4E86 info / health
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always


info.build.artifact=@project.artifactId@
info.build.name=@project.name@
info.build.description=@project.description@
info.build.version=@project.version@


例如/info:首先在application.properties文件中添加对应的属性值,符号@包围的属性值来自pom.xml文件中的元素节点。


这里需要注意的是:@RequestMapping(value = "/produces", produces = "application/json"):表示将功能处理方法将生产json格式的数据,此时根据请求头中的Accept进行匹配,如请求头“Accept:application/json”时即可匹配;

访问"{[/actuator/httptrace],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}","访问httptrace需要请求的头信息是Accept参数是application/vnd.spring-boot.actuator.v2+json或者是application/json;

Spring Boot]SpringBoot四大神器之Actuator的更多相关文章

  1. SpringBoot四大神器之Actuator

    介绍 Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供 ...

  2. Springboot监控之一:SpringBoot四大神器之Actuator

    介绍 Spring Boot有四大神器,分别是auto-configuration.starters.cli.actuator,本文主要讲actuator.actuator是spring boot提供 ...

  3. Springboot监控之一:SpringBoot四大神器之Actuator之2--spring boot健康检查对Redis的连接检查的调整

    因为项目里面用到了redis集群,但并不是用spring boot的配置方式,启动后项目健康检查老是检查redis的时候状态为down,导致注册到eureka后项目状态也是down.问下能不能设置sp ...

  4. Springboot监控之一:SpringBoot四大神器之Actuator之3-springBoot的监控和管理--指标说明

    Spring Boot包含很多其他的特性,它们可以帮你监控和管理发布到生产环境的应用.你可以选择使用HTTP端点,JMX或远程shell(SSH或Telnet)来管理和监控应用.审计(Auditing ...

  5. Springboot监控之一:SpringBoot四大神器之Actuator之2--springboot健康检查

    Health 信息是从 ApplicationContext 中所有的 HealthIndicator 的 Bean 中收集的, Spring Boot 内置了一些 HealthIndicator. ...

  6. Springboot监控之一:SpringBoot四大神器之Actuator之2--覆盖修改spring cloud的默认的consul健康检查规则

    微服务网关是socket长连接与支付公司对接,该网关需要提供http接口给内部系统调用,当socket没有建立连接时(网关服务的高可用是haProxy搭建的,有些服务的socket可能未连上支付公司) ...

  7. SpringBoot四大神器之Starter

    SpringBoot的starter主要用来简化依赖用的.本文主要分两部分,一部分是列出一些starter的依赖,另一部分是教你自己写一个starter. 部分starters的依赖 Starter( ...

  8. SpringBoot四大神器之auto-configuration

    SpringBoot 自动配置主要通过 @EnableAutoConfiguration, @Conditional, @EnableConfigurationProperties 或者 @Confi ...

  9. 学习Spring Boot:(二十七)Spring Boot 2.0 中使用 Actuator

    前言 主要是完成微服务的监控,完成监控治理.可以查看微服务间的数据处理和调用,当它们之间出现了异常,就可以快速定位到出现问题的地方. springboot - version: 2.0 正文 依赖 m ...

随机推荐

  1. [Objective-C] 016_UI篇_UIView(上)

    在我们使用app时屏幕上能看到的UI元素(按钮,列表,图片...),我们称之为视图,都是继承与UIView,它们通常有着位置,大小,背景颜色等属性,在appl中视图和窗口展示了应用的用户界面,同时负责 ...

  2. Linux(一):VMware安装出现的问题

    目录 1 兼容性问题 2 VMware打卡虚拟机提示"此虚拟机可能已被复制或移动" 1 兼容性问题 问题:VMware Workstation 与 Device/Credentia ...

  3. 设计并测试Trapezium类 代码参考

    #include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...

  4. 循序渐进VUE+Element 前端应用开发(6)--- 常规Element 界面组件的使用

    在我们开发BS页面的时候,往往需要了解常规界面组件的使用,小到最普通的单文本输入框.多文本框.下拉列表,以及按钮.图片展示.弹出对话框.表单处理.条码二维码等等,本篇随笔基于普通表格业务的展示录入的场 ...

  5. [前端开发]form-data和x-www-form-urlencoded的区别

    在后台开发时,之前做了文件的上传,用的是form-data,但并不知其区别.今天遇到了req.body为空的情况,切换成了x-www-form-urlencoded解决 form-data 就是htt ...

  6. js函数prototype属性学习(二)

    继续探讨js对象的prototype属性,前面已经看到在创建完一个对象之后,随时都会有一个_proto_属性伴随所有,那么,这个_proto_又是用来干嘛的,面试时问的高大上的原型链又是怎么回事? 拿 ...

  7. JavaScript (六) js的基本语法 - - - Math 及 Date对象、String对象、Array对象

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 一.Math 1.Math对象的案例 var result= Math.max(10,20,30,40) ...

  8. Java实现 第十一届 蓝桥杯 (本科组)省内模拟赛

    有错误的或者有问题的欢迎评论 计算机存储中有多少字节 合法括号序列 无向连通图最少包含多少条边 字母重新排列 凯撒密码加密 反倍数 正整数的摆动序列 螺旋矩阵 小明植树 户户通电 计算机存储中有多少字 ...

  9. Java实现 LeetCode 225 用队列实现栈

    225. 用队列实现栈 使用队列实现栈的下列操作: push(x) – 元素 x 入栈 pop() – 移除栈顶元素 top() – 获取栈顶元素 empty() – 返回栈是否为空 注意: 你只能使 ...

  10. java实现第七届蓝桥杯搭积木

    搭积木 题目描述 小明最近喜欢搭数字积木, 一共有10块积木,每个积木上有一个数字,0~9. 搭积木规则: 每个积木放到其它两个积木的上面,并且一定比下面的两个积木数字小. 最后搭成4层的金字塔形,必 ...