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

        共 3385字,需瀏覽 7分鐘

         ·

        2021-06-07 01:59

        上一篇:一個(gè)90后員工猝死的全過(guò)程


        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>
        然后,在啟動(dòng)類(lèi) Application.java 添加如下注解:
        @SpringBootApplication
        @EnablePrometheusEndpoint
        @EnableSpringBootMetricsCollector
        public class Application {  
            public static void main(String[] args) {
             SpringApplication.run(Application.class, args); 
            }
        }
        最后,配置默認(rèn)的登錄賬號(hào)和密碼,在 application.yml 中:
        security:
          user:
            name:user
            password: pwd

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

        利用賬號(hào)密碼訪問(wèn) http://localhost:8080/application/prometheus ,可以看到 Prometheus 格式的指標(biāo)數(shù)據(jù):

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

        首先,獲取 Prometheus 的 Docker 鏡像:

        $ docker pull prom/prometheus

        然后,編寫(xiě)配置文件 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 #此處填寫(xiě) Spring Boot 應(yīng)用的 IP + 端口號(hào)

        接著,啟動(dòng) Prometheus :

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

        3、Grafana 可視化監(jiān)控?cái)?shù)據(jù)

        首先,獲取 Grafana 的 Docker 鏡像:

        $ docker pull grafana/grafana1

        然后,啟動(dòng) Grafana:

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

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

        Grafana 登錄賬號(hào) admin 密碼 admin

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

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

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

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



        最后,關(guān)注公眾號(hào)互聯(lián)網(wǎng)架構(gòu)師,在后臺(tái)回復(fù):2T,可以獲取我整理和創(chuàng)作的 Java 系列教程非常齊全。

         推薦閱讀 

        1、2019 年 9 月全國(guó)程序員工資統(tǒng)計(jì),你是什么水平?

        2、如何才能成為優(yōu)秀的架構(gòu)師?

        3、從零開(kāi)始搭建創(chuàng)業(yè)公司后臺(tái)技術(shù)棧

        4、程序員一般可以從什么平臺(tái)接私活?

        5、37歲程序員被裁,120天沒(méi)找到工作,無(wú)奈去小公司,結(jié)果懵了...

        6、滴滴業(yè)務(wù)中臺(tái)構(gòu)建實(shí)踐,首次曝光

        7、不認(rèn)命,從10年流水線工人,到谷歌上班的程序媛,一位湖南妹子的勵(lì)志故事

        8、15張圖看懂瞎忙和高效的區(qū)別!


        瀏覽 13
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
          
          

            1. 啊嗯轻一点进去了第一次 | 国产男操女 | 免费做爱小视频 | 小受被用各种姿势进入np唐棠 | 一边做一边喷水 |