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

        共 3647字,需瀏覽 8分鐘

         ·

        2021-06-11 20:17

        1、Spring Boot 應(yīng)用暴露監(jiān)控指標(biāo)

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

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

        采集應(yīng)用的指標(biāo)信息,我們使用的是prometheus,相應(yīng)的我們引入包:

        <dependency>          
           <groupId>io.prometheus</groupId>    
           <artifactId>simpleclient_spring_boot</artifactId>                       
           <version>0.0.26</version>    
        </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

        啟動應(yīng)用程序后,會看到如下一系列的 Mappings

        利用賬號密碼訪問 http://localhost:8080/application/prometheus ,可以看到 Prometheus 格式的指標(biāo)數(shù)據(jù):Spring Boot 學(xué)習(xí)筆記,分享給你看下。

        2、Prometheus 采集 Spring Boot 指標(biāo)數(shù)據(jù)

        首先,獲取 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 應(yīng)用的 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這是鏡像,如果本地沒有,就回去你設(shè)置好的鏡像倉庫去取。

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

        Spring Boot 基礎(chǔ)就不介紹了,最新的教程和示例源碼看這個:https://github.com/javastacks/spring-boot-best-practice

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

        首先,獲取 Grafana 的 Docker 鏡像:

        $ docker pull grafana/grafana1

        然后,啟動 Grafana:

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

        接著,訪問 http://localhost:3000/ 配置 Prometheus 數(shù)據(jù)源:

        Grafana 登錄賬號 admin 密碼 admin

        1. 先配置數(shù)據(jù)源.

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

        prometh采集的數(shù)據(jù):

        參考:https://www.jianshu.com/p/7ecb57a3f326
        原文:https://blog.csdn.net/weixin_44196699/article/details/105010045

        推薦閱讀:

        世界的真實格局分析,地球人類社會底層運行原理

        企業(yè)IT技術(shù)架構(gòu)規(guī)劃方案

        論數(shù)字化轉(zhuǎn)型——轉(zhuǎn)什么,如何轉(zhuǎn)?

        企業(yè)10大管理流程圖,數(shù)字化轉(zhuǎn)型從業(yè)者必備!

        【中臺實踐】華為大數(shù)據(jù)中臺架構(gòu)分享.pdf

        華為的數(shù)字化轉(zhuǎn)型方法論

        華為如何實施數(shù)字化轉(zhuǎn)型(附PPT)

        超詳細280頁Docker實戰(zhàn)文檔!開放下載

        華為大數(shù)據(jù)解決方案(PPT)

        瀏覽 73
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

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

        手機掃一掃分享

        分享
        舉報
          
          

            1. 午夜成人无码福利 | 三级理论网站 | 五月天精品无码 | 51无码人妻精品1国产蜜芽 | 国产人人操 |