Docker容器监控之CAdvisor+InfluxDB+Granfana

1、原生命令

1
docker stats

image-20220118212346079

通过docker stats命令可以很方便的看到当前宿主机上所有容器的CPU,内存以及网络流量等数据,一般小公司够用了。。。。

但是,docker stats统计结果只能是当前宿主机的全部容器,数据资料是实时的,没有地方存储、没有健康指标过线预警等功能

2、容器监控3剑客

image-20220118212633309
image-20220118212447471

CAdvisor监控收集+InfluxDB存储数据+Granfana展示图表

  • CAdvisor

    image-20220118212525866

  • InfluxDB

    image-20220118212606843

  • 2.1.3 Granfana
    image-20220118212618713

3、compose容器编排

3.1、新建目录

1
2
mkdir /cig
cd /cig

3.2、新建3件套组合的docker-compose.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
version: '3.1'

volumes:
grafana_data: {}

services:
influxdb:
image: tutum/influxdb:0.9
restart: always
environment:
- PRE_CREATE_DB=cadvisor
ports:
- "8083:8083"
- "8086:8086"
volumes:
- ./data/influxdb:/data

cadvisor:
image: google/cadvisor
links:
- influxdb:influxsrv
command: -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086
restart: always
ports:
- "8080:8080"
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro

grafana:
user: "104"
image: grafana/grafana
restart: always
links:
- influxdb:influxsrv
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
environment:
- HTTP_USER=admin
- HTTP_PASS=admin
- INFLUXDB_HOST=influxsrv
- INFLUXDB_PORT=8086
- INFLUXDB_NAME=cadvisor
- INFLUXDB_USER=root
- INFLUXDB_PASS=root

3.3、启动docker-compose文件

1
docker-compose up

image-20220118213103447

image-20220118213108264

3.4、查看三个服务容器是否启动

image-20220118213200057

3.5、测试

cadvisor也有基础的图形展现功能,这里主要用它来作数据采集

1
2
3
4
5
6
7
8
# 浏览cAdvisor收集服务,http://ip:8080/
http://192.168.48.111:8080/containers/

# 浏览influxdb存储服务,http://ip:8083/
http://192.168.48.111:8083/

# 浏览grafana展现服务,http://ip:3000,ip+3000端口的方式访问,默认帐户密码(admin/admin)
http://192.168.48.111:3000/

image-20220118213651389

配置步骤:

  1. 配置数据源

    image-20220118213824599

  2. 选择influxdb数据源

    image-20220118213926847

  3. 配置细节

    image-20220118213951294
    image-20220118214038984
    image-20220118214053568

  4. 配置面板panel

    image-20220118214527070
    image-20220118214711214
    image-20220118214721594
    image-20220118214730825
    image-20220118214738397

  5. 到这里cAdvisor+InfluxDB+Grafana容器监控系统就部署完成了


Docker容器监控之CAdvisor+InfluxDB+Granfana
https://flepeng.github.io/042-云原生-01-Docker-83-监控-Docker容器监控之CAdvisor-InfluxDB-Granfana/
作者
Lepeng
发布于
2023年3月8日
许可协议