Sindbad~EG File Manager
3
�f� � @ sr d dl m Z d dlZd dlZd dlmZmZmZmZm Z G dd� de�Z
G dd� de
e�ZG dd � d e
ee�ZdS )
� )�datetimeN)�Plugin�RedHatPlugin�DebianPlugin�UbuntuPlugin� PluginOptc @ sD e Zd ZdZdZdZdZdZdZe dd d
d�gZ
dd
� Zdd� ZdS )�SaraN
The sar plugin is designed to collect system performance data as recorded
by sysstat.
The raw binary data, i.e. the 'saX' files, will be collected and for files
a week old or younger, this plugin will capture human-readable conversions
of those files provided by the 'sar' command locally available, if the
local sysstat installation has not already created a converted copy (e.g.
for the current day-of data being collected at the time of report
generation).
Using the 'all_sar' plugin option will not only cause the plugin to capture
_all_ 'saX' files present on the host, but further perform the 'sar'
conversion on all files, not just those produced within the last week.
Converted 'sar' files will be written to the sos_commands/sar/, and not
to the /var/log/ path that sysstat writes to.
Note that this conversion is done because it is unlikely that the same
version of sysstat that produces the 'saX' files will be the same version
available on a given analyst's workstation, and this conversion is version
sensitive.
zSystem Activity Reporter�sar�system�performance�sysstatz/var/log/sa�all_sarFz"gather all system activity records)�defaultZdescc
C s� | j | j| jd�| jd�rdnd dd� y| j| j�}W n$ tk
r\ | jd| j � d S X tjd�}x�|D ]x}|j |�rn| j| j|�}d|d d � }||kr�| jd� r�| j
|�r�qnd
| }| j||� d| }| j|d| � qnW d S )
N�*r
r F)Z sizelimitZtailitzsar: could not list %szsa[\d]+r � zsar -A -f %szsadf -x -- -A %sz%s.xml)Z
add_copy_specZ path_join�sa_pathZ
get_option�listdir�OSError� _log_warn�re�compile�match�is_older_than_7daysZadd_cmd_output)�selfZdir_listZsa_regexZfnameZsa_data_pathZsar_filenameZsar_cmdZsadf_cmd� r �/usr/lib/python3.6/sar.py�setup5 s*
z Sar.setupc C sj y0t j|�j}tj� tj|� }|jdkr.dS W n4 tk
rd } z| jd||f � W Y dd}~X nX dS )z Is the file older than 7 days? � FzGCould not determine age of '%s' - skipping converting to sar format: %sNT) �os�stat�st_mtime�dtZtodayZ
fromtimestampZdays� Exceptionr )r ZsarfileZ_ftimeZ_age�errr r r r S s
zSar.is_older_than_7daysN)r
r )r )
�__name__�
__module__�__qualname__�__doc__Z
short_descZplugin_nameZprofilesZpackagesr r Zoption_listr r r r r r r s
r c @ s e Zd ZdZdS )� RedHatSarz/var/log/saN)r$ r% r&