Grafana can connect to InfluxDB because InfluxDB is a time-series database, and Grafana is a visualization tool designed to display data from time-series sources.

Here’s how you’d set it up and build a basic dashboard.

First, let’s imagine we have some InfluxDB data. We’ll use InfluxDB’s line protocol to write a few sample data points. This is how InfluxDB expects data to be formatted.

curl -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_usage,host=server1,region=us-west value=65.2,user=10.1,system=20.5'
curl -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_usage,host=server1,region=us-west value=67.8,user=11.5,system=21.0'
curl -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'memory_usage,host=server1,region=us-west percent=75.3'
curl -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_usage,host=server2,region=us-east value=55.0,user=8.2,system=15.1'

Now, let’s get Grafana running. If you don’t have it, you can install it via Docker:

docker run -d -p 3000:3000 --name grafana grafana/grafana

Once Grafana is up, navigate to http://localhost:3000 in your browser. The default login is admin/admin. You’ll be prompted to change the password.

The first step in Grafana is to add InfluxDB as a data source. Go to "Configuration" (the gear icon on the left sidebar) -> "Data sources" -> "Add data source".

Select "InfluxDB" from the list.

Now, configure the connection details:

  • Name: Give it a descriptive name, like MyInfluxDB.
  • Query Language: Select Flux if you’re using InfluxDB 2.x or later, or InfluxQL for InfluxDB 1.x. We’ll assume InfluxDB 1.x for simplicity here, so select InfluxQL.
  • URL: http://localhost:8086 (or wherever your InfluxDB instance is running).
  • Database: mydb (the database we wrote our sample data to).
  • User: (If you have authentication enabled on InfluxDB, enter your username).
  • Password: (If you have authentication enabled, enter your password).
  • Access: Server (default) is usually fine.

Click "Save & Test". You should see a "Data source is working" message.

With the data source connected, you can now create a dashboard. Click the "+" icon on the left sidebar -> "Dashboard" -> "Add new panel".

You’ll see a blank panel editor. On the right side, under "Query", ensure your MyInfluxDB data source is selected.

Let’s build a panel to show CPU usage. In the query editor, you’ll use InfluxQL.

  • Measurement: cpu_usage
  • Field(s): value
  • WHERE: You can add filters here. For example, host = server1.
  • GROUP BY: This is crucial for aggregation and time-series analysis.
    • Time: Select auto or a specific interval like 1m (1 minute). This tells Grafana how to group data points over time.
    • Tag(s): host (to see separate lines for different hosts if you didn’t filter them out).

The query might look something like this in the UI:

SELECT mean("value") FROM "cpu_usage" WHERE $timeFilter GROUP BY time($__interval)

Grafana automatically injects $timeFilter and $__interval based on the dashboard’s time range and the panel’s time grouping.

Under "Visualization" on the right, choose "Graph" (it’s often the default). You’ll see a line graph appear with your sample data.

You can customize the panel:

  • Title: "CPU Usage"

  • Units: Under "Standard options" -> "Unit", select Percent (0-100).

  • Legend: You can rename series here, e.g., {{host}} - CPU Value.

Save the panel by clicking "Apply" in the top right, and then save the dashboard itself by clicking the floppy disk icon.

To add another panel, for example, memory usage:

  • Add a new panel.
  • Select your MyInfluxDB data source.
  • Measurement: memory_usage
  • Field(s): percent
  • WHERE: host = server1
  • GROUP BY: Time auto, Tag host.

The query would be:

SELECT mean("percent") FROM "memory_usage" WHERE $timeFilter GROUP BY time($__interval)

Set the visualization to "Graph" and the Unit to "Percent (0-100)".

The most surprising thing about connecting InfluxDB to Grafana is how seamlessly the query editor adapts to the chosen data source, abstracting away much of the direct InfluxQL or Flux syntax for common operations. You can often build complex queries by just clicking through dropdowns for measurements, fields, and aggregations, with Grafana translating those selections into the appropriate query language behind the scenes.

When you’re building more complex dashboards, you’ll often find yourself using template variables. These allow you to create dropdowns at the top of your dashboard (e.g., for selecting a host or region) that dynamically update all the queries on your dashboard. To set this up, go to dashboard settings (gear icon on dashboard) -> "Variables" -> "Add variable". You’d create a variable named host, set its type to "Query", select your InfluxDB data source, and use a query like SHOW TAG VALUES FROM "cpu_usage" WITH KEY = "host". Then, in your panel queries, you’d replace a hardcoded host = 'server1' with host = '$host'.

The next step is often exploring InfluxDB’s Flux language for more advanced queries or learning how to use Grafana’s alerting features.

Want structured learning?

Take the full Influxdb course →