Grafana: Difference between revisions
All plugins can be provisioned |
Add intra-wiki links and document code example |
||
| Line 1: | Line 1: | ||
[https://grafana.com/ Grafana] is an open-source, general purpose dashboarding tool, which runs as a web application. It can be used to create a variety of time-series graphs and also for displaying logs. It supports Prometheus, graphite, InfluxDB, opentsdb, Grafana Loki, PostgreSQL and many other data sources. | [https://grafana.com/ Grafana] is an open-source, general purpose dashboarding tool, which runs as a web application. It can be used to create a variety of time-series graphs and also for displaying logs. It supports [[Prometheus]], graphite, InfluxDB, opentsdb, [[Grafana Loki]], [[PostgreSQL]] and many other data sources. | ||
See [https://search.nixos.org/options?query=services.grafana Grafana options] | See [https://search.nixos.org/options?query=services.grafana Grafana options]. | ||
== Installation == | == Installation == | ||
| Line 74: | Line 74: | ||
== Configuration == | == Configuration == | ||
Everything | Everything (data sources, users, dashboards, ...) can be configured either in the Web UI or provisioned as code using Nix. | ||
=== Via Web UI === | === Via Web UI === | ||
| Line 85: | Line 85: | ||
=== Declarative configuration === | === Declarative configuration === | ||
Grafana supports [https://grafana.com/docs/grafana/latest/administration/provisioning/ provisioning] data sources, dashboards and alerting using {{nixos:option|services.grafana.provision}}. Note that removing a provision and switching to the new NixOS configuration does not currently remove the provisioned items; you have to define them, for example, in <code>deleteDatasources</code>. | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 93: | Line 95: | ||
enable = true; | enable = true; | ||
# Creates a *mutable* dashboard provider, pulling from /etc/grafana-dashboards. | |||
# With this, you can manually provision dashboards from JSON with `environment.etc` like below. | |||
dashboards.settings.providers = [{ | dashboards.settings.providers = [{ | ||
name = "my dashboards"; | name = "my dashboards"; | ||
options | disableDeletion = true; | ||
options = { | |||
path = "/etc/grafana-dashboards"; | |||
foldersFromFilesStructure = true; | |||
}; | |||
}]; | }]; | ||
datasources.settings.datasources = [ | datasources.settings.datasources = [ | ||
# | # Provisioning a built-in data source | ||
{ | { | ||
name = "Prometheus"; | name = "Prometheus"; | ||
type = "prometheus"; | type = "prometheus"; | ||
url = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}"; | url = "http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}"; | ||
isDefault = true; | |||
editable = false; | |||
} | } | ||
# All plugins can | # All plugins can be provisioned but it's not always documented: https://github.com/fr-ser/grafana-sqlite-datasource/blob/main/docs/faq.md#can-i-use-provisioning-with-this-plugin | ||
# Compare below with https://grafana.com/docs/plugins/yesoreyeram-infinity-datasource/latest/setup/provisioning/ | # Compare below with https://grafana.com/docs/plugins/yesoreyeram-infinity-datasource/latest/setup/provisioning/ | ||
{ | { | ||
name = "Infinity"; | name = "Infinity"; | ||
type = "yesoreyeram-infinity-datasource"; | type = "yesoreyeram-infinity-datasource"; | ||
editable = false; | |||
} | } | ||
]; | ]; | ||
# Note: removing attributes from the above `datasources.settings.datasources` is not enough for them to be deleted | # Note: removing attributes from the above `datasources.settings.datasources` is not currently enough for them to be deleted; | ||
# One needs to use the following option: | # One needs to use the following option: | ||
# datasources.settings.deleteDatasources = [ { name = "foo"; orgId = 1; } { name = "bar"; orgId = 1; } ]; | # datasources.settings.deleteDatasources = [ { name = "foo"; orgId = 1; } { name = "bar"; orgId = 1; } ]; | ||
| Line 119: | Line 130: | ||
}; | }; | ||
environment.etc | # see `dashboards.settings.providers` above | ||
environment.etc."grafana-dashboards/some-dashboard.json".source = ./some-dashboard.json; | |||
</syntaxhighlight> | </syntaxhighlight> | ||