docker部署Prometheus+Cadvisor+Grafana實(shí)現(xiàn)服務(wù)器監(jiān)控
Prometheus
Prometheus是一個(gè)在SoundCloud上構(gòu)建的開源系統(tǒng)監(jiān)視和警報(bào)工具包
特點(diǎn)
- 多維度數(shù)據(jù)模型-由指標(biāo)鍵值對(duì)標(biāo)識(shí)的時(shí)間序列數(shù)據(jù)組成;
- PromQL,一種靈活的查詢語(yǔ)言;
- 不依賴分布式存儲(chǔ); 單個(gè)服務(wù)器節(jié)點(diǎn)是自治的;
- 以HTTP方式,通過(guò)pull模型拉取時(shí)間序列數(shù)據(jù);
- 支持通過(guò)中間網(wǎng)關(guān)推送時(shí)間序列數(shù)據(jù);
- 通過(guò)服務(wù)發(fā)現(xiàn)或者靜態(tài)配置,來(lái)發(fā)現(xiàn)目標(biāo)服務(wù)對(duì)象;
- 支持多種多樣的圖表和界面展示。
docker部署Prometheus
(1)拉取Prometheus
docker pull prom/prometheus
(2)配置Prometheus
新建一個(gè)prometheus.yml
global: # 每15s獲取一次數(shù)據(jù)指標(biāo) scrape_interval: 15s # 獲取數(shù)據(jù)超時(shí)時(shí)長(zhǎng) 10s scrape_timeout: 10s # 規(guī)則評(píng)估評(píng)率,即計(jì)算指標(biāo)是否有觸發(fā)規(guī)則的計(jì)算頻率 evaluation_interval: 15s # 規(guī)則文件,從所有匹配的文件中讀取規(guī)則和警報(bào) rule_files: - "alert_rules.yml" # 采集配置列表 scrape_configs: - job_name: prometheus static_configs: - targets: ['localhost:9090'] - job_name: 'node' scrape_interval: 8s static_configs: - targets: ['node-exporter:9100'] - job_name: 'cadvisor' static_configs: - targets: ['cadvisor:8080']
新建一個(gè)規(guī)則文件alert_rules.yml
groups: - name: targets rules: - alert: monitor_service_down expr: up == 0 for: 30s labels: severity: critical annotations: summary: "Monitor service non-operational" description: "Service {{ $labels.instance }} is down." - name: host rules: - alert: high_cpu_load expr: node_load1 > 1.5 for: 30s labels: severity: warning annotations: summary: "Server under high load" description: "Docker host is under high load, the avg load 1m is at {{ $value}}. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}." - alert: high_memory_load expr: (sum(node_memory_MemTotal_bytes) - sum(node_memory_MemFree_bytes + node_memory_Buffers_bytes + node_memory_Cached_bytes) ) / sum(node_memory_MemTotal_bytes) * 100 > 85 for: 30s labels: severity: warning annotations: summary: "Server memory is almost full" description: "Docker host memory usage is {{ humanize $value}}%. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}." - alert: high_storage_load expr: (node_filesystem_size_bytes{fstype="aufs"} - node_filesystem_free_bytes{fstype="aufs"}) / node_filesystem_size_bytes{fstype="aufs"} * 100 > 85 for: 30s labels: severity: warning annotations: summary: "Server storage is almost full" description: "Docker host storage usage is {{ humanize $value}}%. Reported by instance {{ $labels.instance }} of job {{ $labels.job }}."
(3)運(yùn)行Prometheus
docker run -d --name=prometheus -p 9090:9090 -v ./prometheus[創(chuàng)建的配置文件目錄]:/etc/prometheus -v ./opt/data/prometheus[prometheus數(shù)據(jù)需要存儲(chǔ)的地址]:/prometheus prom/prometheus
(4)訪問(wèn)Prometheus
訪問(wèn)127.0.0.1:9090如下表示安裝成功
二:Cadvisor
Cadvisor 是Google用來(lái)監(jiān)測(cè)單節(jié)點(diǎn)資源信息的監(jiān)控工具。 Cadvisor 提供了基礎(chǔ)查詢界面和http接口,方便其他組件如Grafana 、Prometheus等進(jìn)行數(shù)據(jù)抓取。Cadvisor 可以對(duì)Docker主機(jī)上的資源及容器進(jìn)行實(shí)時(shí)監(jiān)控和性能數(shù)據(jù)采集,包括CPU使用情況、內(nèi)存使用情況、網(wǎng)絡(luò)吞吐量及文件系統(tǒng)使用情況等。Cadvisor 使用Go語(yǔ)言開發(fā),利用Linux的Cgroups獲取容器的資源使用信息。
特點(diǎn)
- 可以展示主機(jī)和容器兩個(gè)層次的監(jiān)控?cái)?shù)據(jù)。
- 可以展示歷史變化數(shù)據(jù)。
- 谷歌公司的開源產(chǎn)品。
- 監(jiān)控指標(biāo)齊全。
- 方便部署,有官方的docker鏡像。
- 默認(rèn)只在本地保存1分鐘數(shù)據(jù),可以集成InfluxDB等第三方存儲(chǔ)使用。
docker部署Cadvisor
(1)拉取Cadvisor
docker pull google/cadvisor
(2)運(yùn)行Cadvisor
docker run -d --volume=/:/rootfs:ro --volume=/var/run:/var/run:ro --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --volume=/dev/disk/:/dev/disk:ro --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest
(3)訪問(wèn)Cadvisor
訪問(wèn)127.0.0.1:8080如下表示安裝成功
三:Grafana
Grafana是一個(gè)可視化面板(Dashboard)工具,有著非常漂亮的圖表和布局等展示功能,功能齊全的度量?jī)x表盤和圖形編輯器,支持Graphite、zabbix、InfluxDB、Prometheus和OpenTSDB等組件作為數(shù)據(jù)源。
特點(diǎn)
- 靈活豐富的圖形化選項(xiàng);
- 可以混合多種風(fēng)格;
- 支持白天和夜間模式;
- 支持多個(gè)數(shù)據(jù)源;
docker部署Grafana
(1)拉取Grafana
docker pull grafana/grafana
(2)運(yùn)行Grafana
docker run -d --name=grafana -p 3000:3000 grafana/grafana
(3)訪問(wèn)Grafana
訪問(wèn)127.0.0.1:3000如下表示安裝成功(默認(rèn)賬號(hào)密碼都為admin)
(4)Grafana配置
1.添加Prometheus數(shù)據(jù)源 Connections -> Data sources -> Add new data source -> 選擇Prometheus 設(shè)置Prometheus server URL 為http://prometheus:9090然后保存
2.添加Dashboards儀表板 Dashboards -> import -> 導(dǎo)入儀表板 可用的儀表版模板:
Node Exporter Dashboard 220417 通用Job分組版
Docker monitoring with service selection
3.設(shè)置首頁(yè)默認(rèn)儀表板 Administration -> Default preferences -> 選擇Home Dashboard
4.語(yǔ)言設(shè)置 用戶頭像 -> Profile -> 選擇Language
參考 http://chabaoo.cn/article/247492.htm
以上就是docker部署Prometheus+Cadvisor+Grafana實(shí)現(xiàn)服務(wù)器監(jiān)控的詳細(xì)內(nèi)容,更多關(guān)于docker部署Prometheus+Cadvisor+Grafana實(shí)現(xiàn)服務(wù)器監(jiān)控的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
一文搞定Docker安裝ElasticSearch的過(guò)程
通過(guò)本文可以幫助大家快速學(xué)習(xí)Docker安裝ElasticSearch的過(guò)程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2021-08-08docker利用selenium+testng實(shí)現(xiàn)web自動(dòng)化的方法
這篇文章主要給大家介紹了關(guān)于docker利用selenium+testng實(shí)現(xiàn)web自動(dòng)化的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2018-10-10使用Docker部署MySQL 5.7&8.0主從集群的方法步驟
這篇文章主要介紹了使用Docker部署MySQL 5.7&8.0主從集群的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03詳解Windows?利用?WSL2?安裝?Docker?的2種方式
這篇文章主要介紹了Windows?利用?WSL2?安裝?Docker?的2種方式,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-10-10docker使用alpine構(gòu)建jdk21鏡像的詳細(xì)步驟
這篇文章主要給大家介紹了關(guān)于docker使用alpine構(gòu)建jdk21鏡像的詳細(xì)步驟,鏡像中包含了應(yīng)用程序所需要的運(yùn)行環(huán)境,函數(shù)庫(kù),配置,以及應(yīng)用本身等各種文件,這些文件分層打包而成,需要的朋友可以參考下2024-03-03完美解決docker安裝mysql后Navicat連接不上的問(wèn)題
這篇文章主要介紹了完美解決docker安裝mysql后Navicat連接不上的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-03-03