The SysStat package, authored by Sebastian Godard and licensed under GPLv2, is supported by 58 contributors on GitHub. This suite comprises several utilities aimed at monitoring system performance and usage:
SysStat includes several tools intended for scheduling via cron or systemd
to accumulate and record performance and activity data:
sar
.sadc
and is intended for execution via cron or systemd
.sar
and designed for cron or systemd
execution.sar
in various formats (CSV, JSON, XML etc.), facilitating data exchange with other programs. This command also supports generating graphs for different activities recorded by sar
in SVG format.sa1 and sa2 are shell wrappers around sadc and sar. The difference is that the shell scripts handle corner cases and logging better and are therefore suggested to be used for crond.
The Debian sysstat package integrates an entry within the system’s crontab. For comprehensive details, consult the file located at /usr/share/doc/sysstat/README.Debian
.
For the display of all-day statistics with sar
to work, data needs to be collected, but this is disabled per default under Debian. The Debian packages encompasses a system crontab file executing the sa1
script. However, it is initially in a disabled state, resulting in the non-collection of statistics. Consequently, executing sar
without parameters typically results in an error, indicated as
Cannot open
/var/log/sysstat/saXX
: No such file or directory.
To rectify this issue and initiate data collection, activate the crontab function by executing:
dpkg-reconfigure sysstat
and affirmatively responding to the inquiry regarding the activation of sysstat’s cron job.
If this option is enabled the sysstat package will monitor system activities
and store the data in log files within /var/log/sysstat/.
This data allows the sar(1) command to display system statistics for the whole
day.
If you don't enable this option, the sar(1) command will only show the current
statistics.
Activate sysstat's cron job?
<Yes> <No>
Furthermore, the package installs specific system crontab files, namely /etc/cron.d/sysstat
and /etc/cron.daily/sysstat
to collect data. Following the example section of the man pages to install cron jobs is not necessary. Undertaking such manual entries might result in concurrent executions of the sa2
script, potentially leading to operational errors.
To automate the installation and configuration of sysstat debconf can be used with Ansible to activate the cron job. However a non interactive configuration fails, because of the file /etc/default/sysstat
. So the debconf configuration has to be done in one of the 3 ways:
/etc/default/sysstat
and non interactivelyBefore we write the Ansible debconf question, we would need to understand what question exactly is used in sysstat
debconf-show sysstat
* sysstat/enable: false
sysstat/remove_files: true
On the command-line the following works after package installation.
debconf-show sysstat
* sysstat/enable: false
sysstat/remove_files: true
# Edit /etc/default/sysstat and set ENABLED to "true"
echo sysstat sysstat/enable boolean true|debconf-set-selections
dpkg-reconfigure --frontend=noninteractive sysstat
debconf-show sysstat
* sysstat/enable: true
sysstat/remove_files: true
With Ansible two more steps are needed.
/etc/default/sysstat
need to be changed# adm-nox.yaml
---
- hosts: role_client
gather_facts: no
become: yes
vars:
ns: adm_nox
packages:
# SysStat (iostat, ...) System performance tools for Linux
- sysstat
tasks:
- name: "{{ ns }}: Install and update packages"
apt:
name: "{{ packages }}"
state: latest
- name: "{{ ns }}: Enable sysstat"
lineinfile:
path: /etc/default/sysstat
regexp: '^ENABLED=".*"'
line: 'ENABLED="true"'
create: yes
- name: "{{ ns }}: Pre-configure sysstat package"
ansible.builtin.debconf:
name: sysstat
question: sysstat/enable
vtype: "boolean"
value: "true"
become: yes
register: dpkg_reconfigure
- name: "{{ ns }}: Reconfigure sysstat package"
ansible.builtin.shell:
cmd: dpkg-reconfigure --frontend=noninteractive sysstat
when: dpkg_reconfigure.changed
become: yes
notify: restart sysstat
handlers:
- name: restart sysstat
service:
name: sysstat
state: restarted
Projects related to sysstat that presents sar data in graphical format.
Version | Date | Notes |
---|---|---|
0.1.3 | 2024-03-21 | Add graphics section |
0.1.2 | 2024-03-08 | Improve introduction, add Debian section, Ansible |
0.1.1 | 2024-03-05 | Add link to mpstat |
0.1.0 | 2024-03-01 | Initial release |