prometheus 监控Docker

启动CAdvisor

docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:rw \
  --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

配置Prometheus

vim /usr/local/prometheus/prometheus.yml 
  - job_name: cadvisor
    file_sd_configs:
    - files: ['/usr/local/prometheus/sd_config/docker-node.yml']
      refresh_interval: 3s

vim /usr/local/prometheus/sd_config/docker-node.yml
- targets:
  - 192.168.1.155:8080
  - 192.168.1.156:8080
  labels:
    type: docker

/usr/local/prometheus/promtool check config /usr/local/prometheus/prometheus.yml

kill -hup `ps -ef |grep prometheus|grep -v grep|awk '{print $2}'`

查看是否获取到docker数据

http://192.168.1.155:9090/targets

image

表达式计算容器

容器CPU使用率:
sum(irate(container_cpu_usage_seconds_total{image!=""}[1m])) without (cpu)

查询容器内存使用量(单位:字节):
container_memory_usage_bytes{image!=""}

查询容器网络接收量速率(单位:字节/秒):
sum(rate(container_network_receive_bytes_total{image!=""}[1m])) without (interface)

查询容器网络传输量速率(单位:字节/秒):
sum(rate(container_network_transmit_bytes_total{image!=""}[1m])) without (interface)

查询容器文件系统读取速率(单位:字节/秒):
sum(rate(container_fs_reads_bytes_total{image!=""}[1m])) without (device)

查询容器文件系统写入速率(单位:字节/秒):
sum(rate(container_fs_writes_bytes_total{image!=""}[1m])) without (device)

配置grafana

导入模板

模板: https://grafana.com/dashboards/893 或者 179

333.png

你可能感兴趣的:(prometheus 监控Docker)