真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

跟我學(xué)SpringCloud(Finchley版)-03-監(jiān)控:強(qiáng)大的BootActuator

第2節(jié)( 跟我學(xué)Spring Cloud(Finchley版)-02-構(gòu)建分布式應(yīng)用 )說過:

創(chuàng)新互聯(lián)建站主要從事成都做網(wǎng)站、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)汪清,10年網(wǎng)站建設(shè)經(jīng)驗,價格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108

應(yīng)用沒有監(jiān)控,沒有畫板,一切指標(biāo)都沒有。在這個Growth Hack逐漸成為主流的時代,不弄個Dashboard把系統(tǒng)壓力、QPS、CPU、內(nèi)存、日活啥的可視化,你好意思出來混嗎……

本節(jié)我們來解決該問題。

Spring Boot Actuator是Spring Boot官方提供的監(jiān)控組件。只需為項目添加以下依賴,即可就整合Spring Boot Actuator。


  org.springframework.boot
  spring-boot-starter-actuator

監(jiān)控端點

Actuator為我們提供了很多監(jiān)控端點,如下表所示。

端點(Spring Boot 2.x)描述HTTP方法是否敏感端點(Spring Boot 1.x)
conditions 顯示自動配置的信息 GET autoconfig
beans 顯示應(yīng)用程序上下文所有的Spring bean GET beans
configprops 顯示所有@ConfigurationProperties的配置屬性列表 GET configprops
dump 顯示線程活動的快照 GET dump
env 顯示環(huán)境變量,包括系統(tǒng)環(huán)境變量以及應(yīng)用環(huán)境變量 GET env
health 顯示應(yīng)用程序的健康指標(biāo),值由HealthIndicator的實現(xiàn)類提供;結(jié)果有UP、 DOWN、OUT_OF_SERVICE、UNKNOWN;如需查看詳情,需配置:management.endpoint.health.show-details GET health
info 顯示應(yīng)用的信息,可使用info.* 屬性自定義info端點公開的數(shù)據(jù) GET info
mappings 顯示所有的URL路徑 GET mappings
metrics 顯示應(yīng)用的度量標(biāo)準(zhǔn)信息 GET metrics

表-Spring Boot Actuator常用端點及描述

只需訪問http://{ip}:{port}/actuator/{endpoint} 端點,即可監(jiān)控應(yīng)用的運行狀況。

測試1:/health端點

為前文編寫的microservice-simple-provider-user 服務(wù)整合Actuator后,我們來做一些測試:

訪問 ,即可獲得如下結(jié)果:

{"status":"UP"}

測試2:/health端點展示詳情

/health 端點配置顯示詳情:

management:
  endpoint:
    health:
      # 是否展示健康檢查詳情
      show-details: always

再次訪問 ,即可獲得如下結(jié)果:

{
    "status": "UP",
    "details": {
        "db": {
            "status": "UP",
            "details": {
                "database": "H2",
                "hello": 1
            }
        },
        "diskSpace": {
            "status": "UP",
            "details": {
                "total": 250790436864,
                "free": 43443773440,
                "threshold": 10485760
            }
        }
    }
}

從中可以看到,/health 端點展示了DB的健康情況以及磁盤的健康情況。

測試3:暴露敏感路徑

默認(rèn)情況下,敏感路徑并不暴露。如需暴露(以metrics為例),需添加配置:

management:
  endpoints:
    web:
      exposure:
        # 暴露metrics端點,如需暴露多個,用,分隔;如需暴露所有端點,用'*'
        include: metrics

訪問: ,可獲得類似如下的結(jié)果:

