12.Docker Beginner to Master—Container Monitoring-CIG

Docker container monitoring CAdvisor+InfluxDB+Granfana

1. Native commands

Question :

Through the docker stats command, you can easily see the CPU, memory, network traffic and other data of all containers on the current host. It is generally sufficient for small companies. . . .

However, the statistical results of docker stats can only be for all the containers of the current host. The data is real-time. There is no place to store it, and there is no function such as health indicator over-line warning.

2. What is it?

Container monitoring 3 swordsman: CAdvisor monitoring collection + InfluxDB storage data + Granfana display chart

3. compose container orchestration cig

3.1 Create a new directory

mkdir /mydocker/cig
cd /mydocker/cig

3.2 Create a new 3-piece set (docker-compose.ymlCAdvisor+InfluxDB+Granfana) combination docker-compose.yml

 
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
  user: "104"
  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

explain:

version: '3.1'                #必须是3.0以上才能运行docker-compose
 
volumes:
  grafana_data: {}            #实现了grafana数据的挂载
 
services:                    #表示我们要启动的服务,即要docker run的内容,多个实例服务
 influxdb:                    
  image: tutum/influxdb:0.9
  restart: always
  environment:
    -PRE_CREATE_DB=cadvisor    #预先创建一个数据库,创建一个数据库一样
  ports:
    -"8083:8083"        #对外是8083
    -"8086:8086"        #内部即8086
  volumes:
    - ./data/influxdb:/data    #B 从A-B即influxdb服务,拉取的镜像,安装的环境,暴露的端口,下面的cadvisor,grafana都是一样的
 
 cadvisor:
  image: google/cadvisor
  links:
    - influxdb:influxsrv
  command: 
  -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxsrv:8086 #这就是相当于mysql选择的那个驱动
  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
  user: "104"
  restart: always                            #因为有restart,所以如影随形,随着docker启动,就启动
  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
    #千言万语一句话,全部由docker-compose一键部署

3.3 Check configuration

docker compose config -q# 检查配置,有问题才有输出

3.4 Start docker-compose file

  docker compose up -d  后台启动

3.5 Check whether the three service containers are started

docker ps

3.6 Testing

3.6.1 Browse cAdvisor collection service, http://192.168.3.15:8080/

Cadvisor also has a basic graphic display function, which is mainly used here for data collection (collecting real-time data)

3.6.2 Browse the influxdb storage service, http://192.168.3.15:8083/
3.6.3 Browse grafana display service, http://192.168.3.15:3000/

Default account password (admin/admin)

Configuration steps:

1. Configure data source

2. Select influxdb data source

2.Configure panel panel

Guess you like

Origin blog.csdn.net/weixin_54514751/article/details/129683753