使用Prometheus+Grafana搭建監(jiān)控系統(tǒng)

基于spring boot 基礎(chǔ)上搭建
1.先添加 pom 依賴

        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_spring_boot</artifactId>
            <version>0.1.0</version>
        </dependency>

啟動(dòng)類添加注解

@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector

配置文件添加

# 默認(rèn)賬號(hào)密碼
managment.security.enabled=false
spring.application.name=microservice-prometheus

2.安裝prometheus
本文中安裝的為Windows 版本,如需Linux,下載鏈接:https://prometheus.io/download/
下載直接解壓即可
修改配置文件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: /prometheus 
    scheme: http
    basic_auth:
      username: user
      password: pwd
    static_configs:
      - targets:
        - 127.0.0.1:9393 #此處填寫 Spring Boot 應(yīng)用的 IP + 端口號(hào)

啟動(dòng) prometheus.exe 即可
啟動(dòng)成功后 打開http://localhost:9090/targets
即可看見(jiàn):

1563437867(1).jpg

3.安裝grafana
同上都是使用Windows版本,下載 戳:https://grafana.com/grafana/download?platform=windows
安裝就不多說(shuō)了,雙擊,選安裝地址即可
啟動(dòng)grafana:
進(jìn)入D:\grafana\grafana\bin目錄下雙擊 grafana-server.exe

啟動(dòng)后訪問(wèn):http://127.0.0.1:3000/

配置數(shù)據(jù)源:

選擇type為Prometheus的數(shù)據(jù)源,名稱為springboot
2.png

3.png

添加一個(gè)dashboard,配置單個(gè)指標(biāo)的可視化監(jiān)控面板:

4.png

填寫指標(biāo)點(diǎn):
6.png

提示,此處填寫需要監(jiān)控的指標(biāo)不能任意填寫,只能填已有的指標(biāo)點(diǎn),具體的可以監(jiān)控的指標(biāo)在 Prometheus 的首頁(yè)看到,即 http://localhost:9090/graph
7.png

或在explore 上找到:


5.jpg

多配置幾個(gè)指標(biāo)之后,即可有如下效果:


8.jpg

到這里大概配置就結(jié)束可以使用了

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容