docker 自带的监控子命令
- ps:docker ps | docker container ls
- top:docker container top $name
- stats:docker container stats
sysdig
sysdig 是一个轻量级的系统监控工具,同时它原生还支持容器。
docker container run -it --rm --name=sysdig --privileged=true \
--volume=/var/run/docker.sock:/host/var/run/docker.sock \
--volume=/dev:/host/dev \
--volume=/proc:/host/proc:ro \
--volume=/boot:/host/boot:ro \
--volume=/lib/modules:/host/lib/modules:ro \
--volume=/usr:/host/usr:ro \
sysdig/sysdig
- 交互界面
- 实时性
- 命令行操作
Weave Scope
weave scope 的最大特点是会自动生成一张 docker host 地图,直观地理解、监控和控制容器。
curl -L git.io/scope -o /usr/local/bin/scope
chmod a+x /usr/local/bin/scope
scope launch
Weave Scope 的访问地址为http://[Host IP]:4040/
cAdvisor
cAdvisor 是 google 开发的容器监控工具。
安装:
docker run \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--publish=8080:8080 \
--detach=true \
--name=cadvisor \
google/cadvisor:latest
通过 http://[Host IP]:8080
访问cAdvisor。
Prometheus
docker run -d -p 9100:9100 \
-v "/proc:/host/proc" \
-v "/sys:/host/sys" \
-v "/:/rootfs" \
--net=host \
prom/node-exporter \
--path.procfs /host/proc \
--path.sysfs /host/sys \
--collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
prometheus.yml配置文件
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
evaluation_interval: 15s # By default, scrape targets every 15 seconds.
# scrape_timeout: 10s # is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
rule_files:
# - "rules/node.rules"
# - "rules2/*.rules"
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090','localhost:8080','localhost:9100','192.168.24.136:8080','192.168.24.136:9100']
运行 Grafana在 host 192.168.24.137 上执行如下命令:
docker run -d -i -p 3000:3000 \
-e "GF_SERVER_ROOT_URL=http://grafana.server.name" \
-e "GF_SECURITY_ADMIN_PASSWORD=secret" \
--net=host \
grafana/grafana