at 16.09-beta 2.1 kB view raw
1{ config, lib, pkgs, ... }: 2with lib; 3let 4 cfg = config.services.sysstat; 5in { 6 options = { 7 services.sysstat = { 8 enable = mkOption { 9 type = types.bool; 10 default = false; 11 description = '' 12 Whether to enable sar system activity collection. 13 ''; 14 }; 15 16 collect-frequency = mkOption { 17 default = "*:00/10"; 18 description = '' 19 OnCalendar specification for sysstat-collect 20 ''; 21 }; 22 23 collect-args = mkOption { 24 default = "1 1"; 25 description = '' 26 Arguments to pass sa1 when collecting statistics 27 ''; 28 }; 29 }; 30 }; 31 32 config = mkIf cfg.enable { 33 systemd.services.sysstat = { 34 description = "Resets System Activity Logs"; 35 wantedBy = [ "multi-user.target" ]; 36 preStart = "test -d /var/log/sa || mkdir -p /var/log/sa"; 37 38 serviceConfig = { 39 User = "root"; 40 RemainAfterExit = true; 41 Type = "oneshot"; 42 ExecStart = "${pkgs.sysstat}/lib/sa/sa1 --boot"; 43 }; 44 }; 45 46 systemd.services.sysstat-collect = { 47 description = "system activity accounting tool"; 48 unitConfig.Documentation = "man:sa1(8)"; 49 50 serviceConfig = { 51 Type = "oneshot"; 52 User = "root"; 53 ExecStart = "${pkgs.sysstat}/lib/sa/sa1 ${cfg.collect-args}"; 54 }; 55 }; 56 57 systemd.timers.sysstat-collect = { 58 description = "Run system activity accounting tool on a regular basis"; 59 wantedBy = [ "timers.target" ]; 60 timerConfig.OnCalendar = cfg.collect-frequency; 61 }; 62 63 systemd.services.sysstat-summary = { 64 description = "Generate a daily summary of process accounting"; 65 unitConfig.Documentation = "man:sa2(8)"; 66 67 serviceConfig = { 68 Type = "oneshot"; 69 User = "root"; 70 ExecStart = "${pkgs.sysstat}/lib/sa/sa2 -A"; 71 }; 72 }; 73 74 systemd.timers.sysstat-summary = { 75 description = "Generate summary of yesterday's process accounting"; 76 wantedBy = [ "timers.target" ]; 77 timerConfig.OnCalendar = "00:07:00"; 78 }; 79 }; 80}