git.iko.soy/typeable/nixpkgs
on master help sign in
nixos: add cadvisor service
commitb6198f08e3cdbf607d9bcae4ddc2a836c59be2eb authorJaka Hudoklin <jakahudoklin@gmail.com> dateSun 28 Dec 2014, 20:21 (12 years ago) parentb232395
5 files changed+139
nixos/modules/misc/ids.nix+1 nixos/modules/module-list.nix+1 nixos/modules/services/monitoring/cadvisor.nix+106 nixos/release.nix+1 nixos/tests/cadvisor.nix+30
nixos/modules/misc/ids.nix+1
@@ -174,6 +174,7 @@
174174 chronos = 164;
175175 gitlab = 165;
176176 tox-bootstrapd = 166;
177+ cadvisor = 167;
177178
178179 # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
179180
nixos/modules/module-list.nix+1
@@ -197,6 +197,7 @@
197197 ./services/misc/zookeeper.nix
198198 ./services/monitoring/apcupsd.nix
199199 ./services/monitoring/bosun.nix
200+ ./services/monitoring/cadvisor.nix
200201 ./services/monitoring/collectd.nix
201202 ./services/monitoring/dd-agent.nix
202203 ./services/monitoring/graphite.nix
nixos/modules/services/monitoring/cadvisor.nixnew file+106
@@ -0,0 +1,106 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.cadvisor;
7+
8+in {
9+ options = {
10+ services.cadvisor = {
11+ enable = mkOption {
12+ default = false;
13+ type = types.bool;
14+ description = "Wherther to enable cadvisor service.";
15+ };
16+
17+ host = mkOption {
18+ default = "127.0.0.1";
19+ type = types.str;
20+ description = "Cadvisor listening host";
21+ };
22+
23+ port = mkOption {
24+ default = 8080;
25+ type = types.int;
26+ description = "Cadvisor listening port";
27+ };
28+
29+ storageDriver = mkOption {
30+ default = null;
31+ type = types.nullOr types.str;
32+ example = "influxdb";
33+ description = "Cadvisor storage driver.";
34+ };
35+
36+ storageDriverHost = mkOption {
37+ default = "localhost:8086";
38+ type = types.str;
39+ description = "Cadvisor storage driver host.";
40+ };
41+
42+ storageDriverDb = mkOption {
43+ default = "root";
44+ type = types.str;
45+ description = "Cadvisord storage driver database name.";
46+ };
47+
48+ storageDriverUser = mkOption {
49+ default = "root";
50+ type = types.str;
51+ description = "Cadvisor storage driver username.";
52+ };
53+
54+ storageDriverPassword = mkOption {
55+ default = "root";
56+ type = types.str;
57+ description = "Cadvisor storage driver password.";
58+ };
59+
60+ storageDriverSecure = mkOption {
61+ default = false;
62+ type = types.bool;
63+ description = "Cadvisor storage driver, enable secure communication.";
64+ };
65+ };
66+ };
67+
68+ config = mkIf cfg.enable {
69+ systemd.services.cadvisor = {
70+ wantedBy = [ "multi-user.target" ];
71+ after = [ "network.target" "docker.service" "influxdb.service" ];
72+
73+ postStart = mkBefore ''
74+ until ${pkgs.curl}/bin/curl -s -o /dev/null 'http://${cfg.host}:${toString cfg.port}/containers/'; do
75+ sleep 1;
76+ done
77+ '';
78+
79+ serviceConfig = {
80+ ExecStart = ''${pkgs.cadvisor}/bin/cadvisor \
81+ -logtostderr=true \
82+ -listen_ip=${cfg.host} \
83+ -port=${toString cfg.port} \
84+ ${optionalString (cfg.storageDriver != null) ''
85+ -storage_driver ${cfg.storageDriver} \
86+ -storage_driver_user ${cfg.storageDriverHost} \
87+ -storage_driver_db ${cfg.storageDriverDb} \
88+ -storage_driver_user ${cfg.storageDriverUser} \
89+ -storage_driver_password ${cfg.storageDriverPassword} \
90+ ${optionalString cfg.storageDriverSecure "-storage_driver_secure"}
91+ ''}
92+ '';
93+ User = "cadvisor";
94+ };
95+ };
96+
97+ virtualisation.docker.enable = true;
98+
99+ users.extraUsers = singleton {
100+ name = "cadvisor";
101+ uid = config.ids.uids.cadvisor;
102+ description = "Cadvisor user";
103+ extraGroups = [ "docker" ];
104+ };
105+ };
106+}
nixos/release.nix+1
@@ -242,6 +242,7 @@ in rec {
242242 tests.avahi = callTest tests/avahi.nix {};
243243 tests.bittorrent = callTest tests/bittorrent.nix {};
244244 tests.blivet = callTest tests/blivet.nix {};
245+ tests.cadvisor = scrubDrv (import tests/cadvisor.nix { system = "x86_64-linux"; });
245246 tests.chromium = callTest tests/chromium.nix {};
246247 tests.cjdns = callTest tests/cjdns.nix {};
247248 tests.containers = callTest tests/containers.nix {};
nixos/tests/cadvisor.nixnew file+30
@@ -0,0 +1,30 @@
1+import ./make-test.nix {
2+ name = "cadvisor";
3+
4+ nodes = {
5+ machine = { config, pkgs, ... }: {
6+ services.cadvisor.enable = true;
7+ };
8+
9+ influxdb = { config, pkgs, lib, ... }: with lib; {
10+ services.cadvisor.enable = true;
11+ services.cadvisor.storageDriver = "influxdb";
12+ services.influxdb.enable = true;
13+ systemd.services.influxdb.postStart = mkAfter ''
14+ ${pkgs.curl}/bin/curl -X POST 'http://localhost:8086/db?u=root&p=root' \
15+ -d '{"name": "root"}'
16+ '';
17+ };
18+ };
19+
20+ testScript =
21+ ''
22+ startAll;
23+ $machine->waitForUnit("cadvisor.service");
24+ $machine->succeed("curl http://localhost:8080/containers/");
25+
26+ $influxdb->waitForUnit("influxdb.service");
27+ $influxdb->waitForUnit("cadvisor.service");
28+ $influxdb->succeed("curl http://localhost:8080/containers/");
29+ '';
30+}