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取不到資料

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 https://prometheus.io/download/ .

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

配置為

這裡我跟原文操作不同的是我把prometheus也同樣採用container安裝,所以指令為

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

理論上會看到兩個服務都是up的狀態,如果沒有請檢查container是否沒有開啟,或port衝突。

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.

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

http://localhost:3000

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

新增一個新的來源

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

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

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

這裡使用 https://grafana.com/grafana/dashboards/193 的模板

在裡面輸入 193 > Load

最後,

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

參考文件:https://medium.com/@mertcan.simsek276/docker-monitoring-with-cadvisor-prometheus-and-grafana-adefe1202bf8

請我喝杯咖啡

https://buymeacoffee.com/stwater20

--

--

NTUT CSIE | Biomedical Informatics Lab | github.com/stwater20 | sectools.tw

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