docker monitor — grafana+cAdvisor+prometheus

目標為監控所有docker container容器,主要是因為我建的大部分服務都在docker上,需要一個監控系統來除錯。

Step 1.

cAdvisor (Container Advisor) collects, aggregates, processes and exports information about running containers. For installing cAdvisor with docker;

請注意,我在server上的docker位置為 /home/docker

預設位置在 /var/lib/docker ,選錯會造成cAdvisor取不到資料

sudo docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \
--volume=/sys:/sys:ro \
--volume=/home/docker/:/home/docker:ro \
--volume=/dev/disk/:/dev/disk:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \

cAdvisor is now running on http://localhost:8080

Step 2.

Prometheus is an open-source system monitoring and alerting toolkit. Prometheus is very easy to setup. Firstly, we need to download the latest release of prometheus from .

首先要配置 promethus.yml,位置在 /etc/prometheus/prometheus.yml


# global config
scrape_interval: 15s
evaluation_interval: 15s
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
- job_name: 'prometheus'
- targets: ['localhost:9090']
- job_name: 'cadvisor'
scrape_interval: 10s
metrics_path: '/metrics'
- targets: ['localhost:8080']
group: 'cadvisor'


docker run -d -p 9090:9090  -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml     prom/prometheus --name=prometheus

啟用後,到http://localhost:9090 看看


Step 3.

Grafana is an open source metric analytics & visualization suite. It is used for visualizing time series data for infrastructure and application analytics. Grafana installation is very laborless, and we will run it using the official Docker container.

$ docker run -d -p 3000:3000 grafana/grafana

Grafana is running on port 3000 so, we will use http://localhost:3000 for going main page of grafana.


點選左方 「Configuration(齒輪)」> data source


選擇 Prometheus,進行相關配置,先前安裝prometheus為 [http://{your_ip}:9090,不要填localhost,因為docker](http://{your_ip}:9090,不要填localhost,因為docker container內的localhost跟實體機的localhost位置不同。

選擇下方 save and test,系統會檢查是否能連線成功。

下一步,選左方「+」> import

這裡使用 的模板

在裡面輸入 193 > Load


你就能在網頁上觀察看 docker 使用的效能與底下容器的狀態了。






NTUT CSIE | Biomedical Informatics Lab | |

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

{UPDATE} Virtual Mother: Baby Care Game Hack Free Resources Generator

Programming Question: Leetcode-15

Normalizing absolute SVG paths with cubic bézier conversions

We replaced thirty lines of Webpack config with one line of bash

Rails with redis and sidekiq 2021

5 Things to Remember Before Shipping Version 1.0 of your Mobile App

star dust dev iog - starting

#100DaysofAWS | Day 21|Amazon Aurora

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


NTUT CSIE | Biomedical Informatics Lab | |

More from Medium

Understanding DevOps Tool — Docker Compose

Understanding DevOps Tool - Docker Compose

Offline Installation Elasticsearch and Kibana to Ubuntu with XPack Security

Monitoring Nginx Rate Limiting

Configure nginx ingress controller to scrape Prometheus metrics with Azure Container Insights in…