springboot actuator 监控

springboot1.5和springboot2.0 的actuator在启动日志上的差异就很大了.

springboot1.5在启动时会打印很多/XXX路径信息表示已暴露这些监控接口了, 而2.0是不一样的,2.0关闭了默认打印, 只能在trace日志级别查看,需要在application.yml中配置如下才可以正常输出web映射路径

logging:
level:
web: trace
2019-05-31 13:33:52.522  INFO 30044 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-05-31 13:33:52.523 INFO 30044 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-05-31 13:33:52.548 INFO 30044 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-05-31 13:33:52.548 INFO 30044 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-05-31 13:33:52.579 INFO 30044 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-05-31 13:33:52.800 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.800 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.801 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/health || /health.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(javax.servlet.http.HttpServletRequest,java.security.Principal)
2019-05-31 13:33:52.801 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2019-05-31 13:33:52.802 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.802 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2019-05-31 13:33:52.802 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env || /env.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.803 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.804 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/auditevents || /auditevents.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public org.springframework.http.ResponseEntity<?> org.springframework.boot.actuate.endpoint.mvc.AuditEventsMvcEndpoint.findByPrincipalAndAfterAndType(java.lang.String,java.util.Date,java.lang.String)
2019-05-31 13:33:52.806 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.get(java.lang.String)
2019-05-31 13:33:52.807 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers/{name:.*}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v1+json || application/json],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.LoggersMvcEndpoint.set(java.lang.String,java.util.Map<java.lang.String, java.lang.String>)
2019-05-31 13:33:52.807 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/loggers || /loggers.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.807 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.807 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.808 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2019-05-31 13:33:52.808 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2019-05-31 13:33:52.809 INFO 30044 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()

springboot中使用actuator

pom.xml

        <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

引完后直接启动即可.

默认访问大部分接口时是需要权限的 , 只有访问http://localhost:8080/info不需要, 为了研究方便, 可以暂时在application.properties中关闭权限管理

management.security.enabled=false

主要暴露的功能

HTTP方法 http监控端点(路径) 描述 鉴权
GET /autoconfig 查看自动配置的使用情况 true
GET /configprops 查看配置属性,包括默认配置 true
GET /beans 查看bean及其关系列表 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

/autoconfig

{
"positiveMatches": {
"AuditAutoConfiguration.AuditEventRepositoryConfiguration": [
{
"condition": "OnBeanCondition",
"message": "@ConditionalOnMissingBean (types: org.springframework.boot.actuate.audit.AuditEventRepository; SearchStrategy: all) found no beans"
}
]
},
"negativeMatches": {
"CacheStatisticsAutoConfiguration": [
{
"condition": "OnBeanCondition",
"message": "@ConditionalOnBean (types: org.springframework.cache.CacheManager; SearchStrategy: all) found no beans"
}
]
}
}

/configprops

{
"management.health.status.CONFIGURATION_PROPERTIES": {
"prefix": "management.health.status",
"properties": {
"order": null
}
},
"multipart.CONFIGURATION_PROPERTIES": {
"prefix": "multipart",
"properties": {
"enabled": false,
"maxRequestSize": "10Mb",
"location": null,
"fileSizeThreshold": "0",
"maxFileSize": "1Mb"
}
},
"environmentEndpoint": {
"prefix": "endpoints.env",
"properties": {
"id": "env",
"enabled": true,
"sensitive": true
}
}
}

/beans

[
{
"context": "application:8080",
"parent": null,
"beans": [
{
"bean": "appMain",
"scope": "singleton",
"type": "com.xixicat.AppMain$$EnhancerBySpringCGLIB$$29382b14",
"resource": "null",
"dependencies": [ ]
},
{
"bean": "videoInfoMapper",
"scope": "singleton",
"type": "com.xixicat.dao.VideoInfoMapper",
"resource": "file [/Users/xixicat/workspace/video-uber/target/classes/com/xixicat/dao/VideoInfoMapper.class]",
"dependencies": [
"sqlSessionFactory"
]
}
]
}
]

/dump

