005--监控Docker容器

环境说明:

  1. 操作系统:Centos7-2009

  2. 确保网络连接正常、yum源正常,确保网络可以连接外网

  3. 版本信息:
    | Docker version 23.0.1, build a5ee5b1 |

  4. 简介:
    :::tips
    cAdvisor(Container Advisor):用于收集正在运行的容器资源使用和性能信息。
    项目地址:https://github.com/google/cadvisor
    :::
    被监控主机:11.0.1.134

步骤说明:

1、软件获取

https://prometheus.io/docs/instrumenting/exporters/
image.png
https://github.com/google/cadvisor
image.png

安装

#设定版本变量
VERSION=v0.36.0 # use the latest release version from https://github.com/google/cadvisor/releases

#创建容器
sudo 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 \
  --privileged \
  --device=/dev/kmsg \
  gcr.io/cadvisor/cadvisor:$VERSION

验证接口暴露数据:http://11.0.1.134:8080/metrics

image.png

验证接口暴露数据图表:http://11.0.1.134:8080/containers/

image.png

监控主机配置

vi 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).

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

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# 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: ["localhost:9090"]
  - job_name: "exp"
    basic_auth:
      username: prometheus
      password: 123456
    static_configs:
      - targets: ["11.0.1.134:9100"]

  - job_name: "docker"
    static_configs:
      - targets: ["11.0.1.134:8080"]

image.png

监控主机配置-重载进程:

ps -ef|grep prome
root        666      1  0 12:42 ?        00:00:05 /opt/monitor/prometheus/prometheus --config.file=/opt/monitor/prometheus/prometheus.yml
root       2448   1524  0 14:51 pts/0    00:00:00 grep --color=auto prome

kill -HUP 666

grafana仪表盘自行导入

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值