git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #5491 from offlinehacker/cadvisor

Add cadvisor package and nixos module

commit1b19b7a3bfaefdf17c3e5547d2214725d3d82ee2 authorJaka Hudoklin <jakahudoklin@gmail.com> dateMon 29 Dec 2014, 17:58 (12 years ago) parent2386effb6198f0
7 files changed+175
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 pkgs/servers/monitoring/cadvisor/default.nix+34 pkgs/top-level/all-packages.nix+2
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+}
pkgs/servers/monitoring/cadvisor/default.nixnew file+34
@@ -0,0 +1,34 @@
1+{ stdenv, lib, go, fetchFromGitHub }:
2+
3+stdenv.mkDerivation rec {
4+ name = "cadvisor-${version}";
5+ version = "0.7.1";
6+
7+ src = fetchFromGitHub {
8+ owner = "google";
9+ repo = "cadvisor";
10+ rev = "${version}";
11+ sha256 = "1vc9fydi6wra45khxsmfw5mx2qyggi7cg6kgajzw518rqa52ivmg";
12+ };
13+
14+ buildInputs = [ go ];
15+
16+ buildPhase = ''
17+ mkdir -p Godeps/_workspace/src/github.com/google/
18+ ln -s $(pwd) Godeps/_workspace/src/github.com/google/cadvisor
19+ GOPATH=$(pwd)/Godeps/_workspace go build -v -o cadvisor github.com/google/cadvisor
20+ '';
21+
22+ installPhase = ''
23+ mkdir -p $out/bin
24+ mv cadvisor $out/bin
25+ '';
26+
27+ meta = with stdenv.lib; {
28+ description = "Analyzes resource usage and performance characteristics of running docker containers.";
29+ homepage = https://github.com/google/cadvisor;
30+ license = licenses.asl20;
31+ maintainers = with maintainers; [ offline ];
32+ platforms = platforms.unix;
33+ };
34+}
pkgs/top-level/all-packages.nix+2
@@ -7555,6 +7555,8 @@ let
75557555 apacheHttpdPackages_2_2 = apacheHttpdPackagesFor pkgs.apacheHttpd_2_2 pkgs.apacheHttpdPackages_2_2;
75567556 apacheHttpdPackages_2_4 = apacheHttpdPackagesFor pkgs.apacheHttpd_2_4 pkgs.apacheHttpdPackages_2_4;
75577557
7558+ cadvisor = callPackage ../servers/monitoring/cadvisor { };
7559+
75587560 cassandra = callPackage ../servers/nosql/cassandra { };
75597561
75607562 apache-jena = callPackage ../servers/nosql/apache-jena/binary.nix {