prometheus監控docker的狀態2020-06-17


參考課程來源:https://www.bilibili.com/video/BV1T54y1Q7VY

 

1.prometheus

 

prometheus是監控系統,也是時間序列數據庫

prometheus.yml配置文件,關於配置文件,也可以參考官方文檔:https://prometheus.io/docs/prometheus/latest/configuration/configuration/

global:
  # How frequently to scrape targets by default.
  scrape_interval: 15s  

  # How frequently to evaluate rules.
  evaluation_interval: 15s

# Rule files specifies a list of globs. Rules and alerts are read from
# all matching files.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A list of scrape configurations.
scrape_configs:
  - job_name: 'prometheus'
  static_configs:
  - targets:['localhost:9090']

# Alerting specifies settings related to the Alertmanager.
alerting:  
  alertmanagers:
    - targets:
  # - alertmanager:9093

prometheus配置文件說明,參考自官方文檔

 

 

創建prometheus容器,請注意prometheus.yml配置文件存放的位置

sudo docker run -d \
--name=prometheus \
--restart=always \
-p 9090:9090 \
-v /root/docker/temp/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus

運行效果

 

打開服務器的9090端口,能看到只監控自己本身(即localhost:9090) 

 

2.cAdvisor

cAdvisor(Container Advisor)是Google開源,用於收集一台機器上所有運行的容器信息(cAdvisor只進行查看,並不做數據的保存,所以需要將cAdvisor的數據加載到Prometheus中)

sudo 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 \
--restart=always \
google/cadvisor:latest

運行效果

 

查看服務器的8080端口

 

 

查看服務器的8080端口如果進入到服務器的http://172.17.130.131:8080/metrics地址,則可以看到監控的指標

 

 

3.node-exporter

node-expoter是prometheus開源的,能夠提取到機器的信息

docker run -d -p 9100:9100 \
  -v "/proc:/host/proc:ro" \
  -v "/sys:/host/sys:ro" \
  -v "/:/rootfs:ro" \
  --net="host" \
  prom/node-exporter

運行效果

 

查看服務器地址:http://172.17.130.131:9100/metrics,也可以查看到node-export的監控指標

 

修改配置文件prometheus.yml,增加了cAdvisor和node-expoter配置,修改如下(刪除了部分注釋),然后重啟prometheus容器

lobal:
  scrape_interval:     15s
  evaluation_interval: 15s
 
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus
 
  - job_name: docker
    static_configs:
      - targets: ['172.17.130.131:8080']
        labels:
          instance: localhost

  - job_name: linux
    static_configs:
      - targets: ['172.17.130.131:9100']
        labels:
          instance: localhost  

 

 

4.Grafana

grafana是跨平台的開源試題分析和可視化工具,可以通過將采集的數據查詢然后做可視化的展示。
啟動Grafana容器

sudo docker run -d --name=grafana --restart=always -p 3001:3000 grafana/grafana

運行效果

 

進入到服務器的3001端口(原本是3000端口,因為服務器在占用3000端口,所以修改成3001)
默認的用戶名與密碼都是admin,首次進入需要修改密碼

 

 

進入后新增數據源(Data Source)

 

可以增加一個prometheus的數據源

 

在prometheus中選擇數據源為服務器的9090地址

 

導入grafana,http://172.17.130.131:3001/dashboard/import
Docker主機監控模板:193
Linux主機監控模板:9276 8919 12227

 

 點擊Load后,可以看到看板的信息

 

Docker容器的看板

 

 

 

 

 

有道雲筆記地址:https://note.youdao.com/ynoteshare1/index.html?id=d91a9f59c0d6f208fdc42014c3870c59&type=note


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM