summary refs log tree commit diff
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2016-07-12 11:52:33 -0500
committerGraham Christensen <graham@grahamc.com>2016-07-12 16:19:40 -0500
commitd3d7f43f762062c03aa083aeaa7cf868246e4e51 (patch)
treedb64830122c92b5baf3df41373723d836f74df73
parent99039235728c673291510c77bca9077abb16a1fb (diff)
downloadnixpkgs-d3d7f43f762062c03aa083aeaa7cf868246e4e51.tar
nixpkgs-d3d7f43f762062c03aa083aeaa7cf868246e4e51.tar.gz
nixpkgs-d3d7f43f762062c03aa083aeaa7cf868246e4e51.tar.bz2
nixpkgs-d3d7f43f762062c03aa083aeaa7cf868246e4e51.tar.lz
nixpkgs-d3d7f43f762062c03aa083aeaa7cf868246e4e51.tar.xz
nixpkgs-d3d7f43f762062c03aa083aeaa7cf868246e4e51.tar.zst
nixpkgs-d3d7f43f762062c03aa083aeaa7cf868246e4e51.zip
sysstat: Create systemd service for historical sar data
Every period, sa1 collects and stores data.
Every 24 hours, sa2 aggregates the previous day's data in to a
report.

Timers and unit configurations were lifted from Fedora's default
units.
-rw-r--r--nixos/modules/services/monitoring/sysstat.nix80
1 files changed, 80 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/sysstat.nix b/nixos/modules/services/monitoring/sysstat.nix
new file mode 100644
index 00000000000..d668faa53cc
--- /dev/null
+++ b/nixos/modules/services/monitoring/sysstat.nix
@@ -0,0 +1,80 @@
+{ config, lib, pkgs, ... }:
+with lib;
+let
+  cfg = config.services.sysstat;
+in {
+  options = {
+    services.sysstat = {
+      enable = mkOption {
+        type = types.bool;
+        default = false;
+        description = ''
+          Whether to enable sar system activity collection.
+        '';
+      };
+
+      collect-frequency = mkOption {
+        default = "*:00/10";
+        description = ''
+          OnCalendar specification for sysstat-collect
+        '';
+      };
+
+      collect-args = mkOption {
+        default = "1 1";
+        description = ''
+          Arguments to pass sa1 when collecting statistics
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    systemd.services.sysstat = {
+      description = "Resets System Activity Logs";
+      wantedBy = [ "multi-user.target" ];
+      preStart = "test -d /var/log/sa || mkdir -p /var/log/sa";
+
+      serviceConfig = {
+        User = "root";
+        RemainAfterExit = true;
+        Type = "oneshot";
+        ExecStart = "${pkgs.sysstat}/lib/sa/sa1 --boot";
+      };
+    };
+
+    systemd.services.sysstat-collect = {
+      description = "system activity accounting tool";
+      unitConfig.Documentation = "man:sa1(8)";
+
+      serviceConfig = {
+        Type = "oneshot";
+        User = "root";
+        ExecStart = "${pkgs.sysstat}/lib/sa/sa1 ${cfg.collect-args}";
+      };
+    };
+
+    systemd.timers.sysstat-collect = {
+      description = "Run system activity accounting tool on a regular basis";
+      wantedBy = [ "timers.target" ];
+      timerConfig.OnCalendar = cfg.collect-frequency;
+    };
+
+    systemd.services.sysstat-summary = {
+      description = "Generate a daily summary of process accounting";
+      unitConfig.Documentation = "man:sa2(8)";
+
+      serviceConfig = {
+        Type = "oneshot";
+        User = "root";
+        ExecStart = "${pkgs.sysstat}/lib/sa/sa2 -A";
+      };
+    };
+
+    systemd.timers.sysstat-summary = {
+      description = "Generate summary of yesterday's process accounting";
+      wantedBy = [ "timers.target" ];
+      timerConfig.OnCalendar = "00:07:00";
+    };
+  };
+}