原文地址: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. Echarts图表legend的排版问题(转载)

    来源:https://blog.csdn.net/david_jiahuan/article/details/80096922 案例一 项目中现有样式: 客户需求:将图例分为两列,并且上下两列的图例要 ...

  2. Linux-bg和fg命令(19)

    使用ctrl+z将程序挂在后台: jobs 查看后台的命令: fg(fore go) 将后台的命令,放置前台(fore)继续执行,比如:fg 2     //等价于vi 2.txt bg(back g ...

  3. mybatis笔记01

    目录 1. Mybatis的介绍 2. 使用JDBC编码的分析 2.1 准备 2.3 程序代码 2.4 JDBC问题 3. Mybatis架构 4. Mybatis入门程序 4.1 mybatis下载 ...

  4. ANOVA (paper from the onlinestat)

    Introduction Author(s) David M. Lane Prerequisites Variance, Significance Testing,All Pairwise Compa ...

  5. Docker 系列七(Dubbo 微服务部署实践).

    一.前言 之前我们公司部署服务,就是大家都懂的那一套(安装JDK.Tomcat —> 编译好文件或者打war包上传 —> 启动Tomcat),这种部署方式一直持续了很久,带来的问题也很多: ...

  6. Java反射的简单入门

    1.Class的简单介绍 Class类的类表示正在运行的Java应用程序中的类和接口. 枚举是一种类,一个注解是一种接口, 每个数组也属于一个反映为类对象的类,该对象由具有相同元素类型和维数的所有数组 ...

  7. jfinal中excel表格导出

    今天工作中遇到了excel表格导出的操作,还好有写好的模板,不然我也是焦头烂额,下面记录一下excel表格导出的操作步骤,同时用来给正在学习jfinal的小伙伴一些参考和学习. 首先我们需要把表格查询 ...

  8. CSS3属性animation-play-state控制动画运行或暂停的技巧

    animation-play-state介绍 animation-play-state 属性规定动画正在运行还是暂停. div{ animation-play-state:paused; -webki ...

  9. 如何用ABP框架快速完成项目(2) - 快的定义!

    为什么要从快的角度来讲这系列课程呢?   因为快是一个很统一很清晰的标准. 所有人对时间都有一个统一清晰的概念.  比如说这系列课程会讲到的一个实例: 集成LinqToExcel, 用我的方法大概耗时 ...

  10. 网络控制器intel 82599, powerpc 830的BD描述符结构

    一.Intel 82599的BD结构 1.文档名称“82599-10-gbe-controller-datasheet.pdf”,可以从intel官网上下载. https://www.intel.cn ...