Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grafana tweaks and fixes #764

Merged
merged 7 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions cmd/incusd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,13 +788,24 @@ func (d *Daemon) setupLoki(URL string, cert string, key string, caCert string, i
return err
}

// Figure out the instance name.
if instanceName == "" {
// Handle standalone systems.
var location string
if !d.serverClustered {
hostname, err := os.Hostname()
if err != nil {
return err
}

location = hostname
if instanceName == "" {
instanceName = hostname
}
} else if instanceName == "" {
instanceName = d.serverName
}

// Start a new client.
d.lokiClient = loki.NewClient(d.shutdownCtx, u, cert, key, caCert, instanceName, logLevel, labels, types)
d.lokiClient = loki.NewClient(d.shutdownCtx, u, cert, key, caCert, instanceName, location, logLevel, labels, types)

// Attach the new client to the log handler.
d.internalListener.AddHandler("loki", d.lokiClient.HandleEvent)
Expand Down
21 changes: 17 additions & 4 deletions doc/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ After editing the configuration, restart Prometheus (for example, `systemctl res
## Set up a Grafana dashboard

To visualize the metrics data, set up [Grafana](https://grafana.com/).
Incus provides a [Grafana dashboard](https://grafana.com/grafana/dashboards/19727-incus/) that is configured to display the Incus metrics scraped by Prometheus.
Incus provides a [Grafana dashboard](https://grafana.com/grafana/dashboards/19727-incus/) that is configured to display the Incus metrics scraped by Prometheus and log entries from Loki.

```{note}
The dashboard requires Grafana 8.4 or later.
Expand All @@ -258,7 +258,7 @@ See the Grafana documentation for instructions on installing and signing in:

Complete the following steps to import the [Incus dashboard](https://grafana.com/grafana/dashboards/19727-incus/):

1. Configure Prometheus as the data source:
1. Configure Prometheus as a data source:

1. Go to {guilabel}`Configuration` > {guilabel}`Data sources`.
1. Click {guilabel}`Add data source`.
Expand All @@ -269,12 +269,20 @@ Complete the following steps to import the [Incus dashboard](https://grafana.com

![Select Prometheus as the data source](images/grafana_select_prometheus.png)

1. In the {guilabel}`URL` field, enter `http://localhost:9090/`.
1. In the {guilabel}`URL` field, enter `http://localhost:9090/` if running Prometheus locally.

![Enter Prometheus URL](images/grafana_configure_datasource.png)

1. Keep the default configuration for the other fields and click {guilabel}`Save & test`.

1. Configure Loki as a data source:

1. Go to {guilabel}`Configuration` > {guilabel}`Data sources`.
1. Click {guilabel}`Add data source`.
1. Select {guilabel}`Loki`.
1. In the {guilabel}`URL` field, enter `http://localhost:3100/` if running Loki locally.
1. Keep the default configuration for the other fields and click {guilabel}`Save & test`.

1. Import the Incus dashboard:

1. Go to {guilabel}`Dashboards` > {guilabel}`Browse`.
Expand All @@ -287,7 +295,7 @@ Complete the following steps to import the [Incus dashboard](https://grafana.com
![Enter the Incus dashboard ID](images/grafana_dashboard_id.png)

1. Click {guilabel}`Load`.
1. In the {guilabel}`Incus` drop-down menu, select the Prometheus data source that you configured.
1. In the {guilabel}`Incus` drop-down menu, select the Prometheus and Loki data sources that you configured.

![Select the Prometheus data source](images/grafana_dashboard_select_datasource.png)

Expand All @@ -301,3 +309,8 @@ You can select the project and filter by instances.
At the bottom of the page, you can see data for each instance.

![Instance data in the Incus Grafana dashboard](images/grafana_instances.png)

```{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.
```
Loading
Loading