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