Merge pull request #5491 from offlinehacker/cadvisor

Add cadvisor package and nixos module
This commit is contained in:
Jaka Hudoklin 2014-12-29 17:58:43 +01:00
commit 1b19b7a3bf
7 changed files with 175 additions and 0 deletions

View File

@ -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!

View File

@ -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

View File

@ -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" ];
};
};
}

View File

@ -242,6 +242,7 @@ in rec {
tests.avahi = callTest tests/avahi.nix {};
tests.bittorrent = callTest tests/bittorrent.nix {};
tests.blivet = callTest tests/blivet.nix {};
tests.cadvisor = scrubDrv (import tests/cadvisor.nix { system = "x86_64-linux"; });
tests.chromium = callTest tests/chromium.nix {};
tests.cjdns = callTest tests/cjdns.nix {};
tests.containers = callTest tests/containers.nix {};

30
nixos/tests/cadvisor.nix Normal file
View File

@ -0,0 +1,30 @@
import ./make-test.nix {
name = "cadvisor";
nodes = {
machine = { config, pkgs, ... }: {
services.cadvisor.enable = true;
};
influxdb = { config, pkgs, lib, ... }: with lib; {
services.cadvisor.enable = true;
services.cadvisor.storageDriver = "influxdb";
services.influxdb.enable = true;
systemd.services.influxdb.postStart = mkAfter ''
${pkgs.curl}/bin/curl -X POST 'http://localhost:8086/db?u=root&p=root' \
-d '{"name": "root"}'
'';
};
};
testScript =
''
startAll;
$machine->waitForUnit("cadvisor.service");
$machine->succeed("curl http://localhost:8080/containers/");
$influxdb->waitForUnit("influxdb.service");
$influxdb->waitForUnit("cadvisor.service");
$influxdb->succeed("curl http://localhost:8080/containers/");
'';
}

View File

@ -0,0 +1,34 @@
{ stdenv, lib, go, fetchFromGitHub }:
stdenv.mkDerivation rec {
name = "cadvisor-${version}";
version = "0.7.1";
src = fetchFromGitHub {
owner = "google";
repo = "cadvisor";
rev = "${version}";
sha256 = "1vc9fydi6wra45khxsmfw5mx2qyggi7cg6kgajzw518rqa52ivmg";
};
buildInputs = [ go ];
buildPhase = ''
mkdir -p Godeps/_workspace/src/github.com/google/
ln -s $(pwd) Godeps/_workspace/src/github.com/google/cadvisor
GOPATH=$(pwd)/Godeps/_workspace go build -v -o cadvisor github.com/google/cadvisor
'';
installPhase = ''
mkdir -p $out/bin
mv cadvisor $out/bin
'';
meta = with stdenv.lib; {
description = "Analyzes resource usage and performance characteristics of running docker containers.";
homepage = https://github.com/google/cadvisor;
license = licenses.asl20;
maintainers = with maintainers; [ offline ];
platforms = platforms.unix;
};
}

View File

@ -7555,6 +7555,8 @@ let
apacheHttpdPackages_2_2 = apacheHttpdPackagesFor pkgs.apacheHttpd_2_2 pkgs.apacheHttpdPackages_2_2;
apacheHttpdPackages_2_4 = apacheHttpdPackagesFor pkgs.apacheHttpd_2_4 pkgs.apacheHttpdPackages_2_4;
cadvisor = callPackage ../servers/monitoring/cadvisor { };
cassandra = callPackage ../servers/nosql/cassandra { };
apache-jena = callPackage ../servers/nosql/apache-jena/binary.nix {