cadvisor_exporter 是一个用于将 cAdvisor 监控数据暴露给 Prometheus 的开源软件。它充当一个代理,运行在与 cAdvisor 相同的主机上,并通过查询 cAdvisor 提供的 API 来获取容器的性能指标和状态信息。
cadvisor_exporter 从 cAdvisor 收集各种容器的资源使用情况,如 CPU 利用率、内存使用量、文件系统使用情况、网络流量等,并将这些指标数据转换成 Prometheus 可以理解的格式。然后,它将这些指标数据暴露给 Prometheus,使得 Prometheus 可以定期从 cadvisor_exporter 暴露的 HTTP 端点获取数据,并将其存储、分析和可视化。
通过与 Prometheus 结合使用,cadvisor_exporter 可以帮助管理员监视和管理容器集群中各个容器的性能和状态。管理员可以使用 Prometheus 查询语言构建自定义的监控规则和警报条件,以便在容器出现问题或性能异常时及时发出警报。
vim /cadvisor_install.sh
- #!/bin/bash
- # -*- coding: utf-8 -*-
- # Author: make.han
- # Email: CIASM@CIASM
- # Date: 2024/01/16
-
- OPT_CATALOGUE=/opt
- CADVISOR_EXPORTER_PREFIX=/opt/cadvisor
- CADVISOR_EXPORTER_URL=https://github.com/google/cadvisor/releases/download/v0.47.2/cadvisor-v0.47.2-linux-amd64
- CADVISOR_EXPORTER_BINARY=cadvisor-v0.47.2-linux-amd64
- CADVISOR_EXPORTER_NEW=cadvisor
- CADVISOR_EXPORTER_PORT=8082
-
- install_cadvisor_exporter (){
- if [ ! -d ${CADVISOR_EXPORTER_PREFIX} ];then
-
- # selinux stop
- setenforce 0
- sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
-
- if [ $? -eq 0 ];then
-
- # create directory
- mkdir -p $CADVISOR_EXPORTER_PREFIX
-
- echo "download cadvisor"
- wget -N -P $CADVISOR_EXPORTER_PREFIX $CADVISOR_EXPORTER_URL
-
- echo "Compile and install & config"
- mv $CADVISOR_EXPORTER_PREFIX/$CADVISOR_EXPORTER_BINARY $CADVISOR_EXPORTER_PREFIX/$CADVISOR_EXPORTER_NEW
-
- # Grant execution permission
- chmod +x $CADVISOR_EXPORTER_PREFIX/$CADVISOR_EXPORTER_NEW
-
- # cadvisor environment variable
- sed -i '$aexport CADVISOR_HOME='$CADVISOR_EXPORTER_PREFIX'' /etc/profile
- sed -i '$aexport PATH=\$CADVISOR_HOME/:\$PATH' /etc/profile
- source /etc/profile
-
- echo "cadvisor Start Service"
- cat >>/usr/lib/systemd/system/cadvisor.service<
- [Unit]
- Description=cadvisor
- Documentation=https://github.com/google/cadvisor/tree/master/docs
- After=network.target
-
- [Service]
- Type=simple
- ExecStart=$CADVISOR_EXPORTER_PREFIX/$CADVISOR_EXPORTER_NEW -port $CADVISOR_EXPORTER_PORT
- Restart=on-failure
-
- [Install]
- WantedBy=multi-user.target
- EOF
-
- echo " cadvisor Example Set the automatic startup service"
- systemctl daemon-reload
- systemctl enable --now cadvisor
-
- # cadvisor version
- cadvisor -version | awk '{print $3}'
-
- echo "firewall cadvisor_exporter port"
- firewall-cmd --zone=public --add-port=$CADVISOR_EXPORTER_PORT/tcp --permanent && firewall-cmd --reload
-
- echo -e "\033[32mThe cadvisor_exporter Install Sussess...\033[0m"
- else
- echo -e "\033[33mThe cadvisor_exporter Install Failed...\033[0m"
- exit 1
- fi
- else
- echo -e "\033[31mThe cadvisor_exporter Install already...\033[0m"
- fi
- }
-
- main (){
- install_cadvisor_exporter
- }
-
- main
bash /cadvisor_install.sh
http://YOU_IP:8082
- scrape_configs:
- - job_name: 'web'
- scrape_interval: 5s
- static_configs:
- - targets:
- - localhost:9090
-
- - job_name: 'docker-cadvisor-monitoring'
- scrape_interval: 5s
- static_configs:
- - targets:
- - 192.168.11.230:8082