2014-12-28 19:21:41 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.cadvisor;
|
|
|
|
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.cadvisor = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
2014-12-30 02:31:03 +00:00
|
|
|
description = "Whether to enable cadvisor service.";
|
2014-12-28 19:21:41 +00:00
|
|
|
};
|
|
|
|
|
2015-12-23 23:14:40 +00:00
|
|
|
listenAddress = mkOption {
|
2014-12-28 19:21:41 +00:00
|
|
|
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 ''
|
2016-01-19 08:55:31 +00:00
|
|
|
until ${pkgs.curl.bin}/bin/curl -s -o /dev/null 'http://${cfg.listenAddress}:${toString cfg.port}/containers/'; do
|
2014-12-28 19:21:41 +00:00
|
|
|
sleep 1;
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''${pkgs.cadvisor}/bin/cadvisor \
|
|
|
|
-logtostderr=true \
|
2015-12-23 23:14:40 +00:00
|
|
|
-listen_ip=${cfg.listenAddress} \
|
2014-12-28 19:21:41 +00:00
|
|
|
-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"}
|
|
|
|
''}
|
|
|
|
'';
|
2016-09-16 21:06:16 +01:00
|
|
|
TimeoutStartSec=300;
|
2014-12-28 19:21:41 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-03-18 13:30:12 +00:00
|
|
|
virtualisation.docker.enable = mkDefault true;
|
2014-12-28 19:21:41 +00:00
|
|
|
};
|
|
|
|
}
|