o
    O6ufÏ  ã                   @   sr   d dl m Z d dlZd dlZd dlmZmZmZmZm	Z	 G dd„ deƒZ
G dd„ de
eƒZG dd	„ d	e
eeƒZdS )
é    )ÚdatetimeN)ÚPluginÚRedHatPluginÚDebianPluginÚUbuntuPluginÚ	PluginOptc                   @   sD   e Zd ZdZdZdZdZdZdZe	ddd	d
�gZ
dd„ Zdd„ ZdS )Ú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.
    zSystem Activity ReporterÚsar)ÚsystemÚperformance)Úsysstatú/var/log/saúall-sarFz"gather all system activity records)ÚdefaultÚdescc                 C   sð   | j |  | jd¡|  d¡rdnd dd� z|  | j¡}W n ty/   |  d| j› �¡ Y d S w t d¡}|D ]>}| 	|¡ru|  | j|¡}d|d	d …  }||vrg|  d¡s\|  
|¡r\q7d
|› �}|  ||¡ d|› �}|  ||› d�¡ q7d S )NÚ*r   r   F)Ú	sizelimitÚtailitzsar: could not list zsa[\d]+r	   é   z
sar -A -f zsadf -x -- -A z.xml)Úadd_copy_specÚ	path_joinÚsa_pathÚ
get_optionÚlistdirÚOSErrorÚ	_log_warnÚreÚcompileÚmatchÚis_older_than_7daysÚadd_cmd_output)ÚselfÚdir_listÚsa_regexÚfnameÚsa_data_pathÚsar_filenameÚsar_cmdÚsadf_cmd© r)   ú8/usr/lib/python3/dist-packages/sos/report/plugins/sar.pyÚsetup5   s4   þþ


ÿ

€ôz	Sar.setupc              
   C   sr   zt  |¡j}t ¡ t |¡ }|jdkrW dS W dS  ty8 } z|  d|› d|› �¡ W Y d}~dS d}~ww )z  Is the file older than 7 days? é   FzCould not determine age of 'z'' - skipping converting to sar format: NT)	ÚosÚstatÚst_mtimeÚdtÚtodayÚfromtimestampÚdaysÚ	Exceptionr   )r!   ÚsarfileÚ_ftimeÚ_ageÚerrr)   r)   r*   r   S   s   
ÿüÿ€üzSar.is_older_than_7daysN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
short_descÚplugin_nameÚprofilesÚpackagesr   r   Úoption_listr+   r   r)   r)   r)   r*   r      s    ÿÿr   c                   @   ó   e Zd ZdZdS )Ú	RedHatSarr   N©r9   r:   r;   r   r)   r)   r)   r*   rC   a   ó    rC   c                   @   rB   )Ú	DebianSarz/var/log/sysstatNrD   r)   r)   r)   r*   rF   f   rE   rF   )r   r0   r-   r   Úsos.report.pluginsr   r   r   r   r   r   rC   rF   r)   r)   r)   r*   Ú<module>   s   Q