about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-04-06 12:35:39 -0700
committerFranck Cuny <franck@fcuny.net>2022-04-06 12:35:39 -0700
commite3d4144cf9b17424d8c684ccd9c94b67f7e7e203 (patch)
tree9454aa88f4929473cbe595c4161aefc30dcfd12b
parentrefactor prometheus as a module (diff)
downloadworld-e3d4144cf9b17424d8c684ccd9c94b67f7e7e203.tar.gz
refactor grafana as a module
-rw-r--r--hosts/common/server/grafana.nix41
-rw-r--r--hosts/profiles/nas.nix2
-rw-r--r--modules/services/grafana/dashboards/fly-app_rev1.json (renamed from hosts/common/server/dashboards/fly-app_rev1.json)0
-rw-r--r--modules/services/grafana/dashboards/nas.json (renamed from hosts/common/server/dashboards/nas.json)0
-rw-r--r--modules/services/grafana/dashboards/node-exporter.json (renamed from hosts/common/server/dashboards/node-exporter.json)0
-rw-r--r--modules/services/grafana/dashboards/rtr.json (renamed from hosts/common/server/dashboards/rtr.json)0
-rw-r--r--modules/services/grafana/dashboards/traefik_rev5.json (renamed from hosts/common/server/dashboards/traefik_rev5.json)0
-rw-r--r--modules/services/grafana/default.nix47
8 files changed, 48 insertions, 42 deletions
diff --git a/hosts/common/server/grafana.nix b/hosts/common/server/grafana.nix
deleted file mode 100644
index 474c4e2..0000000
--- a/hosts/common/server/grafana.nix
+++ /dev/null
@@ -1,41 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-{
-  services.grafana = {
-    enable = true;
-    # Bind to all interfaces.
-    addr = "";
-    security.adminUser = "fcuny";
-
-    analytics.reporting.enable = false;
-
-    provision = {
-      enable = true;
-      datasources = [{
-        name = "prometheus";
-        type = "prometheus";
-        isDefault = true;
-        url = "http://localhost:9090";
-      }];
-      dashboards = [{
-        disableDeletion = true;
-        options.path = ./dashboards;
-      }];
-    };
-  };
-
-  age.secrets.restic-repo-systems.file =
-    ../../../secrets/restic/repo-systems.age;
-
-  services.restic.backups = {
-    grafana = {
-      paths = [ "/var/lib/grafana/data" ];
-      repository = "/data/slow/backups/systems";
-      passwordFile = config.age.secrets.restic-repo-systems.path;
-      timerConfig = { OnCalendar = "00:05"; };
-      initialize = true;
-      extraBackupArgs = [ "--tag grafana" ];
-      pruneOpts = [ "--keep-daily 7" "--keep-weekly 4" ];
-    };
-  };
-}
diff --git a/hosts/profiles/nas.nix b/hosts/profiles/nas.nix
index bf5f772..bcc221c 100644
--- a/hosts/profiles/nas.nix
+++ b/hosts/profiles/nas.nix
@@ -2,7 +2,6 @@
   imports = [
     # other profiles
     ./server.nix
-    ../common/server/grafana.nix
     ../common/server/traefik.nix
     ../common/server/transmission.nix
     ../common/server/gitea.nix
@@ -27,6 +26,7 @@
     };
     unifi = { enable = true; };
     prometheus = { enable = true; };
+    grafana = { enable = true; };
   };
 
   services.restic.backups = {
diff --git a/hosts/common/server/dashboards/fly-app_rev1.json b/modules/services/grafana/dashboards/fly-app_rev1.json
index 5894078..5894078 100644
--- a/hosts/common/server/dashboards/fly-app_rev1.json
+++ b/modules/services/grafana/dashboards/fly-app_rev1.json
diff --git a/hosts/common/server/dashboards/nas.json b/modules/services/grafana/dashboards/nas.json
index 61daa3b..61daa3b 100644
--- a/hosts/common/server/dashboards/nas.json
+++ b/modules/services/grafana/dashboards/nas.json
diff --git a/hosts/common/server/dashboards/node-exporter.json b/modules/services/grafana/dashboards/node-exporter.json
index 44356fa..44356fa 100644
--- a/hosts/common/server/dashboards/node-exporter.json
+++ b/modules/services/grafana/dashboards/node-exporter.json
diff --git a/hosts/common/server/dashboards/rtr.json b/modules/services/grafana/dashboards/rtr.json
index 75f1598..75f1598 100644
--- a/hosts/common/server/dashboards/rtr.json
+++ b/modules/services/grafana/dashboards/rtr.json
diff --git a/hosts/common/server/dashboards/traefik_rev5.json b/modules/services/grafana/dashboards/traefik_rev5.json
index b39b8c5..b39b8c5 100644
--- a/hosts/common/server/dashboards/traefik_rev5.json
+++ b/modules/services/grafana/dashboards/traefik_rev5.json
diff --git a/modules/services/grafana/default.nix b/modules/services/grafana/default.nix
new file mode 100644
index 0000000..5d67bc1
--- /dev/null
+++ b/modules/services/grafana/default.nix
@@ -0,0 +1,47 @@
+{ config, lib, pkgs, ... }:
+let cfg = config.my.services.grafana;
+in {
+  options.my.services.grafana = with lib; {
+    enable = mkEnableOption "grafana observability stack";
+  };
+
+  config = lib.mkIf cfg.enable {
+    services.grafana = {
+      enable = true;
+      # Bind to all interfaces.
+      addr = "";
+      security.adminUser = "fcuny";
+
+      analytics.reporting.enable = false;
+
+      provision = {
+        enable = true;
+        datasources = [{
+          name = "prometheus";
+          type = "prometheus";
+          isDefault = true;
+          url = "http://localhost:9090";
+        }];
+        dashboards = [{
+          disableDeletion = true;
+          options.path = ./dashboards;
+        }];
+      };
+    };
+
+    age.secrets.restic-repo-systems.file =
+      ../../../secrets/restic/repo-systems.age;
+
+    services.restic.backups = {
+      grafana = {
+        paths = [ "/var/lib/grafana/data" ];
+        repository = "/data/slow/backups/systems";
+        passwordFile = config.age.secrets.restic-repo-systems.path;
+        timerConfig = { OnCalendar = "00:05"; };
+        initialize = true;
+        extraBackupArgs = [ "--tag grafana" ];
+        pruneOpts = [ "--keep-daily 7" "--keep-weekly 4" ];
+      };
+    };
+  };
+}