[
{
"threadName": "Signal Dispatcher",
"threadId": 4,
"blockedTime": -1,
"blockedCount": 0,
"waitedTime": -1,
"waitedCount": 0,
"lockName": null,
"lockOwnerId": -1,
"lockOwnerName": null,
"inNative": false,
"suspended": false,
"threadState": "RUNNABLE",
"stackTrace": [ ],
"lockedMonitors": [ ],
"lockedSynchronizers": [ ],
"lockInfo": null
},
{
"threadName": "Reference Handler",
"threadId": 2,
"blockedTime": -1,
"blockedCount": 217,
"waitedTime": -1,
"waitedCount": 9,
"lockName": "java.lang.ref.Reference$Lock@45de945",
"lockOwnerId": -1,
"lockOwnerName": null,
"inNative": false,
"suspended": false,
"threadState": "WAITING",
"stackTrace": [
{
"methodName": "wait",
"fileName": "Object.java",
"lineNumber": -2,
"className": "java.lang.Object",
"nativeMethod": true
},
{
"methodName": "wait",
"fileName": "Object.java",
"lineNumber": 503,
"className": "java.lang.Object",
"nativeMethod": false
},
{
"methodName": "run",
"fileName": "Reference.java",
"lineNumber": 133,
"className": "java.lang.ref.Reference$ReferenceHandler",
"nativeMethod": false
}
],
"lockedMonitors": [ ],
"lockedSynchronizers": [ ],
"lockInfo": {
"className": "java.lang.ref.Reference$Lock",
"identityHashCode": 73263429
}
}
]

/env

