Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build Docker Container Monitoring system with CAdvisor + InfluxDB + Grafana

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

CAdvisor + InfluxDB + Grafana is how to build Docker container monitoring system, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

The container can be quickly expanded by using docker compose combined applications and scale, and the service containers started by docker compose are all on the same host. When multiple container applications are running on a host, the container's operation, such as CPU utilization, memory utilization, network status, disk space and a series of time series data information that changes over time, need to be understood, so monitoring is necessary.

Selection of container monitoring scheme

There are a variety of monitoring methods for containers, except for the docker stats command that comes with docker itself, and Scout,Data Dog,Sysdig Cloud,Sensu Monitoring Framework,CAdvisor can also monitor the container.

Through the docker stats command, you can easily see the CPU, memory, network traffic and other data of all containers on the current host. However, the disadvantage of the docker stats command is that it only counts all the containers of the current host, and the data obtained is real-time, with no place to store and no alarm function.

Although Scout,Data Dog,Sysdig Cloud provides more perfect services, but they are all managed services and are charged, Sensu Monitoring Framework is highly integrated and free, but the deployment is too complex, comprehensively consider choosing CAdvisor as a monitoring tool.

CAdvisor, which comes from Google, has the advantage of open source products, complete monitoring indicators, easy deployment, and an official docker image. The disadvantage is that the integration is not high, and the data is saved locally for only 2 minutes by default. However, you can add InfluxDB to store data, dock with Grafana display charts, and it is convenient to build a container monitoring system. Data collection and chart display work well, and have little impact on system performance.

Building Container Monitoring system CAdvisor with CAdvisor + InfluxDB + Grafana

CAdvisor is a container resource monitoring tool, including container memory, CPU, network IO, disk IO, etc., and provides a WEB page to view the real-time running status of the container. CAdvisor stores data for 2 minutes by default and is only for a single physical machine. However, CAdvisor provides many data integration interfaces and supports integration such as InfluxDB,Redis,Kafka,Elasticsearch. You can add the corresponding configuration to send the monitoring data to these databases for storage.

There are two main functions of CAdvisor: displaying Host, container monitoring data and displaying historical changes.

InfluxDB

InfluxDB is an open source distributed database of timing, events and metrics written in the Goto language without external dependencies.

Since CAdvisor only stores the last 2 minutes of data locally by default, in order to persist the data and uniformly collect and display the monitoring data, you need to store the data in InfluxDB. InfluxDB is a temporal database, which is specially used to store timing-related data, which is very suitable for storing CAdvisor data, and CAdvisor itself provides a method for InfluxDB integration. You can specify the configuration when you start the container.

Main functions of InfluxDB:

Support time-related functions based on time series

Measurability, which can calculate a large amount of data in real time

Event-based support for arbitrary event data

The main features of InfluxDB:

No structure

Can be any number of columns

Expandable

Support a series of functions such as min,max to facilitate statistics

Native HTTP support, built-in HTTP API

Powerful SQL-like syntax

Granfana

Grafana is an open source data monitoring and analysis visualization platform, supporting a variety of data source configurations (such as InfluxDB,MySQL,Elasticserach,OpenTSDB,Graphite, etc.) and rich plug-ins and template functions, supporting chart access control and alarm.

Main features of Grafana

Flexible and rich graphical options

Can mix a variety of styles

Support for day and night mode

Multiple data sources

CAdvisor is responsible for collecting container data that changes over time.

InfluxDB is responsible for storing time series data

Grafana is responsible for analyzing and displaying time series data.

Install, deploy, deploy InfluxDB service

Start the service container of InfluxDB:

Docker run-d-name influxdb-p 8086 purl 8086\

-v / data/influxdb:/var/lib/influxdb\

-- hostname influexdb\

Influxdb

Create test databases and root users in the container

Docker exec-it influxdb influx

> CREATE DATABASE "test"

> CREATE USER "root" WITH PASSWORD 'root' WITH ALL PRIVILEGES

Deploy CAdvisor

Start the service container of CAdvisor:

Docker run\

-- volume=/:/rootfs:ro\

-- volume=/var/run:/var/run:ro\

-- volume=/sys:/sys:ro\

-- volume=/var/lib/docker/:/var/lib/docker:ro\

-- volume=/dev/disk/:/dev/disk:ro\

-- publish=8080:8080\

-- detach=true\

-- name=cadvisor\

Google/cadvisor:latest\

-storage_driver=influxdb\

-storage_driver_host=influxdb:8086\

-storage_driver_db=test\

-storage_driver_user=root\

-storage_driver_password=root

After the service container is set up, you can access http:///ip:8080 through a browser.

Deploy Grafana

Start the Grafana service container:

Docker run-d-p 3000UR 3000\

-v / data/grafana:/var/lib/grafana\

-- link=influxdb:influxdb\

-- name grafana grafana/grafana

After running the command directly, you may find that the container is not started. Through the docker logs command, you will find the error of "mkdir: can't create directory'/ var/lib/grafana/plugins': Permission denied". In fact, you do not have the permission of / data/grafana on the host corresponding to the data volume. You can create the / data/grafana directory and give the permission 777 before running the startup command. Or use "docker run-entrypoint" id "grafana/grafana" to view uid,gid,groups (default is 472), and then modify permissions via "chown-R 472 / data/grafana".

Grafana can be accessed by http://ip:3000 after normal startup. The following login page appears. The password needs to be changed for the first visit. The default username password is: admin/admin.

Docker Compose integrated deployment

Prepare the docker-compose.yml file

Version: '3.1'

Volumes:

Grafana_data: {}

Services:

Influxdb:

Image: influxdb

Restart: always

Environment:

-PRE_CREATE_DB=cadvisor

Ports:

-"8086 rime 8086"

Expose:

-"8090"

-"8099"

Volumes:

-. / data/influxdb:/data

Cadvisor:

Image: google/cadvisor

Links:

-influxdb:influxdb-host

Command:-storage_driver=influxdb-storage_driver_db=cadvisor-storage_driver_host=influxdb-host:8086

Restart: always

Ports:

-"8080Rank 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:influxdb-host

Ports:

-"3000Groupe 3000"

Volumes:

-grafana_data:/var/lib/data

Environment:

-HTTP_USER=admin

-HTTP_PASS=admin

-INFLUXDB_HOST=influxdb-host

-INFLUXDB_PORT=8086

-INFLUXDB_NAME=cadvisor

-INFLUXDB_USER=root

-INFLUXDB_PASS=root

Run the following command from the docker-compose.yml file directory to start the service:

Docker-compose up-d

-d specifies that the startup can be started in the background, and the startup log can be viewed in the console without adding for the first startup. Of course, the startup log can also be viewed through "docker-compose logs" in the background.

After the service is started normally, you can access Granafa by http://ip:3000. Click add data source on the Home Dashboard page.

Configure InfluxDB connection information. Of course, before configuring connection information, you need to enter the InfluxDB container to create the corresponding cadvisor database and user root/root.

Create cadvisor databases and root users in the container

Docker exec-it influxdb-contianer-id influx

> CREATE DATABASE "cadvisor"

> CREATE USER "root" WITH PASSWORD 'root' WITH ALL PRIVILEGES

Configure the connection InfluxDB connection:

After the data source is configured, you can go back to Home Dashboard to add dashboard charts to display monitoring information. Grafana provides rich image templates to display monitoring data.

Add dashboard:

Optional template:

Edit the chart:

Configure a chart display that monitors the memory usage of the cadvisor container. Once configured, click Save.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report