2021-07-13 19:09:27 +02:00
|
|
|
# Grafana dashboards for all the things!
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
cfg = config.my.services.monitoring;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.services.monitoring = with lib; {
|
|
|
|
enable = mkEnableOption "monitoring";
|
|
|
|
|
|
|
|
grafana = {
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 9500;
|
|
|
|
example = 3001;
|
|
|
|
description = "Internal port";
|
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "ambroisie";
|
|
|
|
example = "admin";
|
|
|
|
description = "Admin username";
|
|
|
|
};
|
|
|
|
|
|
|
|
passwordFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "/var/lib/grafana/password.txt";
|
|
|
|
description = "Admin password stored in a file";
|
|
|
|
};
|
2023-07-17 12:58:29 +02:00
|
|
|
|
|
|
|
secretKeyFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "/var/lib/grafana/secret_key.txt";
|
|
|
|
description = "Secret key stored in a file";
|
|
|
|
};
|
2021-07-13 19:09:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
prometheus = {
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 9501;
|
|
|
|
example = 3002;
|
|
|
|
description = "Internal port";
|
|
|
|
};
|
2021-07-15 18:50:04 +02:00
|
|
|
|
|
|
|
scrapeInterval = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "15s";
|
|
|
|
example = "1m";
|
|
|
|
description = "Scrape interval";
|
|
|
|
};
|
2021-07-13 19:09:27 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.grafana = {
|
|
|
|
enable = true;
|
|
|
|
|
2022-10-26 14:15:34 +02:00
|
|
|
settings = {
|
|
|
|
server = {
|
|
|
|
domain = "monitoring.${config.networking.domain}";
|
|
|
|
root_url = "https://monitoring.${config.networking.domain}/";
|
|
|
|
http_port = cfg.grafana.port;
|
|
|
|
http_addr = "127.0.0.1"; # Proxied through Nginx
|
|
|
|
};
|
|
|
|
|
|
|
|
security = {
|
|
|
|
admin_user = cfg.grafana.username;
|
|
|
|
admin_password = "$__file{${cfg.grafana.passwordFile}}";
|
2023-07-17 12:58:29 +02:00
|
|
|
secret_key = "$__file{${cfg.grafana.secretKeyFile}}";
|
2022-10-26 14:15:34 +02:00
|
|
|
};
|
2021-07-13 19:09:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
provision = {
|
|
|
|
enable = true;
|
|
|
|
|
2022-10-26 14:15:34 +02:00
|
|
|
datasources.settings.datasources = [
|
2021-07-13 19:09:27 +02:00
|
|
|
{
|
|
|
|
name = "Prometheus";
|
|
|
|
type = "prometheus";
|
|
|
|
url = "http://localhost:${toString cfg.prometheus.port}";
|
2021-07-15 18:50:04 +02:00
|
|
|
jsonData = {
|
|
|
|
timeInterval = cfg.prometheus.scrapeInterval;
|
|
|
|
};
|
2021-07-13 19:09:27 +02:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2022-10-26 14:15:34 +02:00
|
|
|
dashboards.settings.providers = [
|
2021-07-13 19:09:27 +02:00
|
|
|
{
|
|
|
|
name = "Node Exporter";
|
2021-07-29 13:17:42 +02:00
|
|
|
options.path = pkgs.nur.repos.alarsyo.grafanaDashboards.node-exporter;
|
2021-07-13 19:09:27 +02:00
|
|
|
disableDeletion = true;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.prometheus = {
|
|
|
|
enable = true;
|
|
|
|
port = cfg.prometheus.port;
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
|
|
|
|
retentionTime = "2y";
|
|
|
|
|
|
|
|
exporters = {
|
|
|
|
node = {
|
|
|
|
enable = true;
|
|
|
|
enabledCollectors = [ "systemd" ];
|
|
|
|
port = 9100;
|
|
|
|
listenAddress = "127.0.0.1";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-07-15 18:50:04 +02:00
|
|
|
globalConfig = {
|
|
|
|
scrape_interval = cfg.prometheus.scrapeInterval;
|
|
|
|
};
|
|
|
|
|
2021-07-13 19:09:27 +02:00
|
|
|
scrapeConfigs = [
|
|
|
|
{
|
|
|
|
job_name = config.networking.hostName;
|
|
|
|
static_configs = [{
|
|
|
|
targets = [ "127.0.0.1:${toString config.services.prometheus.exporters.node.port}" ];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-12-25 19:25:08 +01:00
|
|
|
my.services.nginx.virtualHosts = {
|
|
|
|
monitoring = {
|
2021-08-24 23:05:10 +02:00
|
|
|
inherit (cfg.grafana) port;
|
2023-12-25 19:25:08 +01:00
|
|
|
};
|
|
|
|
};
|
2021-11-05 15:40:29 +01:00
|
|
|
|
|
|
|
my.system.persist.directories = [
|
|
|
|
config.services.grafana.dataDir
|
|
|
|
"/var/lib/${config.services.prometheus.stateDir}"
|
|
|
|
];
|
2021-07-13 19:09:27 +02:00
|
|
|
};
|
|
|
|
}
|