{
profiles: [],
server.ports: {
local.server.port: 8080
},
servletContextInitParams: {},
systemProperties: {
java.runtime.name: "Java(TM) SE Runtime Environment",
sun.boot.library.path: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib",
java.vm.version: "24.79-b02",
gopherProxySet: "false",
maven.multiModuleProjectDirectory: "/Users/xixicat/workspace/video-uber",
java.vm.vendor: "Oracle Corporation",
java.vendor.url: "http://java.oracle.com/",
guice.disable.misplaced.annotation.check: "true",
path.separator: ":",
java.vm.name: "Java HotSpot(TM) 64-Bit Server VM",
file.encoding.pkg: "sun.io",
user.country: "CN",
sun.java.launcher: "SUN_STANDARD",
sun.os.patch.level: "unknown",
PID: "763",
java.vm.specification.name: "Java Virtual Machine Specification",
user.dir: "/Users/xixicat/workspace/video-uber",
java.runtime.version: "1.7.0_79-b15",
java.awt.graphicsenv: "sun.awt.CGraphicsEnvironment",
java.endorsed.dirs: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/endorsed",
os.arch: "x86_64",
java.io.tmpdir: "/var/folders/tl/xkf4nr61033gd6lk5d3llz080000gn/T/",
line.separator: " ",
java.vm.specification.vendor: "Oracle Corporation",
os.name: "Mac OS X",
classworlds.conf: "/Users/xixicat/devtool/maven-3.3.3/bin/m2.conf",
sun.jnu.encoding: "UTF-8",
spring.beaninfo.ignore: "true",
java.library.path: "/Users/xixicat/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.",
java.specification.name: "Java Platform API Specification",
java.class.version: "51.0",
sun.management.compiler: "HotSpot 64-Bit Tiered Compilers",
os.version: "10.10.5",
user.home: "/Users/xixicat",
user.timezone: "Asia/Shanghai",
java.awt.printerjob: "sun.lwawt.macosx.CPrinterJob",
file.encoding: "UTF-8",
java.specification.version: "1.7",
java.class.path: "/Users/xixicat/devtool/maven-3.3.3/boot/plexus-classworlds-2.5.2.jar",
user.name: "xixicat",
java.vm.specification.version: "1.7",
sun.java.command: "org.codehaus.plexus.classworlds.launcher.Launcher spring-boot:run",
java.home: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre",
sun.arch.data.model: "64",
user.language: "zh",
java.specification.vendor: "Oracle Corporation",
awt.toolkit: "sun.lwawt.macosx.LWCToolkit",
java.vm.info: "mixed mode",
java.version: "1.7.0_79",
java.ext.dirs: "/Users/xixicat/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java",
sun.boot.class.path: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre/classes",
java.awt.headless: "true",
java.vendor: "Oracle Corporation",
maven.home: "/Users/xixicat/devtool/maven-3.3.3",
file.separator: "/",
LOG_EXCEPTION_CONVERSION_WORD: "%wEx",
java.vendor.url.bug: "http://bugreport.sun.com/bugreport/",
sun.io.unicode.encoding: "UnicodeBig",
sun.cpu.endian: "little",
sun.cpu.isalist: ""
},
systemEnvironment: {
TERM: "xterm-256color",
ZSH: "/Users/xixicat/.oh-my-zsh",
GVM_BROKER_SERVICE: "http://release.gvm.io",
GRIFFON_HOME: "/Users/xixicat/.gvm/griffon/current",
JAVA_MAIN_CLASS_763: "org.codehaus.plexus.classworlds.launcher.Launcher",
JAVA_HOME: "/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home",
SHLVL: "1",
MAVEN_CMD_LINE_ARGS: " spring-boot:run",
__CF_USER_TEXT_ENCODING: "0x1F5:0x19:0x34",
GROOVY_HOME: "/Users/xixicat/.gvm/groovy/current",
XPC_FLAGS: "0x0",
GVM_INIT: "true",
JBAKE_HOME: "/Users/xixicat/.gvm/jbake/current",
PWD: "/Users/xixicat/workspace/video-uber",
GVM_DIR: "/Users/xixicat/.gvm",
GVM_VERSION: "2.4.3",
MAVEN_PROJECTBASEDIR: "/Users/xixicat/workspace/video-uber",
LOGNAME: "xixicat",
SSH_AUTH_SOCK: "/private/tmp/com.apple.launchd.93xr1duECQ/Listeners",
SPRINGBOOT_HOME: "/Users/xixicat/.gvm/springboot/current",
GAIDEN_HOME: "/Users/xixicat/.gvm/gaiden/current",
LAZYBONES_HOME: "/Users/xixicat/.gvm/lazybones/current",
OLDPWD: "/Users/xixicat/workspace/video-uber",
SHELL: "/bin/zsh",
JBOSSFORGE_HOME: "/Users/xixicat/.gvm/jbossforge/current",
LC_CTYPE: "zh_CN.UTF-8",
TMPDIR: "/var/folders/tl/xkf4nr61033gd6lk5d3llz080000gn/T/",
GVM_SERVICE: "http://api.gvmtool.net",
GVM_PLATFORM: "Darwin",
CLASSPATH: ".:/Users/xixicat/.m2/repository/co/paralleluniverse/quasar-core/0.7.2/quasar-core-0.7.2.jar",
GLIDE_HOME: "/Users/xixicat/.gvm/glide/current",
PATH: "/Users/xixicat/.gvm/vertx/current/bin:/Users/xixicat/.gvm/springboot/current/bin:/Users/xixicat/.gvm/lazybones/current/bin:/Users/xixicat/.gvm/jbossforge/current/bin:/Users/xixicat/.gvm/jbake/current/bin:/Users/xixicat/.gvm/groovyserv/current/bin:/Users/xixicat/.gvm/groovy/current/bin:/Users/xixicat/.gvm/griffon/current/bin:/Users/xixicat/.gvm/grails/current/bin:/Users/xixicat/.gvm/gradle/current/bin:/Users/xixicat/.gvm/glide/current/bin:/Users/xixicat/.gvm/gaiden/current/bin:/Users/xixicat/.gvm/crash/current/bin:/Users/xixicat/.gvm/asciidoctorj/current/bin:/Users/xixicat/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin:/Users/xixicat/devtool/maven-3.3.3/bin:/Users/xixicat/devtool/gradle-2.6/bin:/Users/xixicat/devtool/android-sdk/platform-tools",
GRADLE_HOME: "/Users/xixicat/.gvm/gradle/current",
GROOVYSERV_HOME: "/Users/xixicat/.gvm/groovyserv/current",
GRAILS_HOME: "/Users/xixicat/.gvm/grails/current",
USER: "xixicat",
LESS: "-R",
PAGER: "less",
HOME: "/Users/xixicat",
CRASH_HOME: "/Users/xixicat/.gvm/crash/current",
XPC_SERVICE_NAME: "0",
VERTX_HOME: "/Users/xixicat/.gvm/vertx/current",
GVM_BROADCAST_SERVICE: "http://cast.gvm.io",
Apple_PubSub_Socket_Render: "/private/tmp/com.apple.launchd.y6fNwP8Sk6/Render",
LSCOLORS: "Gxfxcxdxbxegedabagacad",
ASCIIDOCTORJ_HOME: "/Users/xixicat/.gvm/asciidoctorj/current"
},
applicationConfig: [classpath: /application.properties]: {
pool.acquireIncrement: "1",
pool.minPoolSize: "5",
pool.initialPoolSize: "1",
database.username: "root",
pool.maxIdleTime: "60",
database.url: "jdbc:mysql://127.0.0.1:3307/video_uber?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull",
spring.jackson.dateFormat: "yyyy-MM-dd'T'HH:mm:ss",
database.slave.username: "root",
spring.jackson.serialization.write - dates - as - timestamps: "false",
pool.idleTimeout: "30000",
database.slave.url: "jdbc:mysql://127.0.0.1:3307/demo?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull",
server.port: "8080",
database.slave.password: "******",
database.password: "******",
database.driverClassName: "com.mysql.jdbc.Driver",
pool.maxPoolSize: "50",
database.dataSourceClassName: "com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
}
}

