码迷,mamicode.com
首页 > 其他好文 > 详细

Prometheus监控Docker服务(五)

时间:2020-05-10 20:56:31      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:数据源   tac   second   alert   google   run   refresh   增加   config   

一、使用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配置文件

# 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主机的信息了

技术图片

 技术图片

 三、配置Grafana图表盘

技术图片

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

技术图片

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

技术图片

Prometheus监控Docker服务(五)

标签:数据源   tac   second   alert   google   run   refresh   增加   config   

原文地址:https://www.cnblogs.com/cyleon/p/12864720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!