summary refs log tree commit diff
path: root/nixos/modules/services/monitoring
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2017-01-20 21:05:10 +0100
committerGitHub <noreply@github.com>2017-01-20 21:05:10 +0100
commit2b2b0b566d84254621f9ca537d5d91e2a9de9c68 (patch)
tree0acc9867f326b14c1e3a294a7657a5581584d7a2 /nixos/modules/services/monitoring
parent66c0b9d29281e5f7e64d6aba4a316e61db9b2d85 (diff)
parent2715222f0cca9327f896a2ec1ed2de0b7934ad17 (diff)
downloadnixlib-2b2b0b566d84254621f9ca537d5d91e2a9de9c68.tar
nixlib-2b2b0b566d84254621f9ca537d5d91e2a9de9c68.tar.gz
nixlib-2b2b0b566d84254621f9ca537d5d91e2a9de9c68.tar.bz2
nixlib-2b2b0b566d84254621f9ca537d5d91e2a9de9c68.tar.lz
nixlib-2b2b0b566d84254621f9ca537d5d91e2a9de9c68.tar.xz
nixlib-2b2b0b566d84254621f9ca537d5d91e2a9de9c68.tar.zst
nixlib-2b2b0b566d84254621f9ca537d5d91e2a9de9c68.zip
Merge pull request #20183 from womfoo/init/netdata-service
netdata service: init
Diffstat (limited to 'nixos/modules/services/monitoring')
-rw-r--r--nixos/modules/services/monitoring/netdata.nix78
1 files changed, 78 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/netdata.nix b/nixos/modules/services/monitoring/netdata.nix
new file mode 100644
index 000000000000..e1fde4fc9500
--- /dev/null
+++ b/nixos/modules/services/monitoring/netdata.nix
@@ -0,0 +1,78 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+  cfg = config.services.netdata;
+
+  configFile = pkgs.writeText "netdata.conf" cfg.configText;
+
+  defaultUser = "netdata";
+
+in {
+  options = {
+    services.netdata = {
+      enable = mkOption {
+        default = false;
+        type = types.bool;
+        description = "Whether to enable netdata monitoring.";
+      };
+
+      user = mkOption {
+        type = types.str;
+        default = "netdata";
+        description = "User account under which netdata runs.";
+      };
+
+      group = mkOption {
+        type = types.str;
+        default = "netdata";
+        description = "Group under which netdata runs.";
+      };
+
+      configText = mkOption {
+        type = types.lines;
+        default = "";
+        description = "netdata.conf configuration.";
+        example = ''
+          [global]
+          debug log = syslog
+          access log = syslog
+          error log = syslog
+        '';
+      };
+
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.netdata = {
+      description = "Real time performance monitoring";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+      preStart = concatStringsSep "\n" (map (dir: ''
+        mkdir -vp ${dir}
+        chmod 750 ${dir}
+        chown -R ${cfg.user}:${cfg.group} ${dir}
+        '') [ "/var/cache/netdata"
+              "/var/log/netdata"
+              "/var/lib/netdata" ]);
+      serviceConfig = {
+        User = cfg.user;
+        Group = cfg.group;
+        PermissionsStartOnly = true;
+        ExecStart = "${pkgs.netdata}/bin/netdata -D -c ${configFile}";
+        TimeoutStopSec = 60;
+      };
+    };
+
+    users.extraUsers = optional (cfg.user == defaultUser) {
+      name = defaultUser;
+    };
+
+    users.extraGroups = optional (cfg.group == defaultUser) {
+      name = defaultUser;
+    };
+
+  };
+}