/health

{
status: "UP",
diskSpace: {
status: "UP",
total: 249779191808,
free: 193741590528,
threshold: 10485760
},
db: {
status: "UP",
database: "MySQL",
hello: 1
}
}

/info

需要自己在application.properties里头添加信息,比如

info:
contact:
email: xixicat@gmail.com
phone: 0755-82890987

然后请求就可以出来了

{
"contact": {
"phone": "0755-82890987",
"email": "xixicat@gmail.com"
}
}

/mappings

仅展示部分

{
"/webjars/**": {
"bean": "resourceHandlerMapping"
},
"/**": {
"bean": "resourceHandlerMapping"
},
"/**/favicon.ico": {
"bean": "faviconHandlerMapping"
},
"{[/ticket],methods=[GET]}": {
"bean": "requestMappingHandlerMapping",
"method": "public com.example.simple.bean.Ticket com.example.starterdemo.controller.TicketController.getDefaultTicket(java.lang.String)"
},
"{[/error]}": {
"bean": "requestMappingHandlerMapping",
"method": "public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)"
},
"{[/error],produces=[text/html]}": {
"bean": "requestMappingHandlerMapping",
"method": "public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)"
},
"{[/configprops || /configprops.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
"bean": "endpointHandlerMapping",
"method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
},
"{[/info || /info.json],methods=[GET],produces=[application/vnd.spring-boot.actuator.v1+json || application/json]}": {
"bean": "endpointHandlerMapping",
"method": "public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()"
} }

resourceHandlerMapping 位于org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#resourceHandlerMapping   Bean声明中

/metrics

{
mem: 499404,
mem.free: 257591,
processors: 8,
instance.uptime: 4284997,
uptime: 4294909,
systemload.average: 1.84521484375,
heap.committed: 437248,
heap.init: 262144,
heap.used: 179656,
heap: 3728384,
nonheap.committed: 62848,
nonheap.init: 24000,
nonheap.used: 62156,
nonheap: 133120,
threads.peak: 18,
threads.daemon: 6,
threads.totalStarted: 176,
threads: 16,
classes: 10294,
classes.loaded: 10294,
classes.unloaded: 0,
gc.ps_scavenge.count: 11,
gc.ps_scavenge.time: 405,
gc.ps_marksweep.count: 0,
gc.ps_marksweep.time: 0,
datasource.primary.active: 0,
datasource.primary.usage: 0,
counter.status.200.autoconfig: 1,
counter.status.200.beans: 1,
counter.status.200.configprops: 1,
counter.status.200.dump: 1,
counter.status.200.env: 1,
counter.status.200.health: 1,
counter.status.200.info: 1,
counter.status.200.mappings: 1,
gauge.response.autoconfig: 81,
gauge.response.beans: 15,
gauge.response.configprops: 105,
gauge.response.dump: 76,
gauge.response.env: 4,
gauge.response.health: 43,
gauge.response.info: 1,
gauge.response.mappings: 4
}

/shutdown

要真正生效,得配置文件开启

endpoints.shutdown.enabled: true

/trace

记录最近100个请求的信息

