Prometheus监控Docker服务(五)

scmrpu 2020-05-10

一、使用cAdvisor(Container Advisor)收集正在运行的容器资源使用和性能信息。

https://github.com/google/cadvisor

运行单个cAdvisor来监控整个Docker主机,默认的监听端口为8080

# docker run   --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   google/cadvisor:latest

# docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                      NAMES
736e45251dd4        google/cadvisor:latest   "/usr/bin/cadvisor -…"   20 seconds ago      Up 16 seconds       0.0.0.0:8080->8080/tcp                     cadvisor
64b6b784dcb0        tengine2.2:v2            "nginx -g ‘daemon of…"   5 months ago        Up 5 months         0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   nginx
c864cd8e4f09        php55:v13                "php-fpm"                5 months ago        Up 5 months         0.0.0.0:9000->9000/tcp                     php

查看metrics:

http://192.168.5.85:8080/metrics

Prometheus监控Docker服务(五)

 二、修改prometheus配置文件

# vim /usr/local/prometheus/prometheus.yml 
# 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.

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

scrape_configs:
  - job_name: ‘prometheus‘

    # metrics_path defaults to ‘/metrics‘
    # scheme defaults to ‘http‘.

    static_configs:
    - targets: [‘192.168.5.237:9090‘]

  - job_name: ‘node‘
    file_sd_configs:
    - refresh_interval: 30s
      files:
      - "/usr/local/prometheus/sd_config/node*.yml"
# 增加要监控的docker主机
  - job_name: ‘docker‘
    static_configs:                                                                                                                     
    - targets: [‘192.168.5.85:8080‘]   

# 检查配置文件
# /usr/local/prometheus/promtool check config /usr/local/prometheus/prometheus.yml 
Checking /usr/local/prometheus/prometheus.yml
  SUCCESS: 0 rule files found

# 重启服务
# systemctl restart prometheus.service

targets中已经能查到docker主机的信息了

Prometheus监控Docker服务(五)

 Prometheus监控Docker服务(五)

 三、配置Grafana图表盘

Prometheus监控Docker服务(五)

 修改名称及数据源等信息后点击import

Prometheus监控Docker服务(五)

 能查到主机上所有运行容器的CPU、内存、和网络的使用情况

Prometheus监控Docker服务(五)

相关推荐