<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Spring Boot 應用可視化監(jiān)控,一目了然!

          共 2182字,需瀏覽 5分鐘

           ·

          2021-02-24 11:10

          1、Spring Boot 應用暴露監(jiān)控指標【版本 1.5.7.RELEASE】

          首先,添加依賴如下依賴:

          <dependency>???????
          ???<groupId>org.springframework.bootgroupId>?????
          ???<artifactId>spring-boot-starter-actuatorartifactId>??
          dependency>???

          采集應用的指標信息,我們使用的是prometheus,相應的我們引入包:

          <dependency>??????????
          ??<groupId>io.prometheusgroupId>????
          ??<artifactId>simpleclient_spring_bootartifactId>?????????????????????<version>0.0.26version>????
          dependency>

          然后,在啟動類?Application.java?添加如下注解:

          @SpringBootApplication
          @EnablePrometheusEndpoint
          @EnableSpringBootMetricsCollector
          public?class?Application?{??
          ????public?static?void?main(String[]?args)?{????????SpringApplication.run(Application.class,?args);?
          ?}
          }

          最后,配置默認的登錄賬號和密碼,在?application.yml?中:

          security:
          ??user:
          ????name:user
          ????password:?pwd

          啟動應用程序后,會看到如下一系列的?Mappings

          img

          利用賬號密碼訪問 http://localhost:8080/application/prometheus ,可以看到 Prometheus 格式的指標數據?


          2、Prometheus 采集 Spring Boot 指標數據

          首先,獲取 Prometheus 的 Docker 鏡像:

          $?docker?pull?prom/prometheus

          然后,編寫配置文件?prometheus.yml?:

          global:
          ??scrape_interval:?10s
          ??scrape_timeout:?10s
          ??evaluation_interval:?10m
          scrape_configs:
          ??-?job_name:?spring-boot
          ????scrape_interval:?5s
          ????scrape_timeout:?5s
          ????metrics_path:?/application/prometheus
          ????scheme:?http
          ????basic_auth:
          ??????username:?admin
          ??????password:?123456
          ????static_configs:
          ??????-?targets:
          ????????-?192.168.11.54:8099?#此處填寫?Spring?Boot?應用的?IP?+?端口號

          接著,啟動 Prometheus :

          docker?run?-d?--name?prometheus?-p?9090:9090
          -v?D:\test\actuator\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml?prom/prometheus

          請注意,D:\test\actuator\prometheus\prometheus.yml?,是我的配置文件存放地址,我們需要將它放到容器里面去,所以用了-v來做文件映射。/etc/prometheus/prometheus.yml這個是容器啟動的時候去取的默認配置,這里我是直接覆蓋掉了它。prom/prometheus這是鏡像,如果本地沒有,就回去你設置好的鏡像倉庫去取。

          啟動完成后用docker ps看下是否已經啟動成功,之后打開瀏覽器輸入:
          http://localhost:9090/targets,檢查 Spring Boot 采集狀態(tài)是否正常,如果看到下圖就是成功了。

          img

          3、Grafana 可視化監(jiān)控數據

          首先,獲取 Grafana 的 Docker 鏡像:

          $?docker?pull?grafana/grafana1

          然后,啟動 Grafana:

          $?docker?run?--name?grafana?-d?-p?3000:3000?grafana/grafana1

          接著,訪問 http://localhost:3000/ 配置 Prometheus 數據源:

          Grafana 登錄賬號 admin 密碼 admin

          1. 先配置數據源.

          img

          2.配置單個指標的可視化監(jiān)控面板:

          img

          img

          img

          prometh采集的數據

          img

          img

          PS:如果覺得我的分享不錯,歡迎大家隨手點贊、在看。

          END
          點擊下方卡片關注,訂閱更多精彩內容

          推薦閱讀:

          華為正式宣布養(yǎng)豬,網友沸騰:支持華為自救!

          API 面試四連殺:接口如何設計?安全如何保證?簽名如何實現?防重如何實現?

          Spring Boot 中引入 MyBatisPlus 的常規(guī)流程

          垃圾代碼和優(yōu)質代碼的區(qū)別?

          入職騰訊第九年,我辭職了


          瀏覽 68
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  狼人色综合 | 免费黄色成人网站在线观看 | 操操操操操操 | 伊人无码不卡电影网 | 成人性别视频影音先锋电影 |