[{
"timestamp": 1452955704922,
"info": {
"method": "GET",
"path": "/metrics",
"headers": {
"request": {
"Accept - Encoding": "gzip, deflate, sdch",
"Upgrade - Insecure - Requests": "1",
"Accept - Language": "zh-CN,zh;q=0.8,en;q=0.6",
"User - Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Connection": "keep-alive",
"Host": "localhost:8080"
},
"response": {
"Content - Type": "application/json; charset=UTF-8",
"X - Application - Context": "application:8080",
"Date": "Sat, 16 Jan 2016 14:48:24 GMT",
"status": "200"
}
}
}
}, {
"timestamp": 1452951489549,
"info": {
"method": "GET",
"path": "/autoconfig",
"headers": {
"request": {
"Accept - Encoding": "gzip, deflate, sdch",
"Upgrade - Insecure - Requests": "1",
"Accept - Language": "zh-CN,zh;q=0.8,en;q=0.6",
"User - Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Connection": "keep-alive",
"Host": "localhost:8080"
},
"response": {
"Content - Type": "application/json; charset=UTF-8",
"X - Application - Context": "application:8080",
"Date": "Sat, 16 Jan 2016 13:38:09 GMT",
"status": "200"
}
}
}
}]

修改监控属性

server.port=8080

#禁用监控端口的安全认证
management.security.enabled=false #用于/info的监控访问
info.app.id=appid1
info.app.name=boboapp #还能使用git.properties 以git.开头的属性, 暂未研究 git.xxx.xxx=yyy #自定义/beans监控端点的名称,如果没有手动指明endpoints.beans.path则访问路径默认等于id同名路径
endpoints.beans.id=mybeans
#指定beans监控端点的访问路径成/my-beans, 所以不能通过/beans或/mybeans来访问了
endpoints.beans.path=my-beans #关闭所有端点
#endpoints.enabled=false #开启某个端点,它的优先级高于endpoints.enabled
endpoints.beans.enabled=true #定制所有端点的访问根路径,最好是指定访问根路径,然后用security进行权限控制
management.context-path=/endpoints
#再起一个额外端口来使用监控管理功能,这时需要使用http://localhost:18080/endpoints/my-beans来访问端点,如果port=-1代表禁用管理端点
management.port=18080 #当在pom.xml中引入redis和actuator之后, 使用http://localhost:18080/endpoints/health,将能看到redis状态
spring.redis.host=localhost

在本地redis未启动时访问http://localhost:18080/endpoints/health

{
"status": "DOWN",
"diskSpace": {
"status": "UP",
"total": 520721788928,
"free": 254064136192,
"threshold": 10485760
},
"redis": {
"status": "DOWN",
"error": "org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool"
}
}

在本地redis启动时,访问 http://localhost:18080/endpoints/health 得到正常状态

{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 520721788928,
"free": 254064136192,
"threshold": 10485760
},
"redis": {
"status": "UP",
"version": "3.2.100"
}
}

自定义监控

默认指示器都在spring-boot-actuator-1.5.21.RELEASE.jar包下, 如RedisHealthIndicator

要自定义指示器只需要添加一个HealthIndicator接口的实现类即可, 并返回Health对象

package com.example.actuator.indicator;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component; @Component
public class MyAppHealthIndicator implements HealthIndicator { @Override
public Health health() {
int num = 1;
if( 1 == num ){
return Health.up().build();
}else{
return Health.down().withDetail("errorMessage","xx接口服务异常中").build();
}
}
}

此时访问 http://localhost:18080/endpoints/health 能看到myapp属性如下

{
"status": "UP",
"myApp": {
"status": "UP"
},
"diskSpace": {
"status": "UP",
"total": 520721788928,
"free": 254064111616,
"threshold": 10485760
},
"redis": {
"status": "UP",
"version": "3.2.100"
}
}

springboot2差异

在springboot2中

根路径/变成了/actuator

#actuator端口
management.server.port=9001
#修改访问路径 2.0之前默认是/ 2.0默认是 /actuator 可以通过这个属性值修改
management.endpoints.web.base-path=/monitor
#开放所有页面节点 默认只开启了health、info两个节点
management.endpoints.web.exposure.include=*
#显示健康具体信息 默认不会显示详细信息
management.endpoint.health.show-details=always

参考

 

我的git项目地址

https://gitee.com/KingBoBo/springboot-08-actuator

