An overview of the

A host can run multiple containerized applications. Containerized applications run on the host. We need to know the running status of the container, including a series of information such as CPU usage, memory usage, network status and disk space, and these information changes over time, which is called timing data. This paper will practice how to build a visual monitoring center to collect the time series information of these containers carrying specific applications and analyze and display it visually!

Do it, do it…

Note: This article was published on My public account CodeSheep. You can subscribe by holding down or scanning the heart below ↓ ↓ ↓


Prepare the mirror

  • Adviser: Collects the container data over time

  • Influxdb: Stores temporal data

  • Grafana: Responsible for analyzing and presenting temporal data


The Influxdb service is deployed

You can think of it as a database service that actually stores data. The database was chosen for the reasons stated on the website:

Open Source Time Series DB Platform for Metrics & Events (Time Series Data)

Let’s deploy the service

docker run -d -p 8086:8086 \
-v ~/influxdb:/var/lib/influxdb \
--name influxdb tutum/influxdb
Copy the code
  • Enter influxDB inside the influxDB container and execute the Influx command:
docker exec -it influxdb influx
Copy the code

  • Create database test and root users for this trial test
CREATE DATABASE "test"
Copy the code
CREATE USER "root" WITH PASSWORD 'root' WITH ALL PRIVILEGES
Copy the code


Deploy the cAdvisor service

Google’s CAdvisor can be used to gather temporal information about Docker containers, including resource usage and performance data as the containers run.

  • Run the CAdvisor service
docker run -d\ -v /:/rootfs -v /var/run:/var/run -v /sys:/sys \ -v /var/lib/docker:/var/lib/docker \ --link=influxdb:influxdb --name Cadvisor Google/CAdvisor :v0.27.3 \ --storage_driver= Influxdb \ --storage_driver_host= InfluxDB :8086 \ --storage_driver_db=test \
--storage_driver_user=root \
--storage_driver_password=root
Copy the code

Special attention:

There are two other configuration items that need to be added when running the above docker (CentOS, RHEL) :

  • –privileged=true

When set to true, root in the container has true root permission, can see devices on host, and can mount. Otherwise, root inside the container is only an external normal user privilege. Because cAdvisor requires access to the Docker daemon through sockets, this option is required on CentOs and RHEL systems.

  • –volume=/cgroup:/cgroup:ro

For CentOS and RHEL versions (such as CentOS6), the cgroup layer is attached to the /cgroup directory. Therefore, you need to add the -volume =/cgroup:/cgroup:ro option when running cAdvisor.


Deploy the Grafana service

Grafana is an open source time-series data analysis tool with a professional and easy-to-use interface that you’ll see when deployed:

docker run -d -p 5000:3000 \
-v ~/grafana:/var/lib/grafana \
--link=influxdb:influxdb \
--name grafana grafana/grafana
Copy the code

All three containers are now started:

Let’s start with the concrete experiment


In actual combat

  • Access the Grafana service

Open localhost:5000 to access grafana’s Web service, and you will be prompted to log in. Note that the user name and password are admin

When you log in, you can see the main grafana page:

As you can see, there are several steps that need to be done on Grafana. Here, Install Grafana is done. Next we need to:

  • Add data source
  • Create dashboard
  • … .

  • Add Data Source

Click Add Data Source to enter

And then mostly the Setting TAB Settings

We need to fill in the contents according to the actual situation:

A message will be displayed when the Data source is added successfully

Once the data source is added, we need to add the Dashboard.


  • Add Dashboard

Click Add Dashboard to enter

There are many types of dashboards to choose from, but Graph is the most popular

After entering, click the Panel Title dropdown and select Edit to Edit it

The main thing in Edit is to add criteria to a query. Continue below


  • Add Query Editor

In the query conditions, we can select the indicators to be monitored:

Select a memory usage, and then select grafana itself for the container to monitor.

We can monitor more than one metric, and we can monitor more than one container. We just need to add query entries one by one.

Finally, I added three monitoring conditions to monitor the memory usage of grafana, InfluxDB and CAdvisor, respectively, and displayed them in the figure.

There are many Settings to explore, such as some coordinate customization, display policy customization, even we can customize alarm policies and so on


Afterword.

  • The author’s more original articles are here, welcome to watch

  • My Personal Blog

The author has more SpringBt practice articles here:

  • Spring Boot application monitoring actual combat
  • The SpringBoot application is deployed in an external Tomcat container
  • ElasticSearch in SpringBt practice
  • A preliminary study on Kotlin+SpringBoot joint programming
  • Spring Boot Logging framework practices
  • SpringBoot elegant coding: Lombok plus

If you are interested, take some time to read some of the author’s articles on containerization and microservitization:

  • Use K8S technology stack to create personal private cloud serial articles
  • Nginx server configuration from a detailed configuration list
  • Docker container visual monitoring center was built
  • Use ELK to build Docker containerized application log center
  • RPC framework practice: Apache Thrift
  • RPC framework practice: Google gRPC
  • Establishment of microservice call chain tracking center
  • Docker containers communicate across hosts
  • Preliminary study on Docker Swarm cluster
  • Several guidelines for writing dockerFiles efficiently