中文文檔
需了解cadvisor
首先在監(jiān)控服務(wù)器安裝:
1.安裝Node Exporter 來(lái)收集硬件信息
所有節(jié)點(diǎn)運(yùn)行以下命令安裝Node Exporter 容器
docker run -d -p 9100:9100 \
-v "/proc:/host/proc" \
-v "/sys:/host/sys" \
-v "/:/rootfs" \
-v "/etc/localtime:/etc/localtime" \
--net=host \
prom/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
注意:
這里我們使用了 --net=host,這樣 Prometheus Server 可以直接與 Node Exporter 通信
2.安裝cAdvisor 來(lái)收集容器信息 所有節(jié)點(diǎn)運(yùn)行以下命令來(lái)安裝cAdvisor
docker run -d \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
--net=host \
-v "/etc/localtime:/etc/localtime" \
google/cadvisor:latest
注意:
這里我們使用了 --net=host,這樣 Prometheus Server 可以直接與 cAdvisor 通信。
3.安裝普羅米修斯服務(wù)
首先在本地創(chuàng)建prometheus.yml這是普羅米修斯的配置文件
將下方內(nèi)容寫(xiě)入到文件中
將監(jiān)聽(tīng)的地址改為自己本機(jī)地址
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
#監(jiān)聽(tīng)的地址
- targets: ['localhost:9090','10.0.122.39:8080','10.0.122.39:9090']
啟動(dòng)容器
docker run -d -p 9090:9090 \
-v /root/prometheus.yml:/etc/prometheus/prometheus.yml \
-v "/etc/localtime:/etc/localtime" \
--name prometheus \
--net=host \
prom/prometheus
注意:
這里我們使用了 --net=host,這樣 Prometheus Server 可以直接與 Exporter 和 Grafana 通信。
當(dāng)Prometheus容器啟動(dòng)成功后訪問(wèn)
10.0.122.39:9090

4.在DockerMachine上運(yùn)行Grafana
docker run -d -i -p 3000:3000 \
-v "/etc/localtime:/etc/localtime" \
-e "GF_SERVER_ROOT_URL=http://grafana.server.name" \
-e "GF_SECURITY_ADMIN_PASSWORD=admin8888" \
--net=host \
grafana/grafana
Grafana啟動(dòng)后,在瀏覽器中打開(kāi)http://10.0.122.39:3000 登錄界面,登錄用admin 密碼為剛創(chuàng)建Grafana時(shí)的admin8888

添加普羅米修斯服務(wù)器,重點(diǎn)看框部分,其它默認(rèn)即可

如果一切順利該DataSource可以正常工作了,也就是說(shuō)Grafana可以正常跟Prometheus正常通信了,接下來(lái)通過(guò)dashboard展示數(shù)據(jù)。
7.自己手工創(chuàng)建dashboard有點(diǎn)困難,可以借助開(kāi)元的力量訪問(wèn) 監(jiān)控模板地址 將會(huì)看到很多用于監(jiān)控 Docker 的 Dashboard。監(jiān)控模板地址(多種監(jiān)控模板根據(jù)自己需求下載不同的模板)

有些dashboard可以下載后直接導(dǎo)入,而有些需要修改后再導(dǎo)入,需要看dashboard的overview

最后效果

最后說(shuō)明:
監(jiān)控服務(wù)器 需要安裝4個(gè)服務(wù)
Prometheus Server(普羅米修斯監(jiān)控主服務(wù)器 )
Node Exporter (收集Host硬件和操作系統(tǒng)信息)
cAdvisor (負(fù)責(zé)收集Host上運(yùn)行的容器信息)
Grafana (展示普羅米修斯監(jiān)控界面)
被監(jiān)控的只有安裝2個(gè)
Node Exporter (收集Host硬件和操作系統(tǒng)信息)
cAdvisor (負(fù)責(zé)收集Host上運(yùn)行的容器信息)