Grafana
easy 26 minGrafana is a web application that queries many kinds of stores, draws the answers on dashboards and evaluates alert rules on them.
Video lesson · Chapter 1 of 5
Two pictures on the station wall
Grafana in 90 seconds
1:30Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
Grafana is a server with a web interface. You tell it about data sources, such as a Prometheus server, a log store or a SQL database. A panel holds one or more queries and a way to draw the answer. A dashboard is a page of panels that share a time range and variables.
It is a reader. When you open a dashboard, the browser asks the Grafana server, the Grafana server asks each store in that store's own language, and the answers become charts. Grafana's own database holds only its things: dashboards, users, folders, alert rules, and the settings of the data sources.
The name is also a company, Grafana Labs, with other products such as Loki for logs, Tempo for traces and Mimir for metrics. This page is about Grafana, the dashboard server.
Why it exists
A system has several stores of facts about itself: metrics here, logs there, business numbers in a database. During an incident people need them side by side, over the same ten minutes. Copying everything into one store is expensive. Asking each store and drawing the answers together is cheap.
Charts are also a shared language. A dashboard in version control, with a variable for the service name, gives every team the same view. That is worth more than a private chart that only one person can read.
A short history
January 2014
Torkel Odegaard releases Grafana. Its interface began from Kibana 3, turned toward time series and easy editing.
2014
The company behind it is founded, first under the name Raintank.
April 2021
Grafana, Loki and Tempo change from the Apache 2.0 licence to AGPLv3. Plugins, agents and some libraries stay Apache licensed.
April 2026
Grafana 13: dynamic dashboards and Git Sync become generally available.
October 2026
Version 13.3, the newest minor release at the time of writing.
Words to know
- Data source
- A configured connection to a store: type, address, credentials.
- Panel
- One picture: queries, optional transformations, a visualization.
- Dashboard
- Panels with a shared time range, refresh rate and variables. Saved as JSON.
- Variable
- A value chosen at the top of a dashboard and used inside queries.
- Expression
- A calculation on query results in the Grafana server, for example reduce or math.
- Transformation
- A change to the result in the browser before drawing, for example joining two tables.
- Contact point
- Where an alert message goes: email, chat, a paging service, a webhook.
- Provisioning
- Data sources and dashboards defined in files that are read at start.
How it works
Step through the idea, or press Play.
Open. The browser loads a dashboard from Grafana's database
Understand it
Start here
The window-dresser
Imagine a street with three shops and one big display window. A window-dresser hangs pictures of what the shops have. The goods stay in the shops.
If the picture is wrong, look in the shop first.
The idea
What is inside and what is not
One reader, several stores
Data sources
Built in: Prometheus, Loki, Elasticsearch, Jaeger, Tempo, MySQL, PostgreSQL, Microsoft SQL Server, CloudWatch and more. Others as plugins.
Dashboards
Panels, variables, links and annotations on one time range.
Explore
A query page without a dashboard, for an investigation.
Alerting
Rules on any backend data source, with routing and silences.
Permissions
Organizations, folders and the roles Viewer, Editor and Admin.
As code
Files, Git Sync, Terraform, an operator for Kubernetes, or a library that builds dashboards.
Three editions
| Open source | Enterprise | Cloud | |
|---|---|---|---|
| Who runs it | You | You | Grafana Labs |
| Licence | AGPLv3 | Commercial, unlocks extra features | Subscription, with a free tier |
| Query caching | No | Yes | Yes |
| Permissions per data source | No | Yes | Yes |
| Dashboards and alerting | Yes | Yes | Yes |
Inside
The life of one panel
Opening a dashboard
- 1
Fill in
Variables and the time range are put into the query text.
- 2
Choose a step
Max data points is by default the panel's width in pixels. The interval follows: the range divided by that number.
- 3
Ask through the server
In proxy mode the browser never sees the store's password. The server adds it.
- 4
Same shape
Every plugin returns data frames: columns with names and types. That is why panels and stores can be mixed.
- 5
Transform and draw
Join, filter, rename, calculate, then draw. Transformations work on data that has already arrived.
Numbers
Points and load
Why a long range is not slower by itself
How much load do screens make?
min_refresh_interval can enforce it; its default is 5 seconds.Building
Variables instead of copies
Twelve services do not need twelve dashboards. A variable named service becomes a drop-down at the top, and every query uses it. A data source can be a variable too, so one dashboard serves staging and production.
# Requests per second of the chosen servicessum by (service) ( rate(http_requests_total{service=~"$service"}[$__rate_interval]))# 95th percentilehistogram_quantile(0.95, sum by (le) ( rate(http_request_seconds_bucket{service=~"$service"}[$__rate_interval])))=~ and not =.Built-in variables
| Name | Meaning | Use |
|---|---|---|
$__interval | The step that fits the panel | SQL grouping, averages of gauges |
$__rate_interval | max(interval + scrape interval, 4 x scrape interval) | Inside rate() and increase() |
$__range | The whole time range | One total for the page |
$__timeFilter(col) | A SQL condition for the time range | SQL data sources |
From overview to cause
A dashboard people use
- Answers one question, with the most important row on top
- Units and axis limits are set
- Errors as a share, not only a count
- A short text: what it is for and who owns it
- Links from alert to dashboard to logs
A wall of noise
- 60 panels that nobody can name
- Two axes with different units in one chart
- Averages of latency and no percentiles
- Copies with one small change
- Refresh every 5 seconds on data that changes hourly
Alerts
Rules that run without a screen
From rule to message
Grafana Alerting follows the Prometheus model: evaluating a rule and delivering a message are two jobs. A rule holds queries and expressions and one condition. If the query returns 12 series, the rule has 12 alert instances, each with its own state. Rules run in the server, so they need a data source with a backend, not a browser.
When the answer is missing
| State | Happens when | Choices |
|---|---|---|
| No Data | The query works but returns nothing | An alert of its own (default), treat as firing, normal, or keep the last state |
| Error | The store fails or times out | An alert of its own (default), treat as firing, normal, or keep the last state |
| Pending | The condition holds, but not yet long enough | The pending period |
Rules in Grafana
- Any supported store: logs, SQL, cloud metrics
- One page for all teams
- Edited next to the panel
Rules in Prometheus
- Work when Grafana is down
- Files, tests with promtool, review
- Only for Prometheus data
As code
Data sources and dashboards in files
# provisioning/datasources/main.yamlapiVersion: 1datasources: - name: Prometheus uid: prom-main type: prometheus access: proxy url: http://prometheus:9090 isDefault: true jsonData: timeInterval: 15s - name: Orders uid: orders-db type: postgres url: db-replica:5432 user: grafana_reader jsonData: database: orders sslmode: require secureJsonData: password: $ORDERS_DB_PASSWORD# provisioning/dashboards/main.yamlapiVersion: 1providers: - name: shop type: file allowUiUpdates: false updateIntervalSeconds: 30 options: path: /var/lib/grafana/dashboards foldersFromFilesStructure: trueallowUiUpdates: false people can try changes in the browser, but not save them over the file.| Way | Good for | Mind |
|---|---|---|
| Files (provisioning) | Containers, a fixed set | The file wins over changes in the browser |
| Git Sync | People edit in the browser, changes become commits or pull requests | Generally available since 13 |
| Terraform | Dashboards together with other infrastructure | State files |
| Foundation SDK | Many similar dashboards generated by a program | A build step |
| Browser only | Experiments | Keeps the last 20 versions, but no review |
Operate
Running it for a company
Two servers, one database
From one to two servers
- 1
Leave SQLite
The default database is a file. Two servers need MySQL 8.0 or newer, or PostgreSQL 12 or newer.
- 2
Put a balancer in front
Active-active. See load balancing.
- 3
Connect the alerting
Set
ha_peersso the servers gossip on port 9094, TCP and UDP. Otherwise people get every message twice. - 4
Know what is doubled
By default every server evaluates every rule, so the stores see the rule queries twice. A single-node evaluation mode exists. Duplicates can still happen: delivery is preferred over silence.
- 5
Same key everywhere
All servers need the same
secret_key, or they cannot read the stored passwords of data sources.
The project's size classes
| Class | Users at once | Alert rules | Dashboards |
|---|---|---|---|
| Small | Under 25 | Under 100 | Under 200 |
| Medium | 25 to 200 | 100 to 1,000 | 200 to 2,000 |
| Large | 200 or more | 1,000 or more | 2,000 or more |
More settings to change on day one: the first administrator is admin with password admin, cookie_secure is false until you set it, and port 3000 speaks plain HTTP. Put TLS in front, use single sign-on, and limit which addresses data sources may point to.
A panel is empty or slow
Decide
When to choose it, and when not
Choose Grafana when
- Data lives in several stores
- Prometheus, Loki or SQL need a common view
- Dashboards should be code
- You want to run it yourself or move between clouds
Look elsewhere when
- You need a place to store metrics: that is another product
- Business users need pivot tables and reports: use a BI tool
- Charts are part of your product for customers: draw them in your app
- One vendor should do collection, storage and screens: see Datadog
Neighbours
| Product | Alike | Different |
|---|---|---|
| Kibana, in the ELK Stack | Dashboards, exploring logs | Made for Elasticsearch; it does not query your other stores |
| Prometheus web page | Runs PromQL, draws a graph | For trying queries, not for saved dashboards |
| Datadog | Dashboards and alerts | Also collects and stores; a paid service |
| Jaeger web page | Shows traces | Only traces; Grafana can show them beside metrics |
Summary
The whole topic in one minute.
Grafana asks other stores and draws. It does not collect and, apart from its own settings, it does not keep. So a slow dashboard is usually a slow query, and an empty panel is usually a store that is down or a wrong time range.
Use variables instead of copies, keep dashboards as code, run two servers with one shared database, and decide on one place for alert rules. Remember that a user of an organization can by default send any query to any of its data sources.
- Grafana asks and draws. Measurements stay in their stores.
- Panel = queries + transformations + a picture. Dashboard = panels + time range + variables.
- Load = panels x open screens / refresh time.
- Use
$__rate_intervaland set the scrape interval. - Two servers need a shared database, gossip for alerts and the same secret key.
- Roles do not limit queries: limit the data source's account.
Sources
- Grafana: introduction
- Grafana: data sources
- Grafana: query and transform data
- Grafana: Prometheus template variables
- Grafana: install, sizes and databases
- Grafana: high availability
- Grafana: alerting high availability
- Grafana: security configuration
- Grafana: provisioning
- Grafana: when to upgrade
- Grafana Labs: relicensing to AGPLv3
- Grafana Labs: history of Grafana UX