1. 程式人生 > >Prometheus+Grafana部署監控docker服務

Prometheus+Grafana部署監控docker服務

int mar alt src x86_64 follow emd contain nod

1.環境
192.168.244.128 Prometheus 監控服務器
192.168.244.129 docker 服務(被監控端)
註:都是centos7.5系統

2.下載安裝包
https://prometheus.io/download/ (需要的安裝包都可以下載)
wget https://github.com/prometheus/prometheus/releases/download/v2.3.2/prometheus-2.3.2.linux-amd64.tar.gz

服務端(監控server)
3.安裝prometheus
部署到/usr/local/目錄
promethus不用編譯安裝,解壓目錄中有配置文件與啟動文件

tar -zxvf prometheus-2.3.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/ && mv prometheus-2.3.2.linux-amd64/ prometheus
驗證
[root@prometheus local]# cd prometheus/
[root@prometheus prometheus]# ./prometheus --version
prometheus, version 2.3.2 (branch: HEAD, revision: 71af5e29e815795e9dd14742ee7725682fa14b7b)
build user: root@5258e0bd9cc1
build date: 20180712-14:02:52
go version: go1.10.3

備份配置文件並配置
cp prometheus.yml prometheus.yml-bak

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:

    • targets: [‘192.168.244.128:9090‘,‘192.168.244.129:8080‘]

添加需要監控的服務器IP和端口

啟動(後臺啟動)
./prometheus --config.file=prometheus.yml &
然後我們可以訪問 http://<服務器IP地址>:9090,驗證Prometheus是否已安裝成功,web顯示應該如下
技術分享圖片
通過點擊下拉欄選取指標,點擊”Excute” 我們能夠看到Prometheus的性能指標。
點擊”status”可以查看相關狀態。

4.node_exporter安裝
wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz
解壓並安裝
tar xf node_exporter-0.16.0.linux-amd64.tar.gz C /usr/local/
cd /usr/local/ && mv mv node_exporter-0.16.0 node_exporter
cd node_exporter/ && ./node_exporter &

返回一大堆指標

5.grafana安裝
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.2.3-1.x86_64.rpm
sudo yum localinstall grafana-5.2.3-1.x86_64.rpm
服務端圖像呈現組件安裝
yum install fontconfig freetype* urw-fonts -y
開啟系統默認啟動
systemctl enable grafana-server
啟動服務
systemctl start grafana-server
查看服務是否正常啟動
systemctl status grafana-server
[root@prometheus ~]# systemctl status grafana-server
● grafana-server.service - Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: disabled)
Active: active (running) since 四 2018-08-30 16:18:55 CST; 3h 23min ago
Docs: http://docs.grafana.org
Main PID: 10535 (grafana-server)
CGroup: /system.slice/grafana-server.service
└─10535 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid ...
訪問grafana, http://<服務器IP>:3000
默認用戶名密碼:admin/admin
技術分享圖片

客戶端(被監控)
6.安裝cAdvisor 來收集容器信息 所有節點運行以下命令來安裝cAdvisor
docker run \
--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

為grafana添加Prometheus數據源
技術分享圖片
導入監控模板
https://grafana.com/dashboards?search=docker 多種docker 監控模板
技術分享圖片
技術分享圖片
添加釘釘報警
技術分享圖片
測試
技術分享圖片

Prometheus+Grafana部署監控docker服務