SpringBoot Actuator监控【转】的更多相关文章

  1. 使用springboot actuator监控应用

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...

  2. springBoot actuator监控配置及使用

    准备环境: 一个springBoot工程 第一步:添加以下依赖 <dependency> <groupId>org.springframework.boot</group ...

  3. springboot actuator监控笔记

    0 环境 系统:win10 编辑器:IDEA 1 概念 监控 管理自身信息(可以自定义) 的模块 2 文件配置 1 pom的配置 监控的添加 <dependency> <groupI ...

  4. Spring Boot Actuator监控使用详解

    在企业级应用中,学习了如何进行SpringBoot应用的功能开发,以及如何写单元测试.集成测试等还是不够的.在实际的软件开发中还需要:应用程序的监控和管理.SpringBoot的Actuator模块实 ...

  5. springboot actuator 配置安全

    springboot actuator监控是什么?类似php的phpinfor()函数,不过actuator更强大,可以查看的数据.状态更多.Actuator是Spring Boot提供的对应用系统的 ...

  6. SpringBoot系列: Actuator监控

    Sprng Boot 2 actuator变动加大, 网上很多资料都都已经过期. ============================配置项============================ ...

  7. 【spring cloud】【spring boot】网管服务-->配置文件添加endpoints.enabled = false,SpringBoot应用监控Actuator使用的安全隐患

    转载:https://xz.aliyun.com/t/2233 ==================================================================== ...

  8. SpringBoot actuator 应用监控。

    前言 : 今天在阅读 <SpringCloud微服务实战>一书时看到了SpringBoot actuator相关知识,并且自己也本地调试实践.觉得SpringBoot这一套监控还是挺有意思 ...

  9. SpringBoot系列九:SpringBoot服务整合(整合邮件服务、定时调度、Actuator监控)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 服务整合 2.背景 在进行项目开发的时候经常会遇见以下的几个问题:需要进行邮件发送.定时的任务调 ...

随机推荐

  1. 关于mysql8授权的问题,mysql萌新小白采坑记录

    记录本人第一次使用mysql时踩的坑,因为我从官网下载最新的版本8.0.15msi版本的,直接下一步下一步安装完成之后,本地访问正常,然后服务器安装访问也正常.然后本地连接服务器上的mysql时报错. ...

  2. PAT甲级——A1060 Are They Equal

    If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered ...

  3. MR过程解析(转自about云)

     图中1:表示待处理数据,比如日志,比如单词计数图中2:表示map阶段,对他们split,然后送到不同分区图中3:表示reduce阶段,对这些数据整合处理.图中4:表示二次mapreduce,这个是m ...

  4. git(转)

    转载:http://www.cnblogs.com/my-freedom/p/5701427.html 一.如何安装git 下载地址: https://git-scm.com/download/win ...

  5. bootstrap--栅格系统布局

    栅格布局使用例子: <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset=&q ...

  6. 读书笔记--Head First JQuery目录

    1.JQuery入门 2.选择器与方法 3.JQuery事件与函数 4.JQuery Web页面管理 5.JQuery效果与动画 6.JQuery与JavaScript 7.定制函数停工定制效果 8. ...

  7. What every computer science major should know 每一个计算机科学专业的毕业生都应该都知道的

    Given the expansive growth in the field, it's become challenging to discern what belongs in a modern ...

  8. PYTHON网络爬虫与信息提取[信息的组织与提取](单元五)

    1 三种信息类型的简介 xml : extensible markup language 与html非常相似 现有html后有xml xml是html发展来的 扩展 通用 json  类型 javas ...

  9. win10 ubuntu 双系统启动顺序设置

    之前安装ubuntu的时候就遇到过这个问题, 当时解决了,设置成开始可以选择启动ubuntu系统还是win系统. 但是过了好久后又忘记了,最近win10开了一次安全模式启动后,一开机就是win10,u ...

  10. 洛谷P1966 [NOIP2013提高组Day1T2]火柴排队

    P1966 火柴排队 题目描述 涵涵有两盒火柴,每盒装有 n 根火柴,每根火柴都有一个高度. 现在将每盒中的火柴各自排成一列, 同一列火柴的高度互不相同, 两列火柴之间的距离定义为: ∑(ai-bi) ...