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