Prometheus + Grafana搭建可視化監(jiān)控系統(tǒng)

參考:Prometheus + Grafana搭建可視化監(jiān)控系統(tǒng)(1) - ZongweiBai - 博客園 (cnblogs.com)

Linux

監(jiān)控遠(yuǎn)程Linux主機使用的Exporter是node_exporter 組件,同樣選擇對應(yīng)的版本下載,解壓到 /usr/local/promethus-export/node_exporter,node_exporter無需配置,直接啟動即可:

./node_exporter

啟動完成后,訪問 http://127.0.0.1:9100 驗證是否正確啟動。

SpringBoot2

本次部署使用的是SpringBoot 2.3.4.RELEASE,對Prometheus的支持非常好,首先引用maven依賴:

<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>

添加application.yaml

# actuator相關(guān)配置
management:
  endpoints:
    web:
      exposure:
        include: "*"
      base-path: /actuator
  endpoint:
    prometheus:
      enabled: true
  metrics:
    export:
      prometheus:
        enabled: true
        step: 1ms
        descriptions: true

配置自定義bean

@Bean
public MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
    return (registry) -> registry.config().commonTags("application", applicationName);
}

完成這三步后啟動Application,就可以使用actuator接口查看到Prometheus收集的數(shù)據(jù):http://127.0.0.1:8080/actuator/prometheus 。

最終,訪問Prometheus的target,就能看到我們剛剛部署的這三個exporter:

image

配置Grafana

Prometheus的查看界面過于簡單,也很難做到一目了然,配合Grafana的強大前端表現(xiàn)力和豐富的dashboard,我們可以很輕松的配置出美觀的界面。

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

首先添加一個數(shù)據(jù)源,將Grafana和Prometheus關(guān)聯(lián)起來。選擇Configuration的Data Sources,點擊Add data source,選擇Prometheus,在URL一欄填寫Prometheus的訪問地址,然后保存即可。

image

添加Dashboard

數(shù)據(jù)源配置成功后,選擇Create->Import,在此界面上傳或配置Dashboard,在https://github.com/percona/grafana-dashboards 這個項目,我們可以找到一些成熟的Dashboard配置,對于Linux監(jiān)控可以選擇 System_Overview.json,對于MySQL可以選擇 MySQL_Overview.json,將這兩個文件下載,依次選擇 【Upload JSON file】按鈕進(jìn)行上傳。

注意:上傳之前請先將所有的pmm-singlestat-panel替換為singlestat,否則會報panel未定義,無法正常顯示。

除了這個開源項目之外,Grafana還提供了官方的Dashboard市場:https://grafana.com/grafana/dashboards 。我們可以在這里找到各種數(shù)據(jù)源各種收集器的Dashboard配置。

對于Springboot2,我選擇了 https://grafana.com/grafana/dashboards/10280 作為配置,將10280填入第一個輸入框,然后點擊【load】。

至此,所有的配置都已完成,最后來看看SpringBoot的監(jiān)控效果圖。

image

參考

Spring Boot 2.1X+Prometheus +Grafana實現(xiàn)監(jiān)控及可視化

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

Linux下安裝Prometheus詳細(xì)步驟

Spring Boot 2.x監(jiān)控數(shù)據(jù)可視化(Actuator + Prometheus + Grafana手把手)

Spring Boot2.x-14 使用Prometheus + Grafana 實現(xiàn)可視化的監(jiān)控

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

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

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