actuator官方的介紹html
Spring Boot includes a number of additional features to help you monitor and manage your application when it’s pushed to production. You can choose to manage and monitor your application using HTTP endpoints, with JMX or even by remote shell (SSH or Telnet). Auditing, health and metrics gathering can be automatically applied to your application.java
actuator是一個強大功能,有助於對應用程序進行監視和管理,經過restful api
請求來監管、審計、收集應用的運行狀況web
1.添加依賴spring
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2.啓動項目shell
用瀏覽器打開 http://localhost:8080/actuatorapi
{ "_links": { "self": { "href": "http://localhost:8080/actuator", "templated": false }, "health": { "href": "http://localhost:8080/actuator/health", "templated": false }, "health-component": { "href": "http://localhost:8080/actuator/health/{component}", "templated": true }, "health-component-instance": { "href": "http://localhost:8080/actuator/health/{component}/{instance}", "templated": true }, "info": { "href": "http://localhost:8080/actuator/info", "templated": false } } }
actuator暴露了三個簡單的endpoint瀏覽器
開啓全部接口,在application.properties中,添加restful
management.endpoints.web.exposure.include=*
刷新 http://localhost:8080/actuator頁面,會出現不少endpointapp
{ "_links": { "self": { "href": "http://localhost:8080/actuator", "templated": false }, "auditevents": { "href": "http://localhost:8080/actuator/auditevents", "templated": false }, "beans": { "href": "http://localhost:8080/actuator/beans", "templated": false }, "caches-cache": { "href": "http://localhost:8080/actuator/caches/{cache}", "templated": true }, "caches": { "href": "http://localhost:8080/actuator/caches", "templated": false }, "health-component": { "href": "http://localhost:8080/actuator/health/{component}", "templated": true }, "health-component-instance": { "href": "http://localhost:8080/actuator/health/{component}/{instance}", "templated": true }, "health": { "href": "http://localhost:8080/actuator/health", "templated": false }, …… } }
(1)/actuator/health 查看應用健康指標dom
{ "status": "UP" }
(2)/actuator/info查看應用的定製信息
在配置文件中以 info 開頭的配置信息
application.properties包含
info.app.name=abc
info.app.version=1.0.0
返回結果
{ "app": { "name": "abc", "version": "1.0.0" } }
(3)/actuator/metrics 查看應用基本指標
返回actuator提供的全部metric的name
/actuator/metrics/{name}查看具體指標
使用 /actuator/metrics/jvm.memory.max,查看JVM最大內存
{ "name": "jvm.memory.max", "description": "The maximum amount of memory in bytes that can be used for memory management", "baseUnit": "bytes", "measurements": [ { "statistic": "VALUE", "value": 5.583142911E9 } ], "availableTags": [ { "tag": "area", "values": [ "heap", "nonheap" ] }, { "tag": "id", "values": [ "Compressed Class Space", "PS Survivor Space", "PS Old Gen", "Metaspace", "PS Eden Space", "Code Cache" ] } ] }
(4)/actuator/beans 應用中全部Spring Beans
的完整列表
"contexts": { "application": { "beans": { "spring.jpa-org.springframework.boot.autoconfigure.orm.jpa.JpaProperties": { "aliases": [], "scope": "singleton", "type": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties", "resource": null, "dependencies": [] },"uploadController": { "aliases": [], "scope": "singleton", "type": "com.example.demo.controller.UploadController$$EnhancerBySpringCGLIB$$b6fa2feb", "resource": "file [E:\\java\\demo\\target\\classes\\com\\example\\demo\\controller\\UploadController.class]", "dependencies": [] }, …… }, "parentId": null } } }
(5)/actuator/heapdump dump 一份應用的 JVM 堆信息
可使用 JDK 自帶的 Jvm 監控工具 VisualVM 打開該文件查看內存快照
(6)/actuator/scheduledtasks 應用中的定時任務信息
(7)/actuator/env 獲取所有環境屬性
/actuator/env/{name} 獲取特定的環境屬性值
/actuator/env/java.version java版本
{ "property": { "source": "systemProperties", "value": "1.8.0_151" }, "activeProfiles": [ "dev" ], "propertySources": [ { "name": "server.ports" }, { "name": "servletConfigInitParams" }, { "name": "servletContextInitParams" }, { "name": "systemProperties", "property": { "value": "1.8.0_151" } }, { "name": "systemEnvironment" }, { "name": "random" }, { "name": "applicationConfig: [classpath:/application.properties]" }, { "name": "Management Server" } ] }
還有不少,能夠去 https://docs.spring.io/spring-boot/docs/2.0.2.RELEASE/actuator-api/html/ 查看