Grafana
NotesLast but not least, it’s time to introduce Grafana, and use Prometheus (and later Loki) as data sources for dashboards.
Grafana needs a database of its own, for users, dashboards and settings. By default it uses SQLite, in its data directory, which is fine for a single instance, so give it a volume:
podman volume create grafana-volData sources#
You can add data sources in Grafana’s web interface, but it’s neater to “provision” them with a file, so they’re set up automatically, and are part of your configuration rather than something you click:
mkdir -p ~/volumes/grafana/provisioning/datasourcesapiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
- name: Loki
type: loki
access: proxy
url: http://loki:3100The URLs use container names, because Grafana is on the monitoring network too. access: proxy means Grafana’s server makes the requests, not your browser.
Now run Grafana:
podman run -d --name grafana --network monitoring-network -p 3000:3000 \
-v grafana-vol:/var/lib/grafana \
-v ~/volumes/grafana/provisioning:/etc/grafana/provisioning:Z \
docker.io/grafana/grafana:13.3.2In a browser, go to http://localhost:3000. The initial username and password are admin/admin, and it asks you to change the password on first login. Under Connections, Data sources, you’ll see Prometheus and Loki already set up. (Loki is added in a later section; until then, its connection test fails.)
To use PostgreSQL for Grafana’s own database instead of SQLite, for example to run more than one Grafana, set it with environment variables: -e GF_DATABASE_TYPE=postgres -e GF_DATABASE_HOST=local-postgres:5432 -e GF_DATABASE_NAME=grafana_db -e GF_DATABASE_USER=grafana_user -e GF_DATABASE_PASSWORD=.... Any setting in grafana.ini can be set this way, as GF_<SECTION>_<KEY>.
Dashboards#
Under Dashboards, New, Import, you can import ready-made dashboards from grafana.com/grafana/dashboards. For example, enter 1860 for “Node Exporter Full”, and choose the Prometheus data source. The node_exporter metrics spring to life:
You can add panels of your own with PromQL, for example the home page views per minute:
rate(home_page_hits_total[5m]) * 60Or requests per second for each page of the application:
sum by (handler) (rate(http_requests_total[5m]))