原文地址:http://blog.csdn.net/wh_ouyangshuang/article/details/48048111

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>
ID 描述 敏感(Sensitive)
autoconfig 显示一个auto-configuration的报告,该报告展示所有auto-configuration候选者及它们被应用或未被应用的原因 true
beans 显示一个应用中所有Spring Beans的完整列表 true
configprops 显示一个所有@ConfigurationProperties的整理列表 true
dump 执行一个线程转储 true
env 暴露来自Spring ConfigurableEnvironment的属性 true
health 展示应用的健康信息(当使用一个未认证连接访问时显示一个简单的’status’,使用认证连接访问则显示全部信息详情) false
info 显示任意的应用信息 false
metrics 展示当前应用的’指标’信息 true
mappings 显示一个所有@RequestMapping路径的整理列表 true
shutdown 允许应用以优雅的方式关闭(默认情况下不启用) true
trace 显示trace信息(默认为最新的一些HTTP请求) true

health

比如:http://localhost:8080/health 
你可以得到结果

{
status: "UP",
}

在应用配置加上

endpoints.health.sensitive=false

再次访问http://localhost:8080/health

{
status: "UP",
diskSpace: {
status: "UP",
free: 32516145152,
threshold: 10485760
},
db: {
status: "UP",
database: "Microsoft SQL Server",
hello: 1440729256277
}
}

自定义当然也可以,你可以注册实现了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请求

[
{
timestamp: 1440728799269,
info: {
method: "GET",
path: "/health",
headers: {
request: {
host: "localhost:7231",
connection: "keep-alive",
accept: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
user-agent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36",
accept-encoding: "gzip,deflate,sdch",
accept-language: "zh-CN,zh;q=0.8,en;q=0.6",
ra-ver: "3.0.7",
ra-sid: "74E754D8-20141117-085628-93e7a4-1dd60b"
},
response: {
X-Application-Context: "executecount:integration:7231",
Content-Type: "application/json;charset=UTF-8",
Transfer-Encoding: "chunked",
Content-Encoding: "gzip",
Vary: "Accept-Encoding",
Date: "Fri, 28 Aug 2015 02:26:39 GMT",
status: "200"
}
}
}
}
]

看看 InMemoryTraceRepository,默认是100个事件,如果需要可以定义自己的 InMemoryTraceRepository 实例。如果需要,你可以创建自己的替代 TraceRepository 实现。

public class InMemoryTraceRepository implements TraceRepository {

    private int capacity = 100;

    private boolean reverse = true;
}

如果需要追踪其他的事件,你可以将一个TraceRepository注入到你的Spring Beans中

info

当执行 http://localhost:8080/info 的时候,结果什么没有 
但是,单加入加入一些配置

info.app.name=ecs
info.app.version=1.0.0 info.build.artifactId=@project.artifactId@
info.build.version=@project.version@

执行/info

{
app: {
version: "1.0.0",
name: "ecs"
},
build: {
artifactId: "execute-count-server",
version: "0.0.3"
}
}

/info 是用来在构建的时候,自动扩展属性的。对于Maven项目,可以通过 @..@ 占位符引用Maven的’project properties’。

env

通过/env可以访问环境信息

