-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sysstat: Create systemd service for historical sar data
Every period, sa1 collects and stores data. Every 24 hours, sa2 aggregates the previous day's data in to a report. Timers and unit configurations were lifted from Fedora's default units.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{ config, lib, pkgs, ... }: | ||
with lib; | ||
let | ||
cfg = config.services.sysstat; | ||
in { | ||
options = { | ||
services.sysstat = { | ||
enable = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = '' | ||
Whether to enable sar system activity collection. | ||
''; | ||
}; | ||
|
||
collect-frequency = mkOption { | ||
default = "*:00/10"; | ||
description = '' | ||
OnCalendar specification for sysstat-collect | ||
''; | ||
}; | ||
|
||
collect-args = mkOption { | ||
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" ]; | ||
preStart = "test -d /var/log/sa || mkdir -p /var/log/sa"; | ||
|
||
serviceConfig = { | ||
User = "root"; | ||
RemainAfterExit = true; | ||
Type = "oneshot"; | ||
ExecStart = "${pkgs.sysstat}/lib/sa/sa1 --boot"; | ||
}; | ||
}; | ||
|
||
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"; | ||
}; | ||
}; | ||
} |