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编程之监控和管理生产环境的更多相关文章

  1. (33)Spring Boot 监控和管理生产环境【从零开始学Spring Boot】

    [本文章是否对你有用以及是否有好的建议,请留言] spring-boot-actuator模块提供了一个监控和管理生产环境的模块,可以使用http.jmx.ssh.telnet等拉管理和监控应用.审计 ...

  2. SpringBoot使用异步线程池实现生产环境批量数据推送

    前言 SpringBoot使用异步线程池: 1.编写线程池配置类,自定义一个线程池: 2.定义一个异步服务: 3.使用@Async注解指向定义的线程池: 这里以我工作中使用过的一个案例来做描述,我所在 ...

  3. SpringBoot应用的监控与管理

    spring-boot-starter-actuator模块 /health /autoconfig /beans /configprops:应用配置属性信息 /env:环境属性,如:环境变量.jvm ...

  4. SpringBoot整合Swagger2以及生产环境的安全问题处理

    1.创建springboot项目 https://www.cnblogs.com/i-tao/p/8878562.html 这里我们使用多环境配置: application-dev.yml(开发环境) ...

  5. [转]SpringBoot整合Swagger2以及生产环境的安全问题处理

    1.创建springboot项目 https://www.cnblogs.com/i-tao/p/8878562.html 这里我们使用多环境配置: application-dev.yml(开发环境) ...

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

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

  7. SpringBoot集成Actuator监控管理

    1.说明 本文详细介绍Spring Boot集成Actuator监控管理的方法, 基于已经创建好的Spring Boot工程, 然后引入Actuator依赖, 介绍监控管理相关功能的使用. Sprin ...

  8. springboot应用监控和管理

    spring boot应用监控和管理 Spring Boot 监控核心是 spring-boot-starter-actuator 依赖,增加依赖后, Spring Boot 会默认配置一些通用的监控 ...

  9. 170710、springboot编程之启动器Starter详解

    此文系参考网络大牛的,如有侵权,请见谅! Spring Boot应用启动器基本的一共有N(现知道的是44)种:具体如下: 1)spring-boot-starter 这是Spring Boot的核心启 ...

随机推荐

  1. android jni aotf 错误

    在jni中希望将字符串转成浮点型数据,使用了atof函数.出现错误: failed: Cannot load library: soinfo_relocate(linker.cpp:975): can ...

  2. python print 不换行

    #!/usr/bin/python # -*- coding: UTF- -*- ,): ,i+): print "%d * %d = %2d\t" % (j, i, i*j), ...

  3. Ubuntu下启动/重启/停止apache服务器

    Task: Start Apache 2 Server /启动apache服务# /etc/init.d/apache2 startor$ sudo /etc/init.d/apache2 start ...

  4. PHP清除HTML代码、空格、回车换行符的函数

    清除HTML代码.空格.回车换行符的函数如下 function DeleteHtml($str) { $str = trim($str); $str = strip_tags($str,"& ...

  5. c++ 参赛设置

    void report(LogWriter& lw); 代表引用原对象 void report(LogWriter lw); 代表重新拷贝构造一个对象

  6. svn merge和branch分析

    [转载] 使用svn几年了,一直对分支和合并敬而远之,一来是因为分支的管理不该我操心,二来即使涉及到分支的管理,也不敢贸然使用合并功能,生怕合并出了问题对团队造成不良影响,最主要的原因是,自己对分支的 ...

  7. Unity3d + PureMVC框架搭建

    0.流程:LoginView-SendNotification()---->LoginCommand--Execute()--->调用proxy中的函数操作模型数据--LoginProxy ...

  8. centos7下配置免密码登录

    主机master ,slaver1,slaver2 1.每台主机都执行 ssh-keygen -t rsa 然后一直回车 2.操作master.master生成公钥 放入authorized_keys ...

  9. js正则表达式的应用

    JavaScript表单验证email,判断一个输入量是否为邮箱email,通过正则表达式实现. //检查email邮箱 function isEmail(str){ var reg = /^([a- ...

  10. java jdk-awt.font在centos上中文乱码的问题, 安装中文字体

    有需求生成一个二维码,并且有一段文本说明,但是使用awt.font来生成中文时,一直存在乱码的问题.网上的解决办法有几种,但是在centos上亲测有用的就是如下的方法. Java代码如下:new ja ...