2016-07-12 18:52:33 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.sysstat;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.sysstat = {
|
2022-08-28 21:18:44 +02:00
|
|
|
enable = mkEnableOption (lib.mdDoc "sar system activity collection");
|
2016-07-12 18:52:33 +02:00
|
|
|
|
|
|
|
collect-frequency = mkOption {
|
2019-12-30 16:43:36 +01:00
|
|
|
type = types.str;
|
2016-07-12 18:52:33 +02:00
|
|
|
default = "*:00/10";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2016-07-12 18:52:33 +02:00
|
|
|
OnCalendar specification for sysstat-collect
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
collect-args = mkOption {
|
2019-12-30 16:43:36 +01:00
|
|
|
type = types.str;
|
2016-07-12 18:52:33 +02:00
|
|
|
default = "1 1";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc ''
|
2016-07-12 18:52:33 +02:00
|
|
|
Arguments to pass sa1 when collecting statistics
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.sysstat = {
|
|
|
|
description = "Resets System Activity Logs";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = "root";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = "${pkgs.sysstat}/lib/sa/sa1 --boot";
|
2019-12-30 16:43:36 +01:00
|
|
|
LogsDirectory = "sa";
|
2016-07-12 18:52:33 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|