170707、springboot编程之监控和管理生产环境
spring-boot-actuator模块提供了一个监控和管理生产环境的模块,可以使用http、jmx、ssh、telnet等拉管理和监控应用。审计(Auditing)、
健康(health)、数据采集(metrics gathering)会自动加入到应用里面。
首先,写一个最基本的spring boot项目。
基于Maven的项目添加‘starter’依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
以下是所有监控描述:
|
HTTP方法 |
路径 |
描述 |
鉴权 |
|
GET |
/autoconfig |
查看自动配置的使用情况,该报告展示所有auto-configuration候选者及它们被应用或未被应用的原因 |
true |
|
GET |
/configprops |
显示一个所有@ConfigurationProperties的整理列表 |
true |
|
GET |
/beans |
显示一个应用中所有Spring Beans的完整列表 |
true |
|
GET |
/dump |
打印线程栈 |
true |
|
GET |
/env |
查看所有环境变量 |
true |
|
GET |
/env/{name} |
查看具体变量值 |
true |
|
GET |
/health |
查看应用健康指标 |
false |
|
GET |
/info |
查看应用信息 |
false |
|
GET |
/mappings |
查看所有url映射 |
true |
|
GET |
/metrics |
查看应用基本指标 |
true |
|
GET |
/metrics/{name} |
查看具体指标 |
true |
|
POST |
/shutdown |
允许应用以优雅的方式关闭(默认情况下不启用) |
true |
|
GET |
/trace |
查看基本追踪信息 |
true |
health
比如:http://localhost:8080/health
你可以得到结果
{
status: "UP",
diskSpace: {
status: "UP",
total: 107374174208,
free: 14877962240,
threshold: 10485760
}
}
可以检查的其他一些情况的健康信息。下面的HealthIndicators会被Spring Boot自动配置:
DiskSpaceHealthIndicator 低磁盘空间检测
DataSourceHealthIndicator 检查是否能从DataSource获取连接
MongoHealthIndicator 检查一个Mongo数据库是否可用(up)
RabbitHealthIndicator 检查一个Rabbit服务器是否可用(up)
RedisHealthIndicator 检查一个Redis服务器是否可用(up)
SolrHealthIndicator 检查一个Solr服务器是否可用(up)
自定义当然也可以,你可以注册实现了HealthIndicator接口的Spring beans,Health响应需要包含一个status和可选的用于展示的详情。
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component; @Component
public class MyHealth implements HealthIndicator { @Override
public Health health() {
int errorCode = check(); // perform some specific health check
if (errorCode != 0) {
return Health.down().withDetail("Error Code", errorCode).build();
}
return Health.up().build();
}
}
trace
访问http://localhost:8080/trace 可以看到结果,默认为最新的一些HTTP请求
info
当执行 http://localhost:8080/info 的时候,结果什么没有
但是,在application.properties加入一些配置
info.app.name=ecs
info.app.version=1.0.0
info.build.artifactId=@project.artifactId@
info.build.version=@project.version@
执行/info就可以看到有些信息了。
/info 是用来在构建的时候,自动扩展属性的。对于Maven项目,可以通过 @..@ 占位符引用Maven的’project properties’。
更多的细节和探索,需要自己看看源码和spring boot的官方文档。
170707、springboot编程之监控和管理生产环境的更多相关文章
- (33)Spring Boot 监控和管理生产环境【从零开始学Spring Boot】
[本文章是否对你有用以及是否有好的建议,请留言] spring-boot-actuator模块提供了一个监控和管理生产环境的模块,可以使用http.jmx.ssh.telnet等拉管理和监控应用.审计 ...
- SpringBoot使用异步线程池实现生产环境批量数据推送
前言 SpringBoot使用异步线程池: 1.编写线程池配置类,自定义一个线程池: 2.定义一个异步服务: 3.使用@Async注解指向定义的线程池: 这里以我工作中使用过的一个案例来做描述,我所在 ...
- SpringBoot应用的监控与管理
spring-boot-starter-actuator模块 /health /autoconfig /beans /configprops:应用配置属性信息 /env:环境属性,如:环境变量.jvm ...
- SpringBoot整合Swagger2以及生产环境的安全问题处理
1.创建springboot项目 https://www.cnblogs.com/i-tao/p/8878562.html 这里我们使用多环境配置: application-dev.yml(开发环境) ...
- [转]SpringBoot整合Swagger2以及生产环境的安全问题处理
1.创建springboot项目 https://www.cnblogs.com/i-tao/p/8878562.html 这里我们使用多环境配置: application-dev.yml(开发环境) ...
- Springboot监控之一:SpringBoot四大神器之Actuator之3-springBoot的监控和管理--指标说明
Spring Boot包含很多其他的特性,它们可以帮你监控和管理发布到生产环境的应用.你可以选择使用HTTP端点,JMX或远程shell(SSH或Telnet)来管理和监控应用.审计(Auditing ...
- SpringBoot集成Actuator监控管理
1.说明 本文详细介绍Spring Boot集成Actuator监控管理的方法, 基于已经创建好的Spring Boot工程, 然后引入Actuator依赖, 介绍监控管理相关功能的使用. Sprin ...
- springboot应用监控和管理
spring boot应用监控和管理 Spring Boot 监控核心是 spring-boot-starter-actuator 依赖,增加依赖后, Spring Boot 会默认配置一些通用的监控 ...
- 170710、springboot编程之启动器Starter详解
此文系参考网络大牛的,如有侵权,请见谅! Spring Boot应用启动器基本的一共有N(现知道的是44)种:具体如下: 1)spring-boot-starter 这是Spring Boot的核心启 ...
随机推荐
- jump display
查找了数据库,再在while里拼接成json是很麻烦的,所以,jump display 获得数组 <?php header("Content-Type:text/html; chars ...
- 关于Cocos2d-x中让主角运动的方法
比如要让角色跳起来 1.如果是用到物理引擎,那么在物理世界中,可以用 hero->getPhysicsBody()->setVelocity(Vec2(0, 400)); //给主角一个 ...
- 转00600异常解决方案:ORA-00600: 内部错误代码, 参数: [19004], [], [], [], [], []
<问题描述> ORACLE 10.1 OR 10.2中所有平台都存在该问题. <问题现象> 在进行多表关联复杂查询时出现 ORA-00600: 内部错误代码, 参数: [190 ...
- C# 窗体显示避免抢夺焦点
通过调用API进行显示可以避免抢夺焦点的问题 以下是API调用 using System.Runtime.InteropServices; [DllImport("user32.dll&qu ...
- Intellij IDEA:maven的本地仓库问题
不知是否我个人的问题,Intellij IDEA中设置的 maven本地仓库的位置 经常失效,动辄变回默认的路径(~/.m2/repository),然后疯狂下载内容. 很抓狂! 今天认真思考了一番, ...
- e651. 列出所有可用字体
A font family refers to a set of font faces with a related typographic design. For example, the font ...
- pyqt的setObjectName()/findChild()
根据设置的Name标示查找组件的对象,关键函数:setObjectName()/findChild() findChild()/2:需要两个参数, 参数一:组件的类型,如QLineEdit.QPush ...
- openstack热迁移和冷迁移
转自: http://www.cnblogs.com/pycode/p/6494848.html 迁移类型: *非在线迁移 (有时也称之为‘迁移’).也就是在迁移到另外的计算节点时的这段时间虚拟机实例 ...
- jQuery-理解事件
一.理解事件 1.什么是事件 事件是Web浏览器通知应用程序(比如我们的js)发生了某个事情! 我们可以为这些特定的事情,事先安排好处理方案,这样就能够实现互动! 2.事件目标 你可以简单的理解为事件 ...
- swift - UIPickerView 的使用
效果显示数下图: 1.初始化 pickerView.center = self.view.center //将dataSource设置成自己 pickerView.dataSource=self // ...