Recolección de métricas adicionales en sar (sysstat)

por | octubre 15, 2017

La herramienta sar (paquete sysstat) recolecta por defecto datos relativos a memoria RAM utilizada, carga de sistema, uso de CPU, swap, etc… pero existen una serie de métricas que tendremos que activar nosotros manualmente. Evidentemente cuantas más métricas activemos más recursos necesitará el demonio para realizar las tareas de recolección correspondientes, por lo que tendremos que considerar cuáles activar especialmente en servidores de producción.

Las pistas las tenemos en la página man de sar. Veremos numerosas entradas del tipo:

...
Note that disk activity depends on sadc options -S DISK and -S XDISK to be collected
...
Note that fibre channel statistics depend on sadc's option "-S DISK" to be collected
...
Note that IPv4 statistics depend on sadc's option "-S SNMP" to be collected
...
Note that ICMPv4 statistics depend on sadc's option "-S SNMP" to be collected
...

Dichas opciones tendrán que ser añadidas en el fichero de configuración /etc/systat/systat (Debian y derivadas) o /etc/sysconfig/sysstat (RHEL y derivadas) en la variable SADC_OPTIONS:

# Parameters for the system activity data collector (see sadc(8) manual page)
# which are used for the generation of log files.
# By default contains the `-S DISK' option responsible for generating disk
# statisitcs. Use `-S XALL' to collect all available statistics.
SADC_OPTIONS="-S DISK"

Así, si queremos activar estadísticas IPv4 tendremos que añadir la opción correspondiente:

SADC_OPTIONS="-S DISK -S SNMP"

Una vez modificado reiniciamos el demonio de sysstat:

systemctl restart sysstat.service

Si el arranca correctamente veremos en /var/log/syslog

...
Oct 15 14:30:54 jota-pc systemd[1]: Stopping LSB: Start/stop sysstat's sadc...
Oct 15 14:30:54 jota-pc systemd[1]: Stopped LSB: Start/stop sysstat's sadc.
Oct 15 14:30:54 jota-pc systemd[1]: Starting LSB: Start/stop sysstat's sadc...
Oct 15 14:30:54 jota-pc sysstat[16088]: Starting the system activity data collector: sadc.
Oct 15 14:30:54 jota-pc systemd[1]: Started LSB: Start/stop sysstat's sadc.
...

También podemos verlo con journalctl:

[root@jota-pc ~]# journalctl UNIT=sysstat.service 
-- Logs begin at Sun 2017-10-15 09:01:53 CEST, end at Sun 2017-10-15 14:31:53 CEST. --
Oct 15 09:01:53 jota-pc systemd[1]: Starting LSB: Start/stop sysstat's sadc...
Oct 15 09:01:53 jota-pc systemd[1]: Started LSB: Start/stop sysstat's sadc.
Oct 15 14:30:54 jota-pc systemd[1]: Stopping LSB: Start/stop sysstat's sadc...
Oct 15 14:30:54 jota-pc systemd[1]: Stopped LSB: Start/stop sysstat's sadc.
Oct 15 14:30:54 jota-pc systemd[1]: Starting LSB: Start/stop sysstat's sadc...
Oct 15 14:30:54 jota-pc systemd[1]: Started LSB: Start/stop sysstat's sadc.

Los cambios no son efectivos en el actual fichero de datos de sar (los claśicos saXX) por lo que si intentamos consultar por ejemplo las estadísticas de tráfico IPv4 con sar -n IP obtendremos un error:

Requested activities not available in file /var/log/sysstat/sa15

Tendremos que esperar al próximo fichero sa generado al día siguiente o bien forzar que se genere uno nuevo borrando el existente y reiniciando el servicio sysstat como vimos anteriormente.

Recordar finalmente que para generar de forma sencilla gráficas a partir de los datos recogidos por sar tenéis mi repo sarviewer en GitHub.