summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/sysstat.nix
blob: ca2cff827232013dfdc821ace316e719b4b330f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{ config, lib, pkgs, ... }:
with lib;
let
  cfg = config.services.sysstat;
in {
  options = {
    services.sysstat = {
      enable = mkEnableOption "sar system activity collection";

      collect-frequency = mkOption {
        type = types.str;
        default = "*:00/10";
        description = ''
          OnCalendar specification for sysstat-collect
        '';
      };

      collect-args = mkOption {
        type = types.str;
        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" ];

      serviceConfig = {
        User = "root";
        RemainAfterExit = true;
        Type = "oneshot";
        ExecStart = "${pkgs.sysstat}/lib/sa/sa1 --boot";
        LogsDirectory = "sa";
      };
    };

    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";
    };
  };
}