Docker-CE 监控

Docker Action 记录 作者: LinkSystem 2017/08/12

Docker Action 是我关于Docker-CE的实践记录,该实践的构建环境以下:

[root@core ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 

[root@core ~]# docker version
Client:
 Version:      17.07.0-ce-rc2
 API version:  1.31
 Go version:   go1.8.3
 Git commit:   36ce605
 Built:        Mon Aug  7 23:43:46 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.07.0-ce-rc2
 API version:  1.31 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   36ce605
 Built:        Mon Aug  7 23:45:07 2017
 OS/Arch:      linux/amd64
 Experimental: false

Prometheus 简介

Prometheus是一个开源系统的监控和报警工具。你可以把Docker作为一个Prometheus的目标。这个主题向您展示了如何配置Docker,将Prometheus设置为Docker容器,并使用普罗米修斯监控您的Docker实例。

Docker-CE 配置

# 由于我的Docker-CE的宿主机是虚拟机,我本地访问存在问题故以下配置
# 若非与我的情况相同可配置为"metrics-addr" : "127.0.0.1:9323"
[root@core ~]# vi /etc/docker/daemon.json
{
  "metrics-addr" : "192.168.100.10:9323",
  "experimental" : true
}

[root@core ~]# sudo systemctl restart docker

Prometheus 配置

[root@core ~]# vi /tmp/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.
  # scrape_timeout is set to the global default (10s).

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
      monitor: 'codelab-monitor'

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first.rules"
  # - "second.rules"

# 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.100.10:9090']

  - job_name: 'docker'
         # metrics_path defaults to '/metrics'
         # scheme defaults to 'http'.

    static_configs:
      - targets: ['192.168.100.10:9323']

Prometheus 运行

[root@core ~]# docker service create --replicas 1 --name my-prometheus \
>     --mount type=bind,source=/tmp/prometheus.yml,destination=/etc/prometheus/prometheus.yml \
>     --publish 9090:9090/tcp \
>     prom/prometheus

Prometheus 使用

创建图表。点击Prometheus UI中的图表链接。从执行按钮右侧的组合框中选择一个指标,然后单击 执行。下面的截图显示了图形 engine_daemon_network_actions_seconds_count。
《Docker-CE 监控》

Prometheus 测试

[root@core ~]# [root@core ~]# docker service create \
> >   --replicas 10 \
> >   --name ping_service \
> >   alpine ping baidu.com

稍后,结果如图所示
《Docker-CE 监控》

    原文作者:linksystem
    原文地址: https://segmentfault.com/a/1190000010626886
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