Set up a Grafana dashboard

To visualize the metrics and logs data, set up Grafana. LXD provides a Grafana dashboard that is configured to display the LXD metrics scraped by Prometheus and events sent to Loki.

Note

The dashboard requires Grafana 8.4 or later.

See the Grafana documentation for instructions on installing and signing in:

Complete the following steps to import the LXD dashboard:

  1. Configure Prometheus as a data source:

    1. From the Basic (quick setup) panel, choose Data Sources.

      Choose data source in Grafana

    2. Select Prometheus.

      Select Prometheus as a data source

    3. In the URL field, enter the address of your Prometheus installation (http://localhost:9090/ if running Prometheus locally).

      Enter Prometheus URL

    4. Keep the default configuration for the other fields and click Save & test.

  2. Configure Loki as another data source:

    1. Select Loki.

      Select Loki as another data source

    2. In the URL field, enter the address of your Loki installation (http://localhost:3100/ if running Loki locally).

      Enter Loki URL

    3. Keep the default configuration for the other fields and click Save & test.

  3. Import the LXD dashboard:

    1. Go back to the Basic (quick setup) panel and now choose Dashboards > Import a dashboard.

    2. In the Find and import dashboards field, enter the dashboard ID 19131.

      Enter the LXD dashboard ID

    3. Click Load.

    4. In the LXD drop-down menu, select the Prometheus and Loki data sources that you configured.

      Select the Prometheus data source

    5. Click Import.

You should now see the LXD dashboard. You can select the project and filter by instances.

Resource overview in the LXD Grafana dashboard

At the bottom of the page, you can see data for each instance.

Instance data in the LXD Grafana dashboard

Note

For proper operation of the Loki part of the dashboard, you need to ensure that the instance field matches the Prometheus job name. You can change the instance field through the loki.instance configuration key.

The Prometheus job_name value can be found in /var/snap/prometheus/current/prometheus.yml (if you are using the snap) or /etc/prometheus/prometheus.yaml (otherwise).

To set the loki.instance configuration key, run the following command: lxc config set loki.instance=<job_name_value>

You can check that setting via: lxc config get loki.instance