We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Post 68
Weather App 15 - Grafana
Published on: 2025-09-02
Tags:
elixir, Blog, Phoenix, Nerves, Weather App
Adding Grafana to Docker Compose
We now need to add in the Grafana user interface so that we can see a more user friendly version of the data. navigate back to the docker-compose.yml and add this.
services:
postgres:
...
grafana:
image: grafana/grafana:8.0.5
depends_on:
- postgres
ports:
- '3000:3000'
volumes:
- grafana-data:/var/lib/grafana
volumes:
...
grafana-data: {}
We now can stop and start the docker container. I ran into an issue here as we never created the database weather_tracker_dev. So I quicky verified if it was created
docker exec -it <container> psql -U postgres
# \l
then ran
# CREATE DATABASE weather_tracker_dev;
from within the database.
Once we are back and both the db and Gafana are running we can now configre the Grafana UI.
We need to add a data source (Docker) and then fill out the form as needed.
With the database connect to Grafana we should at least try and query the data before we make a UI. Head to explore and lets try a query
Ran into issue here with the database being live on the host machine but the grafana and docker not seeing the right database for weather_conditions
# This will reset the password for the grafana UI
docker exec -it <grafana_container_name> grafana-cli admin reset-admin-password <newpassword>
To deal with this we need to check to make sure the container is up
docker ps
Then we want to go into the docker container with this command
docker exec -it weather_tracker-postgres-1 psql -U postgres -d weather_tracker_dev
# to see all the databases
\dt
# To check the local version
psql -U postgres -d weather_tracker_dev
This was an issue so I did a lot of reasearch and found out that using localhost as the host in Grafana was causing issues as it was trying to find a host within its own "local" area. As docker will create its own container it wouldn't find it. replacing grafana:5432 with
weather_tracker-postgres-1:5432
it now watches the right place for the weather_conditions
We can now look at a graph of all the values as we update them
Just be sure that:
Time column: "timestamp"
SELECT -> Column: <data type>
WHERE -> Macro: $_timeFilter
FROM: weather_conditions
Creating a Weather Dashboard
There are a lot of built-in ways to create a dashboard within Grafana so let's get started.
Adding a Stat Panel
First start by adding in a row called Current Measurements
Then add in each data type as a Empty Panel then the type will be either a:
Stat
Gauge
Time Series
For each think about:
Max min for values
Units
Thresholds
Title
That is it you have done it. I want to try and create a site for this so I will work on that next.