How To Setup InfluxDB & Telegraf On Docker

Lahaul Seth
4 min readMar 15, 2021

--

InfluxDB is a time series database which helps in infrastructure monitoring and analysis in real time. Telegraf is an InfluxDB plugin which acts as an agent for collecting, processing, aggregating and writing metrics.

You can also check out the below 2 articles which I wrote previously.

#1. Pull InfluxDB & Telegraf images from Docker Hub

To get started, use the below commands.

 $ docker pull influxdb $ docker pull telegraf

This will pull the latest docker images.

$ docker images -a
REPOSITORY TAG IMAGE ID CREATED SIZE
influxdb latest 3266e99d927f 44 hours ago 283MB
telegraf latest d6dbb36abe4f 2 days ago 281MB

#2. Create a new Docker network bridge

InfluxDB and Telegraf would run in it’s separate container within Docker. To enable Telegraf to communicate with InfluxDB, you will need to create a new network bridge so that both the containers run on the same network.

Use the below command.

$ docker network create --driver bridge influxdb-telegraf

To verify that the bridge has been created, use the below command.

$ docker network inspect influxdb-telegraf
[
{
"Name": "influxdb-telegraf",
"Id": "22271089b8a0f1f5c842ccb74b23b88f8245c28c05d99d22b8cb67e105ecc697",
"Created": "2021-03-15T11:41:13.880850947+05:30",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.19.0.0/16",
"Gateway": "172.19.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]

#3. Run InfluxDB & Telegraf with the new bridge

The next step is to run the containers using the new network bridge.

Use the below commands.

$ docker run --network=influxdb-telegraf -d -P --name=influxdb influxdb
$ docker run --network=influxdb-telegraf -d -P --name=telegraf telegraf

To check if the containers are running, use the below command.

$ docker ps -a 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
564df335fef0 telegraf "/entrypoint.sh tele…" About a minute ago Up About a minute 0.0.0.0:49154->8092/udp, 0.0.0.0:49154->8094/tcp, 0.0.0.0:49153->8125/udp telegraf
bbfae1bee680 influxdb "/entrypoint.sh infl…" 3 minutes ago Up 3 minutes 0.0.0.0:49153->8086/tcp influxdb

Use the below command again to check if both the containers are running on the new bridge.

$ docker network inspect influxdb-telegraf
[
{
"Name": "influxdb-telegraf",
"Id": "22271089b8a0f1f5c842ccb74b23b88f8245c28c05d99d22b8cb67e105ecc697",
"Created": "2021-03-15T11:41:13.880850947+05:30",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.19.0.0/16",
"Gateway": "172.19.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"564df335fef0fc300c0a985491e455044bf6ef270d2f677bf5d3182c8320b887": {
"Name": "telegraf",
"EndpointID": "3538a99afb28cf69f775bb6f435d64de4fa801dd137728838e7234158fca8984",
"MacAddress": "02:42:ac:13:00:03",
"IPv4Address": "172.19.0.3/16",
"IPv6Address": ""
},
"bbfae1bee68002323e38eebecccc4eeeff2b1373515370ef803e14d3def7d4f1": {
"Name": "influxdb",
"EndpointID": "ef3197219cef419d985c156f17c8a06a34c14a0c7a4516d494ba8339385dbddd",
"MacAddress": "02:42:ac:13:00:02",
"IPv4Address": "172.19.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]

#4. Setup InfluxDB & Telegraf

The next step is to use the Docker container IP and open the front end of InfluxDB.

The initial page looks something like below.

The next thing that you can do is create a new bucket and add data configuration.

If you’re looking to monitor only system metrics, you can select System.

The next step that you need to do is export the influx token and start the Telegraf service. To login to bash of the container, use the below command.

$ docker exec -it <container id> /bin/bash

Use the below commands to start the service -

$ export INFLUX_TOKEN=<INFLUX_TOKEN> 
$ telegraf --config http://172.19.0.2:8086/api/v2/telegrafs/<id>

Once the service starts running, you should be able to view the data in the dashboard.

InfluxDB along with Telegraf provides a range of monitoring options. So, make sure to check them out.

So, that’s it for this tutorial. Stay tuned for more.

Originally published at https://www.lionbloggertech.com on March 15, 2021.

--

--

Lahaul Seth

I currently work as a Software Engineer. I’m an Open Source Enthusiast. I also like to write articles on digital marketing and SEO.