Actuator監控:SpringBoot自帶的,對生成環境進行監控的系統css
使用:既然是監控,那就不能監控一個空項目html
這裏我使用SpringBoot整合MyBatis的Demo:前端
http://www.javashuo.com/article/p-cbakawcn-gk.htmlmysql
依賴web
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
而後直接啓動項目便可ajax
訪問http://localhost:8080/actuatorspring
{ "_links": { "self": { "href": "http://localhost:8080/actuator", "templated": false }, "health-component-instance": { "href": "http://localhost:8080/actuator/health/{component}/{instance}", "templated": true }, "health-component": { "href": "http://localhost:8080/actuator/health/{component}", "templated": true }, "health": { "href": "http://localhost:8080/actuator/health", "templated": false }, "info": { "href": "http://localhost:8080/actuator/info", "templated": false } } }
顯示可監控列表sql
訪問http://localhost:8080/actuator/health數據庫
{"status":"UP"}
說明狀態正常緩存
進一步地,使用Actuator獲取地JSON能夠寫前端頁面進行顯示,或者結合定時任務
好比定時訪問http://localhost:8080/actuator/health,若是返回UP說明正常,而後進行其餘操做
問題解決:訪問http://localhost:8080/actuator/health顯示404
緣由:SpringBoot版本問題,SpringBoot1.x訪問http://localhost:8080/health
其實這裏得到的是較少的信息,更多的信息須要進行配置:
management.endpoints.web.exposure.include=*
如今訪問:http://localhost:8080/actuator
{ "_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": { "href": "http://localhost:8080/actuator/health", "templated": false }, "health-component-instance": { "href": "http://localhost:8080/actuator/health/{component}/{instance}", "templated": true }, "health-component": { "href": "http://localhost:8080/actuator/health/{component}", "templated": true }, "conditions": { "href": "http://localhost:8080/actuator/conditions", "templated": false }, "configprops": { "href": "http://localhost:8080/actuator/configprops", "templated": false }, "env": { "href": "http://localhost:8080/actuator/env", "templated": false }, "env-toMatch": { "href": "http://localhost:8080/actuator/env/{toMatch}", "templated": true }, "info": { "href": "http://localhost:8080/actuator/info", "templated": false }, "loggers": { "href": "http://localhost:8080/actuator/loggers", "templated": false }, "loggers-name": { "href": "http://localhost:8080/actuator/loggers/{name}", "templated": true }, "heapdump": { "href": "http://localhost:8080/actuator/heapdump", "templated": false }, "threaddump": { "href": "http://localhost:8080/actuator/threaddump", "templated": false }, "metrics-requiredMetricName": { "href": "http://localhost:8080/actuator/metrics/{requiredMetricName}", "templated": true }, "metrics": { "href": "http://localhost:8080/actuator/metrics", "templated": false }, "scheduledtasks": { "href": "http://localhost:8080/actuator/scheduledtasks", "templated": false }, "httptrace": { "href": "http://localhost:8080/actuator/httptrace", "templated": false }, "mappings": { "href": "http://localhost:8080/actuator/mappings", "templated": false } } }
訪問:http://localhost:8080/actuator/env
得到配置信息
訪問:http://localhost:8080/actuator/beans
監控項目Spring中的beans
訪問:http://localhost:8080/actuator/metrics
查看應用基本指標列表
一般不建議所有開啓,由於不安全
因此,能夠這樣配置
#開啓所有 management.endpoints.web.exposure.include=* #開啓某個 management.endpoints.web.exposure.include=metrics #關閉某個 management.endpoints.web.exposure.exclude=metrics
SpringBoot的學習暫時結束了:
總結和將來規劃:
學會了基本的配置、整合Mybatis、Redis、ActiveMQ、ElasticSearch等
技術棧的規劃:
初級路線:Java基礎->Java Web(html+css+js,servlet,request+response,ajax,mysql+jdbc...)->SSM、SSH->SpringBoot->Spring Cloud
高級路線:Linux->源碼閱讀(Spring、JDK)->數據庫優化(分庫分表,慢查詢,調優...)->緩存(Redis集羣...)->HTTP/HTTPS協議優化
->安全(XSS、DDOS、CSRF)->消息隊列(ActiveMQ,Kafka,RocketMQ)->搜索框架(Lucene、Solr、ElasticSearch)->Docker、K8S
下面開始Spring Cloud的學習!