Grafana is a data visualization and analysis tool that allows you to create interactive dashboards from multiple data sources.
With Grafana, you can create graphs, alerts, and custom panels that help you better understand the data and make informed decisions.
It is compatible with a wide variety of databases, including Prometheus, InfluxDB, Elasticsearch, and many others.
It is widely used for system monitoring, metric visualization, and data analysis.
How to Install Grafana
Before installing Grafana, it’s recommended that your system is up to date. To update your system, run:
sudo apt update
sudo apt upgrade
Now we need to add the Grafana repositories. First, we add the APT keys to authenticate the packages
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
We add the Grafana repository,
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
Finally, we can install Grafana
sudo apt update
sudo apt install -y grafana
Now we need to configure the Grafana service and enable it to start automatically when the Raspberry Pi boots:
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
We can verify that the installation is correct with the following command.
sudo systemctl status grafana-server
If everything is fine, we should see an output indicating that the service is active and running.
Accessing the Grafana Web Interface
Grafana runs through a web interface, which by default runs on port 3000. Open a web browser and access the Grafana interface,
http://127.0.0.1:3000
When you access it for the first time, you will be prompted to log in. The default credentials are:
- Username: admin
- Password: admin
The first time you log in to Grafana, it will ask you to change the admin password. Enter the password you want and then click on “Change Password”.
Once inside, you can start configuring your datasources and dashboards.
Configuring a DataSource
To visualize data in Grafana, we first need to connect it to a data source. Grafana supports a wide variety of data sources, including Prometheus, InfluxDB, and Graphite.
To connect Grafana to a data source:
- Go to the configuration page
- Click on “Add data source”.
- Select the type of data source you want to use
- Follow the instructions to configure the connection
Example with InfluxDB
Let’s see it with an example, along with an InfluxDB database. This is the typical setup for all tutorials, I know you love the Grafana + InfluxDB combo.
If you don’t know what InfluxDB is or how to use it, here’s a tutorial read more
Select to create a new DataSource, and choose InfluxDB. Here we change the following
- Name: Whatever you want
- Query language: Flux
- URL: http://localhost:8086
Further down, in authentication:
- Organization: Whatever you have set in InfluxDB
- Token: The token provided by InfluxDB
- Default Bucket: The name of the bucket (database) you want
Creating a Basic Dashboard
Once we have connected Grafana to a data source, we can start creating dashboards and visualizations. Grafana comes with an easy-to-use panel editor that allows us to add graphs, tables, and other visualizations to your dashboards.
To create a basic dashboard:
- In the Grafana interface, click the + sign in the side menu and select “Dashboard”.
- Add a new “Panel” and select the data source you have configured.
- Configure the visualizations and graphs according to your needs.
That’s how easy it is to create a dashboard! Go ahead, create your graphs and screens like crazy 😘