From e60e690181151f293b1c41b0d89cc1da59bbff60 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sun, 1 Nov 2015 10:16:04 +0000 Subject: [PATCH 1/7] perl-Linux-Distribution: init at 0.23 --- pkgs/top-level/perl-packages.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/top-level/perl-packages.nix b/pkgs/top-level/perl-packages.nix index 4c5ef9ef9db..36cc16b748f 100644 --- a/pkgs/top-level/perl-packages.nix +++ b/pkgs/top-level/perl-packages.nix @@ -6238,6 +6238,18 @@ let self = _self // overrides; _self = with self; { doCheck = false; }; + LinuxDistribution = buildPerlPackage { + name = "Linux-Distribution-0.23"; + src = fetchurl { + url = mirror://cpan/authors/id/C/CH/CHORNY/Linux-Distribution-0.23.tar.gz; + sha256 = "603e27da607b3e872a669d7a66d75982f0969153eab2d4b20c341347b4ebda5f"; + }; + meta = { + description = "Perl extension to detect on which Linux distribution we are running"; + license = "perl"; + }; + }; + LinuxInotify2 = buildPerlPackage rec { name = "Linux-Inotify2-1.22"; src = fetchurl { From 5f646f98f8f20a281a37f1a382777bb1752ab3b3 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sun, 1 Nov 2015 10:16:30 +0000 Subject: [PATCH 2/7] perl-Log-LogLite: init at 0.82 --- pkgs/top-level/perl-packages.nix | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkgs/top-level/perl-packages.nix b/pkgs/top-level/perl-packages.nix index 36cc16b748f..e5ad6a82793 100644 --- a/pkgs/top-level/perl-packages.nix +++ b/pkgs/top-level/perl-packages.nix @@ -6514,6 +6514,19 @@ let self = _self // overrides; _self = with self; { }; }; + LogLogLite = buildPerlPackage rec { + name = "Log-LogLite-0.82"; + src = fetchurl { + url = "mirror://cpan/authors/id/R/RA/RANI/${name}.tar.gz"; + sha256 = "0sqsa4750wvhw4cjmxpxqg30i1jjcddadccflisrdb23qn5zn285"; + }; + propagatedBuildInputs = [ IOLockedFile ]; + meta = { + description = "Helps us create simple logs for our application."; + license = "perl"; + }; + }; + LWP = buildPerlPackage rec { name = "libwww-perl-6.13"; src = fetchurl { From a754e7b8a6358587e2637456ce669a4c5de81a54 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sun, 1 Nov 2015 10:11:30 +0000 Subject: [PATCH 3/7] Add self to maintainers --- lib/maintainers.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/maintainers.nix b/lib/maintainers.nix index 6665539b0e8..e76de34ba60 100644 --- a/lib/maintainers.nix +++ b/lib/maintainers.nix @@ -255,6 +255,7 @@ romildo = "José Romildo Malaquias "; rszibele = "Richard Szibele "; rushmorem = "Rushmore Mushambi "; + rvl = "Rodney Lorrimar "; rycee = "Robert Helgesson "; samuelrivas = "Samuel Rivas "; sander = "Sander van der Burg "; From 96f81e3be57bb46858496edc07fd4bdcc6ce1704 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sun, 1 Nov 2015 10:20:12 +0000 Subject: [PATCH 4/7] longview: Linode metrics collector Longview is a perl script used for sending server metrics to Linode virtual private server hosting. --- pkgs/servers/monitoring/longview/default.nix | 62 +++++++++++++++++++ .../monitoring/longview/log-stdout.patch | 38 ++++++++++++ pkgs/top-level/all-packages.nix | 2 + 3 files changed, 102 insertions(+) create mode 100644 pkgs/servers/monitoring/longview/default.nix create mode 100644 pkgs/servers/monitoring/longview/log-stdout.patch diff --git a/pkgs/servers/monitoring/longview/default.nix b/pkgs/servers/monitoring/longview/default.nix new file mode 100644 index 00000000000..3c08f48e410 --- /dev/null +++ b/pkgs/servers/monitoring/longview/default.nix @@ -0,0 +1,62 @@ +{stdenv, fetchFromGitHub, perl, perlPackages, makeWrapper, glibc }: + +stdenv.mkDerivation rec { + version = "1.1.5pre"; + name = "longview-${version}"; + + src = fetchFromGitHub { + owner = "linode"; + repo = "longview"; + rev = "5bcc9b60896b72de2d14f046f911477c26eb70ba"; + sha256 = "1i6va44bx2zfgbld7znf1slph0iqidlahq2xh3kd8q4lhvbrjn02"; + }; + + patches = + [ # log to systemd journal + ./log-stdout.patch + ]; + + postPatch = + '' + substituteInPlace Linode/Longview/Util.pm --replace /var/run/longview.pid /run/longview.pid + ''; + + buildInputs = [ perl makeWrapper glibc ] + ++ (with perlPackages; [ + LWPUserAgent + LWPProtocolHttps + MozillaCA + CryptSSLeay + IOSocketInet6 + LinuxDistribution + JSONPP + JSON + LogLogLite + TryTiny + DBI + DBDmysql + ]); + + buildPhase = "true"; + installPhase = '' + mkdir -p $out/bin $out/usr + mv Linode $out + ln -s ../Linode/Longview.pl $out/bin/longview + for h in syscall.h sys/syscall.h asm/unistd.h asm/unistd_32.h asm/unistd_64.h bits/wordsize.h bits/syscall.h; do + ${perl}/bin/h2ph -d $out ${glibc}/include/$h + mkdir -p $out/usr/include/$(dirname $h) + mv $out${glibc}/include/''${h%.h}.ph $out/usr/include/$(dirname $h) + done + wrapProgram $out/Linode/Longview.pl --prefix PATH : ${perl}/bin:$out/bin \ + --suffix PERL5LIB : $out/Linode --suffix PERL5LIB : $PERL5LIB \ + --suffix PERL5LIB : $out --suffix INC : $out + ''; + + meta = with stdenv.lib; { + homepage = https://www.linode.com/longview; + description = "Longview collects all of your system-level metrics and sends them to Linode."; + license = licenses.gpl2Plus; + maintainers = [ maintainers.rvl ]; + inherit version; + }; +} diff --git a/pkgs/servers/monitoring/longview/log-stdout.patch b/pkgs/servers/monitoring/longview/log-stdout.patch new file mode 100644 index 00000000000..3e009254bca --- /dev/null +++ b/pkgs/servers/monitoring/longview/log-stdout.patch @@ -0,0 +1,38 @@ +diff -ru longview-5bcc9b60896b72de2d14f046f911477c26eb70ba-src.orig/Linode/Longview/Logger.pm longview-5bcc9b60896b72de2d14f046f911477c26eb70ba-src/Linode/Longview/Logger.pm +--- longview-5bcc9b60896b72de2d14f046f911477c26eb70ba-src.orig/Linode/Longview/Logger.pm 2015-10-28 17:15:32.816515318 +0000 ++++ longview-5bcc9b60896b72de2d14f046f911477c26eb70ba-src/Linode/Longview/Logger.pm 2015-10-28 18:00:50.760332026 +0000 +@@ -26,9 +26,7 @@ + my ( $self, $message ) = @_; + + my $ts = strftime( '%m/%d %T', localtime ); +- $self->{logger}->write( +- sprintf( '%s %s Longview[%i] - %s', $ts, uc($level), $$, $message ), +- $levels->{$level} ); ++ printf( "%s %s Longview[%i] - %s\n", $ts, uc($level), $$, $message ); + die "$message" if $level eq 'logdie'; + }; + } +@@ -37,12 +35,6 @@ + my ( $class, $level ) = @_; + my $self = {}; + +- mkpath($LOGDIR) unless (-d $LOGDIR); +- $self->{logger} +- = Log::LogLite->new( $LOGDIR . 'longview.log', $level ) +- or die "Couldn't create logger object: $!"; +- $self->{logger}->template("\n"); +- + return bless $self, $class; + } + +diff -ru longview-5bcc9b60896b72de2d14f046f911477c26eb70ba-src.orig/Linode/Longview/Util.pm longview-5bcc9b60896b72de2d14f046f911477c26eb70ba-src/Linode/Longview/Util.pm +--- longview-5bcc9b60896b72de2d14f046f911477c26eb70ba-src.orig/Linode/Longview/Util.pm 2015-10-28 17:15:32.816515318 +0000 ++++ longview-5bcc9b60896b72de2d14f046f911477c26eb70ba-src/Linode/Longview/Util.pm 2015-10-28 19:20:30.894314658 +0000 +@@ -225,7 +225,6 @@ + #<<< perltidy ignore + chdir '/' or $logger->logdie("Can't chdir to /: $!"); + open STDIN, '<', '/dev/null' or $logger->logdie("Can't read /dev/null: $!"); +- open STDOUT, '>>', '/dev/null' or $logger->logdie("Can't write to /dev/null: $!"); + open STDERR, '>>', '/dev/null' or $logger->logdie("Can't write to /dev/null: $!"); + tie *STDERR, "Linode::Longview::STDERRLogger"; + defined( my $pid = fork ) or $logger->logdie("Can't fork: $!"); diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a17bf44e9c5..b2f9d208be2 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2150,6 +2150,8 @@ let logstalgia = callPackage ../tools/graphics/logstalgia {}; + longview = callPackage ../servers/monitoring/longview { }; + lout = callPackage ../tools/typesetting/lout { }; lrzip = callPackage ../tools/compression/lrzip { }; From bc3fb7961976ce4d8c1df731f8cff1f97c14c27a Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Sun, 1 Nov 2015 10:22:58 +0000 Subject: [PATCH 5/7] longview nixos module: init --- nixos/modules/module-list.nix | 1 + .../modules/services/monitoring/longview.nix | 77 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 nixos/modules/services/monitoring/longview.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index ecdf2264d69..c4cea424c60 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -240,6 +240,7 @@ ./services/monitoring/grafana.nix ./services/monitoring/graphite.nix ./services/monitoring/heapster.nix + ./services/monitoring/longview.nix ./services/monitoring/monit.nix ./services/monitoring/munin.nix ./services/monitoring/nagios.nix diff --git a/nixos/modules/services/monitoring/longview.nix b/nixos/modules/services/monitoring/longview.nix new file mode 100644 index 00000000000..b55f43b437b --- /dev/null +++ b/nixos/modules/services/monitoring/longview.nix @@ -0,0 +1,77 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.longview; + + pidFile = "/run/longview.pid"; + + apacheConf = '' + #location http://127.0.0.1/server-status?auto + ''; + mysqlConf = '' + #username root + #password example_password + ''; + nginxConf = '' + #location http://127.0.0.1/nginx_status + ''; + +in + +{ + options = { + + services.longview = { + + enable = mkOption { + type = types.bool; + default = false; + description = '' + If enabled, system metrics will be sent to Linode LongView. + ''; + }; + + apiKey = mkOption { + type = types.str; + description = '' + Longview API key. To get this, look in Longview settings which + are found at https://manager.linode.com/longview/. + ''; + }; + + }; + + }; + + config = mkIf cfg.enable { + systemd.services.longview = + { description = "Longview Metrics Collection"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig.Type = "forking"; + serviceConfig.ExecStop = "-${pkgs.coreutils}/bin/kill -TERM $MAINPID"; + serviceConfig.ExecReload = "-${pkgs.coreutils}/bin/kill -HUP $MAINPID"; + serviceConfig.PIDFile = pidFile; + serviceConfig.ExecStart = "${pkgs.longview}/bin/longview"; + }; + + environment.etc."linode/longview.key" = { + mode = "0400"; + text = cfg.apiKey; + }; + environment.etc."linode/longview.d/Apache.conf" = { + mode = "0400"; + text = apacheConf; + }; + environment.etc."linode/longview.d/MySQL.conf" = { + mode = "0400"; + text = mysqlConf; + }; + environment.etc."linode/longview.d/Nginx.conf" = { + mode = "0400"; + text = nginxConf; + }; + }; +} From 33c2b8a1f11b4f6632a28ff920e7b79da31ddb12 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Wed, 11 Nov 2015 12:11:07 +0000 Subject: [PATCH 6/7] longview nixos module: add config options for service monitoring --- .../modules/services/monitoring/longview.nix | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/monitoring/longview.nix b/nixos/modules/services/monitoring/longview.nix index b55f43b437b..955b33a5c0c 100644 --- a/nixos/modules/services/monitoring/longview.nix +++ b/nixos/modules/services/monitoring/longview.nix @@ -7,15 +7,15 @@ let pidFile = "/run/longview.pid"; - apacheConf = '' - #location http://127.0.0.1/server-status?auto + apacheConf = optionalString (cfg.apacheStatusUrl != "") '' + location ${cfg.apacheStatusUrl}?auto ''; - mysqlConf = '' - #username root - #password example_password + mysqlConf = optionalString (cfg.mysqlUser != "") '' + username ${cfg.mysqlUser} + password ${cfg.mysqlPassword} ''; - nginxConf = '' - #location http://127.0.0.1/nginx_status + nginxConf = optionalString (cfg.nginxStatusUrl != "") '' + location ${cfg.nginxStatusUrl} ''; in @@ -35,12 +35,51 @@ in apiKey = mkOption { type = types.str; + example = "01234567-89AB-CDEF-0123456789ABCDEF"; description = '' Longview API key. To get this, look in Longview settings which are found at https://manager.linode.com/longview/. ''; }; + apacheStatusUrl = mkOption { + type = types.str; + default = ""; + example = "http://127.0.0.1/server-status"; + description = '' + The Apache status page URL. If provided, Longview will + gather statistics from this location. This requires Apache + mod_status to be loaded and enabled. + ''; + }; + + nginxStatusUrl = mkOption { + type = types.str; + default = ""; + example = "http://127.0.0.1/nginx_status"; + description = '' + The Nginx status page URL. Longview will gather statistics + from this URL. This requires the Nginx stub_status module to + be enabled and configured at the given location. + ''; + }; + + mysqlUser = mkOption { + type = types.str; + default = ""; + description = '' + The user for connecting to the MySQL database. If provided, + Longview will connect to MySQL and collect statistics about + queries, etc. + ''; + }; + + mysqlPassword = mkOption { + type = types.str; + description = '' + The password corresponding to mysqlUser. + ''; + }; }; }; From 33f869ba1eec1aaecfab992adf2886d13231866a Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Mon, 16 Nov 2015 14:27:36 +0000 Subject: [PATCH 7/7] longview nixos module: improve description for mysql password config options --- nixos/modules/services/monitoring/longview.nix | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/monitoring/longview.nix b/nixos/modules/services/monitoring/longview.nix index 955b33a5c0c..770d56e60ef 100644 --- a/nixos/modules/services/monitoring/longview.nix +++ b/nixos/modules/services/monitoring/longview.nix @@ -70,14 +70,16 @@ in description = '' The user for connecting to the MySQL database. If provided, Longview will connect to MySQL and collect statistics about - queries, etc. + queries, etc. This user does not need to have been granted + any extra privileges. ''; }; mysqlPassword = mkOption { type = types.str; description = '' - The password corresponding to mysqlUser. + The password corresponding to mysqlUser. Warning: this is + stored in cleartext in the Nix store! ''; }; };