summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/misc/ids.nix1
-rwxr-xr-xnixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/monitoring/cadvisor.nix106
3 files changed, 108 insertions, 0 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index bf8365e34645..ed9ff367977d 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -174,6 +174,7 @@
       chronos = 164;
       gitlab = 165;
       tox-bootstrapd = 166;
+      cadvisor = 167;
 
       # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
 
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 2c52ebb37bcb..503dd87ad4d9 100755
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -197,6 +197,7 @@
   ./services/misc/zookeeper.nix
   ./services/monitoring/apcupsd.nix
   ./services/monitoring/bosun.nix
+  ./services/monitoring/cadvisor.nix
   ./services/monitoring/collectd.nix
   ./services/monitoring/dd-agent.nix
   ./services/monitoring/graphite.nix
diff --git a/nixos/modules/services/monitoring/cadvisor.nix b/nixos/modules/services/monitoring/cadvisor.nix
new file mode 100644
index 000000000000..d9c165970eca
--- /dev/null
+++ b/nixos/modules/services/monitoring/cadvisor.nix
@@ -0,0 +1,106 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+  cfg = config.services.cadvisor;
+
+in {
+  options = {
+    services.cadvisor = {
+      enable = mkOption {
+        default = false;
+        type = types.bool;
+        description = "Wherther to enable cadvisor service.";
+      };
+
+      host = mkOption {
+        default = "127.0.0.1";
+        type = types.str;
+        description = "Cadvisor listening host";
+      };
+
+      port = mkOption {
+        default = 8080;
+        type = types.int;
+        description = "Cadvisor listening port";
+      };
+
+      storageDriver = mkOption {
+        default = null;
+        type = types.nullOr types.str;
+        example = "influxdb";
+        description = "Cadvisor storage driver.";
+      };
+
+      storageDriverHost = mkOption {
+        default = "localhost:8086";
+        type = types.str;
+        description = "Cadvisor storage driver host.";
+      };
+
+      storageDriverDb = mkOption {
+        default = "root";
+        type = types.str;
+        description = "Cadvisord storage driver database name.";
+      };
+
+      storageDriverUser = mkOption {
+        default = "root";
+        type = types.str;
+        description = "Cadvisor storage driver username.";
+      };
+
+      storageDriverPassword = mkOption {
+        default = "root";
+        type = types.str;
+        description = "Cadvisor storage driver password.";
+      };
+
+      storageDriverSecure = mkOption {
+        default = false;
+        type = types.bool;
+        description = "Cadvisor storage driver, enable secure communication.";
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.cadvisor = {
+      wantedBy = [ "multi-user.target" ];
+      after = [ "network.target" "docker.service" "influxdb.service" ];
+
+      postStart = mkBefore ''
+        until ${pkgs.curl}/bin/curl -s -o /dev/null 'http://${cfg.host}:${toString cfg.port}/containers/'; do
+          sleep 1;
+        done
+      '';
+
+      serviceConfig = {
+        ExecStart = ''${pkgs.cadvisor}/bin/cadvisor \
+          -logtostderr=true \
+          -listen_ip=${cfg.host} \
+          -port=${toString cfg.port} \
+          ${optionalString (cfg.storageDriver != null) ''
+            -storage_driver ${cfg.storageDriver} \
+            -storage_driver_user ${cfg.storageDriverHost} \
+            -storage_driver_db ${cfg.storageDriverDb} \
+            -storage_driver_user ${cfg.storageDriverUser} \
+            -storage_driver_password ${cfg.storageDriverPassword} \
+            ${optionalString cfg.storageDriverSecure "-storage_driver_secure"}
+          ''}
+        '';
+        User = "cadvisor";
+      };
+    };
+
+    virtualisation.docker.enable = true;
+
+    users.extraUsers = singleton {
+      name = "cadvisor";
+      uid = config.ids.uids.cadvisor;
+      description = "Cadvisor user";
+      extraGroups = [ "docker" ];
+    };
+  };
+}