天天看點

spring boot actuator 簡單使用 spring boot admin + spring boot actuator + erueka 微服務監控

spring boot admin + spring boot actuator + erueka 微服務監控

簡單的spring boot actuator 使用

POM

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

application.yml 這裡開啟了SpringSecurity保護,一般應用上,我們使用form作為使用者登入,如果需要監控程式,那麼我們會需要一個與應用業務無關的賬戶.可以設定一個賬戶角色為admin,随便什麼的,可以使用httpbasic驗證

#開啟shutdown的安全驗證
management:
  security:
    enabled: true
    roles: USER
#  port: 8060
#  address: 127.0.0.1
  health:
    mail:
      enabled: false
#允許關閉請求
endpoints:
  shutdown:
    enabled: false      

httpbasic驗證,密碼必須是經過basic64編碼,這是編碼,不是加密

spring boot actuator 簡單使用 spring boot admin + spring boot actuator + erueka 微服務監控

帶着請求頭去請求,傳回一大串資料

{
    "mem": 1289755,
    "mem.free": 954940,
    "processors": 4,
    "instance.uptime": 268073,
    "uptime": 286927,
    "systemload.average": -1,
    "heap.committed": 1188352,
    "heap.init": 391168,
    "heap.used": 233411,
    "heap": 5563392,
    "nonheap.committed": 103808,
    "nonheap.init": 2496,
    "nonheap.used": 101404,
    "nonheap": 0,
    "threads.peak": 64,
    "threads.daemon": 45,
    "threads.totalStarted": 151,
    "threads": 49,
    "classes": 13708,
    "classes.loaded": 13750,
    "classes.unloaded": 42,
    "gc.ps_scavenge.count": 17,
    "gc.ps_scavenge.time": 331,
    "gc.ps_marksweep.count": 3,
    "gc.ps_marksweep.time": 371,
    "counter.servo.eurekaclient.transport.request": 0,
    "gauge.servo.eurekaclient.registration.lastheartbeatsec_00015": 0,
    "gauge.servo.eurekaclient.registration.lastheartbeatsec_00030": 0,
    "normalized.servo.rest.totaltime": 1.6546110833333332,
    "normalized.servo.rest.count": 0.016666666666666666,
    "gauge.servo.rest.min": 99.276665,
    "gauge.servo.rest.max": 99.276665,
    "counter.servo.timeouts": 0,
    "counter.servo.rejectedexecutions": 0,
    "counter.servo.throwables": 0,
    "gauge.servo.threadpoolused": 0,
    "gauge.servo.eurekaclient.registry.lastupdatesec_00240": 0,
    "normalized.servo.eurekaclient.transport.latency.totaltime": 0,
    "normalized.servo.eurekaclient.transport.latency.count": 0,
    "gauge.servo.eurekaclient.transport.latency.min": 0,
    "gauge.servo.eurekaclient.transport.latency.max": 0,
    "gauge.servo.eurekaclient.registration.lastheartbeatsec_00480": 0,
    "gauge.servo.eurekaclient.transport.currentsessionduration": 261187,
    "gauge.servo.response.index": 158,
    "gauge.servo.eurekaclient.registry.lastupdatesec_00060": 0,
    "counter.servo.discoveryclient_reconcilehashcodemismatch": 0,
    "normalized.servo.discoveryclient_fetchregistry.totaltime": 0.42151759999999994,
    "normalized.servo.discoveryclient_fetchregistry.count": 0.03333333333333333,
    "gauge.servo.discoveryclient_fetchregistry.min": 9.916665,
    "gauge.servo.discoveryclient_fetchregistry.max": 15.374391,
    "counter.servo.discoveryclient_reregister": 0,
    "gauge.servo.eurekaclient.registration.lastsuccessfulheartbeattimeperiod": 471,
    "gauge.servo.eurekaclient.registry.lastsuccessfulregistryfetchtimeperiod": 20672,
    "gauge.servo.eurekaclient.registry.localregistrysize": 1,
    "gauge.servo.response.loginsuccess": 102,
    "gauge.servo.eurekaclient.resolver.lastloadtimestamp": 0,
    "gauge.servo.eurekaclient.resolver.endpointssize": 1,
    "counter.servo.eurekaclient.transport.connectionerrors": 0,
    "gauge.servo.response.dump": 387,
    "gauge.servo.response.mappings": 25,
    "gauge.servo.eurekaclient.registration.lastheartbeatsec_00120": 0,
    "gauge.servo.response.images.kaptcha.jpg": 22,
    "gauge.servo.response.invoice.invoiceinfo.tolist": 146,
    "gauge.servo.response.star-star": 24,
    "gauge.servo.eurekaclient.registration.lastheartbeatsec_00060": 0,
    "gauge.servo.eurekaclient.registration.lastheartbeatsec_00240": 0,
    "gauge.servo.response.root": 365,
    "gauge.servo.response.health": 1037,
    "gauge.servo.response.getloginerror": 25,
    "gauge.servo.eurekaclient.registry.lastupdatesec_00480": 0,
    "counter.servo.discoveryclient-httpclient_reuse": 27,
    "counter.servo.discoveryclient-httpclient_createnew": 9,
    "counter.servo.discoveryclient-httpclient_request": 36,
    "counter.servo.discoveryclient-httpclient_release": 36,
    "counter.servo.discoveryclient-httpclient_delete": 8,
    "normalized.servo.discoveryclient-httpclient_requestconnectiontimer.totaltime": 0.0035334999999999997,
    "normalized.servo.discoveryclient-httpclient_requestconnectiontimer.count": 0.13333333333333333,
    "gauge.servo.discoveryclient-httpclient_requestconnectiontimer.min": 0.016037,
    "gauge.servo.discoveryclient-httpclient_requestconnectiontimer.max": 0.050036,
    "normalized.servo.discoveryclient-httpclient_createconnectiontimer.totaltime": 0.0004543833333333333,
    "normalized.servo.discoveryclient-httpclient_createconnectiontimer.count": 0.03333333333333333,
    "gauge.servo.discoveryclient-httpclient_createconnectiontimer.min": 0.013470999999999999,
    "gauge.servo.discoveryclient-httpclient_createconnectiontimer.max": 0.013791999999999999,
    "gauge.servo.connectioncount": 1,
    "gauge.servo.eurekaclient.registry.lastupdatesec_00015": 1,
    "gauge.servo.eurekaclient.transport.quarantinesize": 0,
    "gauge.servo.response.unmapped": 270,
    "gauge.servo.response.invoice.invoiceinfo.list": 335,
    "gauge.servo.eurekaclient.registry.lastupdatesec_00120": 0,
    "normalized.servo.eureka-connection-cleaner-time.totaltime": 0.00047041666666666667,
    "normalized.servo.eureka-connection-cleaner-time.count": 0.03333333333333333,
    "gauge.servo.eureka-connection-cleaner-time.min": 0.012829,
    "gauge.servo.eureka-connection-cleaner-time.max": 0.015396,
    "counter.servo.eureka-connection-cleaner-failure": 0,
    "gauge.servo.eurekaclient.registry.lastupdatesec_00030": 0,
    "httpsessions.max": -1,
    "httpsessions.active": 0
}      
HTTP方法 路徑 描述 鑒權
GET /autoconfig 檢視自動配置的使用情況 true
/configprops 檢視配置屬性,包括預設配置
/beans 檢視bean及其關系清單
/dump 列印線程棧
/env 檢視所有環境變量
/env/{name} 檢視具體變量值
/health 檢視應用健康名額 false
/info 檢視應用資訊
/mappings 檢視所有url映射
/metrics 檢視應用基本名額
/metrics/{name} 檢視具體名額
POST /shutdown 關閉應用
/trace 檢視基本追蹤資訊

繼續閱讀