docker部署Prometheus+Cadvisor+Grafana實(shí)現(xiàn)服務(wù)器監(jiān)控
Prometheus
Prometheus是一個(gè)在SoundCloud上構(gòu)建的開(kāi)源系統(tǒng)監(jiān)視和警報(bào)工具包
特點(diǎn)
- 多維度數(shù)據(jù)模型-由指標(biāo)鍵值對(duì)標(biāo)識(shí)的時(shí)間序列數(shù)據(jù)組成;
- PromQL,一種靈活的查詢(xún)語(yǔ)言;
- 不依賴(lài)分布式存儲(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)建的配置文件目錄](méi):/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ǔ)查詢(xún)界面和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ǔ)言開(kāi)發(fā),利用Linux的Cgroups獲取容器的資源使用信息。
特點(diǎn)
- 可以展示主機(jī)和容器兩個(gè)層次的監(jiān)控?cái)?shù)據(jù)。
- 可以展示歷史變化數(shù)據(jù)。
- 谷歌公司的開(kāi)源產(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表盤(pán)和圖形編輯器,支持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://m.fzitv.net/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的基本使用及使如何用Docker 運(yùn)行D435i
這篇文章主要介紹了docker的基本使用及使如何用Docker 運(yùn)行D435i,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2023-11-11
教你使用Docker搭建gitlab社區(qū)漢化版的詳細(xì)過(guò)程
很多朋友不太清楚使用Docker搭建gitlab社區(qū)漢化版的過(guò)程,總是容易出現(xiàn)錯(cuò)誤,今天小編抽空給大家分享使用Docker搭建gitlab社區(qū)漢化版的詳細(xì)過(guò)程,一起看看吧2021-09-09
skywalking agent 關(guān)聯(lián)docker鏡像的多種方法
Apache SkyWalking 提供了多種方式來(lái)部署和使用 SkyWalking Agent,包括在 Docker 容器中運(yùn)行的應(yīng)用,本文給大家分享幾種方式將 SkyWalking Agent 集成到你的 Docker 應(yīng)用中,感興趣的朋友一起看看吧2025-04-04
Docker安裝Nacos容器并根據(jù)Nginx實(shí)現(xiàn)負(fù)載均衡
本文主要介紹了Docker安裝Nacos容器并根據(jù)Nginx實(shí)現(xiàn)負(fù)載均衡,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-01-01
mac系統(tǒng)使用docker搭建nacos(親測(cè)有效)
本文主要介紹了mac系統(tǒng)使用docker搭建nacos,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-08-08
Docker跨服務(wù)器通信Overlay解決方案(上)之 Consul單實(shí)例
這篇文章主要介紹了Docker跨服務(wù)器通信Overlay解決方案(上)之 Consul單實(shí)例,本文通過(guò)場(chǎng)景分析實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12

