环境说明:
-
操作系统:Centos7-2009
-
确保网络连接正常、yum源正常,确保网络可以连接外网
-
版本信息:
| Docker version 23.0.1, build a5ee5b1 | -
简介:
:::tips
cAdvisor(Container Advisor):用于收集正在运行的容器资源使用和性能信息。
项目地址:https://github.com/google/cadvisor
:::
被监控主机:11.0.1.134
步骤说明:
1、软件获取
https://prometheus.io/docs/instrumenting/exporters/
https://github.com/google/cadvisor
安装
#设定版本变量
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
验证接口暴露数据图表:http://11.0.1.134:8080/containers/
监控主机配置
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"]
监控主机配置-重载进程:
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仪表盘自行导入