pvv-nixos-config/hosts/ildkule/services/metrics/grafana.nix

87 lines
2.5 KiB
Nix
Raw Normal View History

{ config, pkgs, values, ... }: let
2022-12-20 21:44:22 +01:00
cfg = config.services.grafana;
in {
sops.secrets = let
owner = "grafana";
group = "grafana";
in {
"keys/grafana/secret_key" = { inherit owner group; };
"keys/grafana/admin_password" = { inherit owner group; };
"keys/postgres/grafana" = { inherit owner group; };
};
2022-12-19 22:56:42 +01:00
services.grafana = {
enable = true;
settings = let
# See https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#file-provider
secretFile = path: "$__file{${path}}";
in {
server = {
domain = "ildkule.pvv.ntnu.no";
http_port = 2342;
http_addr = "127.0.0.1";
};
security = {
secret_key = secretFile config.sops.secrets."keys/grafana/secret_key".path;
admin_password = secretFile config.sops.secrets."keys/grafana/admin_password".path;
};
database = {
type = "postgres";
user = "grafana";
host = "${values.hosts.bicep.ipv4}:5432";
password = secretFile config.sops.secrets."keys/postgres/grafana".path;
};
2022-12-19 22:56:42 +01:00
};
2022-12-20 00:26:29 +01:00
provision = {
enable = true;
datasources.settings.datasources = [
{
name = "Ildkule Prometheus";
type = "prometheus";
url = ("http://${config.services.prometheus.listenAddress}:${toString config.services.prometheus.port}");
isDefault = true;
}
{
name = "Ildkule loki";
type = "loki";
url = ("http://${config.services.loki.configuration.server.http_listen_address}:${toString config.services.loki.configuration.server.http_listen_port}");
}
2022-12-20 00:26:29 +01:00
];
2022-12-20 00:38:08 +01:00
dashboards.settings.providers = [
{
name = "Node Exporter Full";
type = "file";
url = "https://grafana.com/api/dashboards/1860/revisions/29/download";
options.path = dashboards/node-exporter-full.json;
}
2022-12-20 23:10:00 +01:00
{
name = "Matrix Synapse";
type = "file";
url = "https://raw.githubusercontent.com/matrix-org/synapse/develop/contrib/grafana/synapse.json";
options.path = dashboards/synapse.json;
}
2022-12-20 00:38:08 +01:00
];
2022-12-20 00:26:29 +01:00
};
2022-12-19 22:56:42 +01:00
};
2022-12-20 21:44:22 +01:00
services.nginx.virtualHosts.${cfg.settings.server.domain} = {
2022-12-20 15:58:12 +01:00
enableACME = true;
forceSSL = true;
2022-12-19 22:56:42 +01:00
locations = {
"/" = {
2022-12-20 21:44:22 +01:00
proxyPass = "http://127.0.0.1:${toString cfg.settings.server.http_port}";
2022-12-19 22:56:42 +01:00
proxyWebsockets = true;
extraConfig = ''
proxy_buffers 8 1024k;
proxy_buffer_size 1024k;
'';
};
};
};
}