diff --git a/modules/services/metrics.nix b/modules/services/metrics.nix index 27e0e8d..ecce2ac 100644 --- a/modules/services/metrics.nix +++ b/modules/services/metrics.nix @@ -10,13 +10,9 @@ in { type = types.str; default = "grafana.reidlab.pink"; }; - orgId = mkOption { - type = types.int; - default = 1; - }; - grafanaPort = mkOption { - type = types.int; - default = 3000; + grafanaSocket = mkOption { + type = types.str; + default = "/run/grafana/grafana.sock"; }; alloyPort = mkOption { type = types.int; @@ -43,19 +39,19 @@ in { settings = { server = { domain = cfg.domain; - http_port = cfg.grafanaPort; - http_addr = "127.0.0.1"; + protocol = "socket"; + socket = cfg.grafanaSocket; }; database.type = "sqlite3"; # TODO: use postgres? # use default secret key - # TODO: maybe don't do that idk + # TODO: maybe don't do that idk security.secret_key = "SW2YcwTIb9zpOOhoPsMm"; }; provision.datasources.settings = { + prune = true; # delete datasources if not in provision file datasources = [ { - orgId = cfg.orgId; name = "Prometheus"; type = "prometheus"; url = "http://127.0.0.1:${toString cfg.prometheusPort}"; @@ -63,23 +59,12 @@ in { isDefault = true; } { - orgId = cfg.orgId; name = "Loki"; type = "loki"; url = "http://127.0.0.1:${toString cfg.lokiPort}"; uid = "loki"; } ]; - deleteDatasources = [ - { - orgId = cfg.orgId; - name = "Prometheus"; - } - { - orgId = cfg.orgId; - name = "Loki"; - } - ]; }; }; @@ -89,6 +74,7 @@ in { ports = { node = mkPort 0; nginx = mkPort 1; + smartctl = mkPort 2; }; in { enable = true; @@ -105,6 +91,10 @@ in { enable = true; port = ports.nginx; }; + smartctl = { + enable = true; + port = ports.smartctl; + }; }; scrapeConfigs = let @@ -126,6 +116,13 @@ in { labels = commonLabels; }]; } + { + job_name = "smartctl"; + static_configs = [{ + targets = [ "127.0.0.1:${toString ports.smartctl}" ]; + labels = commonLabels; + }]; + } ]; }; @@ -246,7 +243,7 @@ in { forceSSL = true; enableACME = true; locations."/" = { - proxyPass = "http://127.0.0.1:${toString cfg.grafanaPort}"; + proxyPass = "http://unix:${cfg.grafanaSocket}"; proxyWebsockets = true; }; locations."= /robots.txt" = {