(12) Using InfluxDB template

The following content comes from Shang Silicon Valley. I wrote this series of articles mainly to facilitate my own subsequent viewing. I don’t have to carry around a PDF to find it, which is too troublesome!

Chapter 12 Using InfluxDB Templates

12.1 What are InfluxDB templates

1. The InfluxDB template is a yaml-style configuration file. It contains a complete set of dashboards, Telegraf configuration and alarm configuration. The InfluxDB template strives to ensure that it can be used out of the box. Download the yaml file and import it into InfluxDB. Everything from data collection to data monitoring and alarming will be created for you.

2. InfluxDB officially includes a batch of templates on github. Before development, you can take a stroll here to see if there is anything you can use directly. https://github.com/influxdata/community-templates

12.2 Example: Rapid deployment using templates

1. In the example, we will use community templates to quickly create a set of docker monitoring templates. To complete this example, you need to master docker related knowledge in advance.

12.2.1 Find the Docker template document

1. Visit https://github.com/influxdata/community-templates in the previous section to find the directory of the Docker template and click in it. As you can see, there is a section titled Quick install with detailed configuration instructions.

Insert image description here

12.2.2 Installing templates

1. Use influx-cli to install the template.

influx apply -f https://raw.githubusercontent.com/influxdata/community-templates/master/docker/docker.yml

2. After the command is executed, the following message will pop up, asking you whether to use the above resources.

Insert image description here
3. The resources referred to here involve what bucket name to create in your InfluxDB, what scheduled tasks and alarm tasks to create, what dashboard to create, etc. If you are on an InfluxDB that is in production and has similar businesses, you still need to take a good look at this list to avoid duplicate bucket names. After confirming that there is no problem, hit y and press Enter.

4. If the content displayed next ends with Stack ID: xxxx, it means the installation is successful! The concept of Stack here is actually an instance of a template.

Insert image description here

12.2.3 View installation results

1. Now, let’s open the Web UI of InfluxDB and take a look at the import effect of our template. The picture below is the bucket created by the template for us, named docker.

12.2.3.1 Buckets

1. There is a bucket named docker

Insert image description here

12.2.3.2 telegraf configuration

1. A Telegraf configuration file named Docker Monitor. This configuration file may need to be modified based on your Docker configuration.

Insert image description here

12.2.3.3 Dashboard

1. The template also helps us create a Docker dashboard, here.

Insert image description here

2. It’s just that we don’t have data in the current Bucket, so the charts in this column are not yet displayed.

Insert image description here

12.2.3.4 Alarm rules

1. The template also helps us set up 4 alarm rules. According to the description of the topic, they are

  • Container CPU usage exceeds 80% for 15 minutes
  • Container hard disk usage exceeds 80%
  • Container's memory usage exceeds 80% for 15 minutes
  • The container did not exit with status 0 (end normally).

Insert image description here

12.2.4 Run Telegraf to collect data

1. Now we need to use Telegraf to run the configuration file in the docker template. But before, we wrote a host_tel.sh start and stop script in the ~/bin directory. That file will ensure that there is only one telegraf globally. Therefore, in order to avoid confusion, we need to stop the previous telegraf now.

host_tel.sh stop

2. Next, we write a new script. Still in the ~/bin directory, create the docker_tel.sh file. Type the following.

#!/bin/bash
export INFLUX_TOKEN=h106QMEj47juNUco-6Top1Tzz0IeMh5MhBIDT8vUdv1R3BVeAzMvWGq2DtmJIcyuPwvPmHTLbZLTbnKxz3UKA==
export INFLUX_HOST=http://localhost:8086/
export INFLUX_ORG=atguigu
/opt/module/telegraf-1.23.4/usr/bin/telegraf --config http://localhost:8086/api/v2/telegrafs/09edf888eeeb6000

3. According to the requirements of the docker template, before running telegraf, we need to declare three variables, INFLUX_TOKEN, INFLUX_HOST and INFLUX_ORG. Then, we modify the execution permissions of docker_tel.sh. Finally, start docker_tel.sh

chmod 755 ./docker_tel.sh
./docker_tel.sh

4. As shown in the figure, telegraf starts successfully.

Insert image description here

12.2.5 View template effect

1. First, you can check whether there is data in the docker bucket in DataExplorer. As shown in the figure, the data has been successfully entered into InfluxDB.
Insert image description here
2. Next, we can take a look at the status of the dashboard. As shown below, the dashboard also displays data successfully.

Insert image description here

12.2.6 Running a docker container

1. Use the following command to run a docker entry container. If there is no docker/getting-started image on your host, then docker will go back to dockerhub to pull the image. Because this image is abroad, the speed may be very slow. If the pull fails, please use Baidu to replace the source. In addition, after the container is running, it will take some time for telegraf to collect data.

docker run -dp 80:80 docker/getting-started

12.2.7 View the dashboard again

1. As shown in the figure below, the number of our images and containers has changed from 0 to 1. And the system's memory usage has become higher.

Insert image description here

12.2.8 Delete stack (template instance)

1. On the Web UI, click the button on the left toolbar, and then click TEMPLATES above. You can see the list of installed templates, and there is a delete button on the right side of each last shift list, which can be quickly deleted in this way. After deletion, all resources involved in the stack will disappear.

Insert image description here

2. You can also delete it through influx-cli

influx stacks remove -o atguigu --stack-id=09ee 20 c 8 0d 692000

3. Influx-cli has full functions. You can also use it to rename a stack, or view all
stacks under an organization, etc.

12.3 Shortcomings of InfluxDB templates

12.3.1 FLUX Compatibility

1. We have seen before that many InfluxDB templates have FLUX language scripts embedded in them. However, the FLUX language versions compiled into different InfluxDBs are different. The most important thing is that the FLUX language is still in a period of rapid change, and the standard library has not yet been determined. Especially later versions of FLUX may discard functions and APIs in previous versions. This results in poor forward compatibility of the FLUX language.

2. The figure below shows the correspondence between the InfluxDB version and the FLUX language version.

Insert image description here

3. For example, the FLUX version of InfluxDB 2.4 is 0.179, and Influx2.0 is 0.131.0. Four iterations can make FLUX more than 40 versions different. The most typical one is the smaple-data template.

Insert image description here

4. It cannot be used after InfluxDB 2.3. If you load this template, you will be prompted that there is a problem with line 11 of the configuration file. This is actually because csv.from(url:xxx) in this template has been abandoned. In addition, the officially maintained template warehouse is in a state of "disrepair" and lacks maintenance. Therefore, you may need to manually modify the template yourself.

Insert image description here

Insert image description here

12.3.2 Ecology is not as good as Grafana

1. Grafana is a framework that specializes in monitoring dashboards. It supports setting monitoring tasks and supports multiple databases as data sources. The community activity is higher than that of InfluxDB, so there are richer and easier-to-use templates under the Grafana framework. Grafana also supports InfluxDB as a data source, so the InfluxDB+Grafana solution can be used in framework selection. In this way, InfluxDB is only responsible for reading and writing, and Grafana is responsible for data display and alarming. The picture below is a template provided by the Grafana community. It can be seen that after filtering, there are 1117 dashboards that support InfluxDB as a data source.

Insert image description here

2. On the other hand, InfluxDB cannot keep up with granfana in terms of templates, activity, and template updates.

Insert image description here

Guess you like

Origin blog.csdn.net/qq_38263083/article/details/131931530