{
    "names": ["jvm.memory.max", "http.server.requests", "jdbc.connections.active", "process.files.max", "jvm.gc.memory.promoted", "tomcat.cache.hit", "system.load.average.1m", "tomcat.cache.access", "jvm.memory.used", "jvm.gc.max.data.size", "jdbc.connections.max", "jdbc.connections.min", "jvm.gc.pause", "jvm.memory.committed", "system.cpu.count", "logback.events", "tomcat.global.sent", "jvm.buffer.memory.used", "tomcat.sessions.created", "jvm.threads.daemon", "system.cpu.usage", "jvm.gc.memory.allocated", "tomcat.global.request.max", "hikaricp.connections.idle", "hikaricp.connections.pending", "tomcat.global.request", "tomcat.sessions.expired", "hikaricp.connections", "jvm.threads.live", "jvm.threads.peak", "tomcat.global.received", "hikaricp.connections.active", "hikaricp.connections.creation", "process.uptime", "tomcat.sessions.rejected", "process.cpu.usage", "tomcat.threads.config.max", "jvm.classes.loaded", "hikaricp.connections.max", "hikaricp.connections.min", "jvm.classes.unloaded", "tomcat.global.error", "tomcat.sessions.active.current", "tomcat.sessions.alive.max", "jvm.gc.live.data.size", "tomcat.servlet.request.max", "hikaricp.connections.usage", "tomcat.threads.current", "tomcat.servlet.request", "hikaricp.connections.timeout", "process.files.open", "jvm.buffer.count", "jvm.buffer.total.capacity", "tomcat.sessions.active.max", "hikaricp.connections.acquire", "tomcat.threads.busy", "process.start.time", "tomcat.servlet.error"]
}

訪問http://localhost:8000/actuator/metrics/{name} ,{name} 列表如上,即可查看當(dāng)前應(yīng)用的度量指標(biāo)。例如訪問: 即可查看JVM可管理的最大內(nèi)存,結(jié)果類似如下:

{
    "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.597298687E9
    }],
    "availableTags": [{
        "tag": "area",
        "values": ["heap", "nonheap"]
    }, {
        "tag": "id",
        "values": ["Compressed Class Space", "PS Survivor Space", "PS Old Gen", "Metaspace", "PS Eden Space", "Code Cache"]
    }]
}

TIPS

  • 如需暴露所有監(jiān)控端點可配置:

    management:
    endpoints:
      web:
        exposure:
          include: '*'
  • 有關(guān)Spring Boot 1.x與2.x端點的差異,詳見:

拓展閱讀

如果能對Actuator端點的文字?jǐn)?shù)據(jù)進(jìn)行圖形化的展示,我們就可以實現(xiàn)比較低層次的“Growth Hack”啦!開源界已經(jīng)有這樣的工具——Spring Boot Admin ,界面如下。有興趣的可前往了解。

跟我學(xué)Spring Cloud(Finchley版)-03-監(jiān)控:強(qiáng)大的Boot Actuator

說明

  • 由于Actuator本身是Spring Boot中的組件,并不是本套教程的重點(其實筆者本不想寫這一節(jié),但后面又會持續(xù)用這些端點,并且Spring Cloud在這些端點的基礎(chǔ)上還做了一些增加,所以還是有必要介紹一下),因此本節(jié)只是對Actuator進(jìn)行了比較簡單的介紹,讀者可自行挖掘Actuator的其他能力。也可持續(xù)關(guān)注本公眾號,本系列完成后,筆者將會扒開Actuator的底褲,深度介紹Spring Boot監(jiān)控的那些事兒。

配套代碼

GitHub:

  • https://github.com/eacdy/spring-cloud-study/tree/master/2018-Finchley/microservice-simple-provider-user
  • https://github.com/eacdy/spring-cloud-study/tree/master/2018-Finchley/microservice-simple-consumer-movie

Gitee:

  • https://gitee.com/itmuch/spring-cloud-study/tree/master/2018-Finchley/microservice-simple-provider-user
  • https://gitee.com/itmuch/spring-cloud-study/tree/master/2018-Finchley/microservice-simple-consumer-movie

原文:http://www.itmuch.com/spring-cloud/finchley-3/ ,轉(zhuǎn)載請說明出處。

干貨分享

跟我學(xué)Spring Cloud(Finchley版)-03-監(jiān)控:強(qiáng)大的Boot Actuator


本文名稱:跟我學(xué)SpringCloud(Finchley版)-03-監(jiān)控:強(qiáng)大的BootActuator
標(biāo)題來源:http://weahome.cn/article/iegheh.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部