From 60b856b115d236c19764936d32e6708e9d585d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?= Date: Wed, 9 Dec 2009 21:45:59 +0000 Subject: [PATCH] Adding a module for system health monitoring (getting graphs generated by rrdtool of usual system counters). It sets up some cron jobs for collecting the data, and not that often, generating the graphs. Then the httpd server is configured with a directory with the generated static files. http://www.brianlane.com/software/systemhealth/ svn path=/nixos/trunk/; revision=18866 --- modules/module-list.nix | 1 + modules/services/monitoring/systemhealth.nix | 130 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 modules/services/monitoring/systemhealth.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index d793c715202e..62f8638020cb 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -60,6 +60,7 @@ ./services/misc/synergy.nix ./services/monitoring/monit.nix ./services/monitoring/nagios/default.nix + ./services/monitoring/systemhealth.nix ./services/monitoring/zabbix-agent.nix ./services/monitoring/zabbix-server.nix ./services/network-filesystems/nfs-kernel.nix diff --git a/modules/services/monitoring/systemhealth.nix b/modules/services/monitoring/systemhealth.nix new file mode 100644 index 000000000000..8d531b526f3a --- /dev/null +++ b/modules/services/monitoring/systemhealth.nix @@ -0,0 +1,130 @@ +{config, pkgs, ...}: + +with pkgs.lib; + +let + cfg = config.services.systemhealth; + + systemhealth = with pkgs; stdenv.mkDerivation { + name = "systemhealth-1.0"; + src = fetchurl { + url = "http://www.brianlane.com/software/systemhealth/src/systemhealth-1.0.tar.bz2"; + sha256 = "1q69lz7hmpbdpbz36zb06nzfkj651413n9icx0njmyr3xzq1j9qy"; + }; + buildInputs = [ python ]; + installPhase = '' + ensureDir $out/bin + cp system_health.py $out/bin + ''; + }; + + rrdDir = "/var/lib/health/rrd"; + htmlDir = "/var/lib/health/html"; + + configFile = rrdDir + "/.syshealthrc"; + # The program will try to read $HOME/.syshealthrc, so we set the proper home. + command = "HOME=${rrdDir} ${systemhealth}/bin/system_health.py"; + + cronJob = '' + */5 * * * * wwwrun ${command} --log + 5 * * * * wwwrun ${command} --graph + ''; + + nameEqualName = s: "${s} = ${s}"; + interfacesSection = concatStringsSep "\n" (map nameEqualName cfg.interfaces); + + driveLine = d: "${d.path} = ${d.name}"; + drivesSection = concatStringsSep "\n" (map driveLine cfg.drives); + +in +{ + options = { + services.systemhealth = { + enable = mkOption { + default = false; + description = '' + Enable the system health monitor and its generation of graphs. + ''; + }; + + urlPrefix = mkOption { + default = "/health"; + description = '' + The URL prefix under which the System Health web pages appear in httpd. + ''; + }; + + interfaces = mkOption { + default = [ "lo" ]; + example = [ "lo" "eth0" "eth1" ]; + description = '' + Interfaces to monitor (minimum one). + ''; + }; + + drives = mkOption { + default = [ ]; + example = [ { name = "root"; path = "/"; } ]; + description = '' + Drives to monitor. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + services.cron.systemCronJobs = [ cronJob ]; + + system.activationScripts.systemhealth = fullDepEntry '' + mkdir -p ${rrdDir} ${htmlDir} + chown wwwrun.wwwrun ${rrdDir} ${htmlDir} + + cat >${configFile} << EOF + [paths] + rrdtool = ${pkgs.rrdtool}/bin/rrdtool + loadavg_rrd = loadavg + ps = /var/run/current-system/sw/bin/ps + df = /var/run/current-system/sw/bin/df + meminfo_rrd = meminfo + uptime_rrd = uptime + rrd_path = ${rrdDir} + png_path = ${htmlDir} + + [processes] + + [interfaces] + ${interfacesSection} + + [drives] + ${drivesSection} + + [graphs] + width = 400 + time = ['-3hours', '-32hours', '-8days', '-5weeks', '-13months'] + height = 100 + + [external] + + EOF + + chown wwwrun.wwwrun ${configFile} + + ${pkgs.su}/bin/su -s "/bin/sh" -c "${command} --check" wwwrun + ${pkgs.su}/bin/su -s "/bin/sh" -c "${command} --html" wwwrun + '' [ "var" ]; + + services.httpd.extraSubservices = [ + { function = f: { + extraConfig = '' + Alias ${cfg.urlPrefix} ${htmlDir} + + + Order allow,deny + Allow from all + + ''; + }; + } + ]; + }; +}