How to Set Up InfluxDB and Grafana with Docker Compose

InfluxDB and Grafana are powerful tools used for storing, querying, and visualizing time-series data. Docker Compose allows you to define and manage multi-container Docker applications. In this tutorial, we’ll walk you through the process of setting up InfluxDB and Grafana using Docker Compose, enabling you to efficiently monitor and visualize your time-series data.

Before we begin, ensure that you have Docker and Docker Compose installed on your machine. You can download them from the official Docker website.

Create a Project Directory: Create a new directory for your project and navigate to it using the terminal:

mkdir influxdb-grafana-setup
cd influxdb-grafana-setup

Create a Docker Compose File: Inside your project directory, create a file named docker-compose.yml and open it in a text editor of your choice:

touch docker-compose.yml

Define Services for InfluxDB and Grafana: In the docker-compose.yml file, define the services for InfluxDB and Grafana:

version: '3'
services:
  influxdb:
    image: influxdb
    container_name: influxdb
    ports:
      - "8086:8086"
    volumes:
      - influxdb-data:/var/lib/influxdb

  grafana:
    image: grafana/grafana
    container_name: grafana
    ports:
      - "3000:3000"
    depends_on:
      - influxdb
    volumes:
      - grafana-data:/var/lib/grafana

Define Volumes: Define the volumes at the bottom of the docker-compose.yml file:

volumes:
  influxdb-data:
  grafana-data:

Start Containers: Save the docker-compose.yml file and run the following command to start the containers:

docker-compose up -d

Access Grafana Web Interface: Open a web browser and navigate to http://localhost:3000. Log in using the default credentials (username: admin, password: admin). You’ll be prompted to change the password upon first login.

Add InfluxDB Data Source: Inside Grafana, click on the gear icon (⚙️) on the left sidebar to access the configuration menu. Select “Data Sources” and then click on “Add data source.” Search for “InfluxDB” and fill in the following details:

  • Name: Give your data source a name.
  • HTTP URL: http://influxdb:8086
  • Database: The name of your InfluxDB database (default is telegraf).
  • User: InfluxDB username.
  • Password: InfluxDB password.
  • HTTP Access: Server (default)

Click on “Save & Test” to verify the connection.

Create a Dashboard: Now, it’s time to create a dashboard to visualize your data. Click on the plus icon (+) on the left sidebar, then select “Dashboard.” Inside the dashboard, click on “Add new panel” and choose the visualization type you want (such as Graph, Singlestat, Table, etc.).

Query and Visualize Data: Configure your panel by selecting the InfluxDB data source you added earlier and specifying the query you want to visualize. Customize the visualization settings according to your needs.

Save and Share Dashboard: Once you’ve configured your panel, click on the disk icon to save the dashboard. Give your dashboard a meaningful name and you can even organize it into folders.

Conclusion: Congratulations! You’ve successfully set up InfluxDB and Grafana using Docker Compose. This powerful combination allows you to store, query, and visualize time-series data efficiently. You can now explore various data sources, queries, and visualization options to gain valuable insights from your data.

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment