在CentOS上监控Docker容器的性能和状态,可以使用以下几种方法:
docker stats 命令docker stats 命令可以实时显示所有运行中的容器的资源使用情况,包括CPU、内存、网络和磁盘I/O。
docker stats
如果你只想监控特定的容器,可以使用 -c 或 --no-stream 参数:
docker stats <container_id_or_name>
cAdvisorcAdvisor(Container Advisor)是一个开源工具,用于收集、聚合、处理和导出有关运行中的容器的资源使用情况和性能特征的指标。
你可以从Docker Hub下载cAdvisor镜像并运行:
docker pull google/cadvisor
docker run -d --name=cadvisor --restart=always \
-p 8080:8080 \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
google/cadvisor
然后,你可以通过浏览器访问 http://<your_server_ip>:8080 来查看容器的监控信息。
Prometheus 是一个开源的监控系统和时间序列数据库,而 Grafana 是一个开源的分析和监控平台。你可以将它们结合起来监控Docker容器。
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-2.30.3.linux-amd64.tar.gz
cd prometheus-2.30.3.linux-amd64
./prometheus --config.file=prometheus.yml
wget https://dl.grafana.com/oss/release/grafana-8.2.0.linux-amd64.tar.gz
tar xvfz grafana-8.2.0.linux-amd64.tar.gz
cd grafana-8.2.0
./bin/grafana-server
编辑 prometheus.yml 文件,添加Docker的监控配置:
scrape_configs:
- job_name: 'docker'
static_configs:
- targets: ['localhost:9323']
然后重启Prometheus服务:
./prometheus --config.file=prometheus.yml
http://<your_server_ip>:3000。htop 和 nmon虽然这些工具不是专门为Docker设计的,但它们可以帮助你监控系统的整体性能,包括CPU、内存和磁盘I/O。
sudo yum install htop nmon
htop
nmon
通过这些方法,你可以全面监控CentOS上Docker容器的性能和状态。