{
profiles: [
"integration"
],
servletContextInitParams: { },
systemProperties: {
java.runtime.name: "Java(TM) SE Runtime Environment",
java.vm.version: "25.25-b02",
java.vm.vendor: "Oracle Corporation",
java.vendor.url: "http://java.oracle.com/",
path.separator: ";",
idea.launcher.port: "7532",
java.vm.name: "Java HotSpot(TM) 64-Bit Server VM",
file.encoding.pkg: "sun.io",
user.country: "CN",
user.script: "",
sun.java.launcher: "SUN_STANDARD",
sun.os.patch.level: "Service Pack 1",
PID: "7416",
java.vm.specification.name: "Java Virtual Machine Specification", ...

通过/env/{name:.*}可以访问特定的环境属性,如:/env/java.*,获取java相关的项

metrics

/metrics显示了应用当前的指标信息

{
mem: 348672,
mem.free: 264831,
processors: 4,
instance.uptime: 1859584,
uptime: 1870818,
systemload.average: -1,
heap.committed: 348672,
heap.init: 124928,
heap.used: 83840,
heap: 1773568,
threads.peak: 23,
threads.daemon: 21,
threads: 23,
classes: 7269,
classes.loaded: 7272,
classes.unloaded: 3,
gc.ps_scavenge.count: 7,
gc.ps_scavenge.time: 379,
gc.ps_marksweep.count: 2,
gc.ps_marksweep.time: 283,
httpsessions.max: -1,
httpsessions.active: 0,
datasource.primary.active: 0,
datasource.primary.usage: 0,
counter.status.200.autoconfig: 1,
counter.status.200.dump.root: 1,
counter.status.200.env: 2,
counter.status.200.env.name:.-star-: 4,
counter.status.200.env.root: 3,
counter.status.200.health: 2,
counter.status.200.info: 1,
counter.status.200.mappings: 1,
counter.status.200.trace: 1,
counter.status.404.env.name:.-star-: 1,
gauge.response.autoconfig: 43,
gauge.response.dump.root: 89,
gauge.response.env: 21,
gauge.response.env.name:.-star-: 14,
gauge.response.env.root: 17,
gauge.response.health: 19,
gauge.response.info: 5,
gauge.response.mappings: 13,
gauge.response.trace: 52
}
  • 系统内存总量(mem),单位:Kb
  • 空闲内存数量(mem.free),单位:Kb
  • 处理器数量(processors)
  • 系统正常运行时间(uptime),单位:毫秒
  • 应用上下文(就是一个应用实例)正常运行时间(instance.uptime),单位:毫秒
  • 系统平均负载(systemload.average)
  • 堆信息(heap,heap.committed,heap.init,heap.used),单位:Kb
  • 线程信息(threads,thread.peak,thead.daemon)
  • 类加载信息(classes,classes.loaded,classes.unloaded)
  • 垃圾收集信息(gc.xxx.count, gc.xxx.time)
  • 最大连接数(datasource.xxx.max)
  • 最小连接数(datasource.xxx.min)
  • 活动连接数(datasource.xxx.active)
  • 连接池的使用情况(datasource.xxx.usage)

也可以使用 /metrics/{name:.*} 访问单个属性。

dump

/dump执行一个线程转储,这是一个例子。

[
{
threadName: "http-nio-7231-exec-10",
threadId: 32,
blockedTime: -1,
blockedCount: 0,
waitedTime: -1,
waitedCount: 3,
lockName: "java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject@7cf8ed03",
lockOwnerId: -1,
lockOwnerName: null,
inNative: false,
suspended: false,
threadState: "WAITING",
stackTrace: [
{
methodName: "park",
fileName: null,
lineNumber: -2,
className: "sun.misc.Unsafe",
nativeMethod: true
}, ...

mappings

/mappings显示一个所有@RequestMapping路径的整理列表,一切尽在眼中。

{
/webjars/**: {
bean: "resourceHandlerMapping"
},
/**: {
bean: "resourceHandlerMapping"
},
/**/favicon.ico: {
bean: "faviconHandlerMapping"
},
{[/mappings],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: {
bean: "endpointHandlerMapping",
method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
},
{[/info],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: {
bean: "endpointHandlerMapping",
method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
},
{[/env/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: {
bean: "endpointHandlerMapping",
method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)"
},
{[/env],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: {
bean: "endpointHandlerMapping",
method: "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
}, ...

autoconfig

autoconfig显示一个auto-configuration的报告,该报告展示所有auto-configuration候选者及它们被应用或未被应用的原因

{
positiveMatches: {
AuditAutoConfiguration.AuditEventRepositoryConfiguration: [
{
condition: "OnBeanCondition",
message: "@ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.AuditEventRepository; SearchStrategy: all) found no beans"
}
],
EndpointAutoConfiguration#autoConfigurationAuditEndpoint: [
{
condition: "OnBeanCondition",
message: "@ConditionalOnBean (types: org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; SearchStrategy: all) found the following [autoConfigurationReport] @ConditionalOnMissingBean (types: org.springframework.boot.actuate.endpoint.AutoConfigurationReportEndpoint; SearchStrategy: current) found no beans"
}
], ...

configprops

/configprops显示一个所有@ConfigurationProperties的整理列表.

{
management.health.status.CONFIGURATION_PROPERTIES: {
prefix: "management.health.status",
properties: {
order: null
}
},
spring.datasource.CONFIGURATION_PROPERTIES: {
prefix: "spring.datasource",
properties: {
schema: null,
data: null,
xa: {
dataSourceClassName: null,
properties: { }
},
separator: ";",
url: "jdbc:sqlserver://192.168.x.x:xxxx;DatabaseName=xxxx;sendStringParametersAsUnicode=false",
platform: "all",
continueOnError: false,
jndiName: null,
sqlScriptEncoding: null,
password: "******",
driverClassName: "com.microsoft.sqlserver.jdbc.SQLServerDriver",
initialize: false,
username: "Monitor"
}
}, ...

spring boot监控--actuator的更多相关文章

  1. Spring Boot|监控-Actuator

    Spring Boot 为我们提供了一个生产级特性-Actuator,包含很多实际有用的API,下面我们就一起来看看这些API. 一.Actuator 首先在程序中引入Actuator <!-- ...

  2. Spring Boot整合actuator实现监控管理

    Spring Boot使用actuator监控管理 1.在pom文件中导入相关的依赖 <dependency> <groupId>org.springframework.boo ...

  3. Spring Boot (27) actuator服务监控与管理

    actuaotr是spring boot项目中非常强大的一个功能,有助于对应用程序进行监控和管理,通过restful api请求来监管.审计.收集应用的运行情况,针对微服务而言它是必不可少的一个环节. ...

  4. 笔记:Spring Boot 监控与管理

    在微服务架构中,我们将原本庞大的单体系统拆分为多个提供不同服务的应用,虽然,各个应用的内部逻辑因分解而简化,但由于部署的应用数量成倍增长,使得系统的维护复杂度大大提升,为了让运维系统能够获取各个为服务 ...

  5. Spring Boot 监控利器 —— Actutor

    参考 CSDN-学习Spring Boot:(二十七)Spring Boot 2.0 中使用 Actuator 使用Actuator监控Spring Boot应用 程序猿DD-Spring Boot ...

  6. Spring Boot 监控与管理

    在微服务架构中,我们将原本庞大的单体系统拆分为多个提供不同服务的应用,虽然,各个应用的内部逻辑因分解而简化,但由于部署的应用数量成倍增长,使得系统的维护复杂度大大提升,为了让运维系统能够获取各个为服务 ...

  7. 从Unauthorized 401错误学习Spring Boot的Actuator

    之前用Spring Boot都是别人搭好的框架,然后自己在里面写就行了.对原理.细节上都怎么涉及,毕竟需求都做不完.但是昨天一个访问RESTful接口的401问题搞了我2个小时.网上找的很多用: ma ...

  8. Spring Boot (28) actuator与spring-boot-admin

    在上一篇中,通过restful api的方式查看信息过于繁琐,也不直观,效率低下.当服务过多的时候看起来就过于麻烦,每个服务都需要调用不同的接口来查看监控信息. SBA SBA全称spring boo ...

  9. spring boot之actuator简介

    当我们的开发工作进入尾声,部署上线之后,对于一个程序而言,可能才刚刚开始,对程序的运行情况的监控要伴随着整个生命周期. 如果这个工作由程序员自己来开发,也未尝不可,但本着不重复制造轮子的思想,我们尽量 ...

随机推荐

  1. C# Winform开发以及控件开发的需要注意的,被人问怕了,都是基础常识

    我是搞控件开发的,经常被人问,所以把一些问题记录了下来!如果有人再问,直接把地址丢给他看. 一. 经常会有人抱怨Winform界面闪烁,下面有几个方法可以尽可能的避免出现闪烁 1.控件的使用尽量以纯色 ...

  2. sublime text 安装nodejs开发插件

    系统:windows10nodejs版本:v6.1.14 请先配置好环境变量,这里就不说啦. 下载并设置nodejs插件 下载地址为https://github.com/tanepiper/Subli ...

  3. 4.3 explain 之 type

    一.explain 的type类型 二.类型的排序 从最好到最差依次是: system > const > eq_ref > ref > range > index &g ...

  4. crontab命令行和日志查看

    1.基本命令行模式 注意:非root用户 systemctl restart crond 失效,请使用最底层的驱动重启 2.crontab日志 cron日志保存在系统目录/var/log/cron 命 ...

  5. 填一个laravel视图缓存没有及时更新的坑

    1.此坑背景 laravel在渲染blade模板后,会将渲染好的结果存到storage/framework/views(默认路径,也可在配置中修改的)中,以便下次使用.但我最近总是发现修改了blade ...

  6. 兼容浏览器的div透明

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. IE CSS Hack【记录】

    1.条件hack 2.属性hack 3.选择器hack CSS Hack一般都是利用各浏览器的支持CSS的能力和BUG来进行的 本文只列举了一些常用的CSS Hack,且不考虑IE6以下的版本 尽可能 ...

  8. vue从入门到进阶:组件Component详解(六)

    一.什么是组件? 组件 (Component) 是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊功 ...

  9. phpcms导航菜单的写法

    PHP打印方法: {php print_r(变量);} <?php print_r(变量);?> 1. <div class="webnav"> {pc:g ...

  10. [转]原生JS-查找相邻的元素-siblings方法的实现

    在针对element的操作里,查找附近的元素是一个不可少的过程,比如在实现tab时,其中的一个div增加了“on”class,其他的去除“on”class.如果用jquery的朋友就肯定不会陌生sib ...