HEX
Server: Apache
System: Linux box5154.bluehost.com 5.14.0-162.23.1.9991722448259.nf.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 31 18:11:45 UTC 2024 x86_64
User: almiraso (1849)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/ntp/__pycache__/statfiles.cpython-39.pyo
a

\��d�#�@sndZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
Gdd�d�Zdd�Zdd	�Z
dS)
zq
statfiles.py - class for digesting and plotting NTP logfiles

Requires gnuplot and liberation fonts installed.

�)�print_function�divisionNc@s�eZdZdZdZdZiZdZdZdZ	dZ
edd��Zedd	��Z
ed
d��Zedd
��Zddd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�NTPStatsz*Gather statistics for a specified NTP sitei�Qi�:	N�c		Cs�g}|D]�}z$|��}t|d�}t|d�}WntyFYqYn0tj||d}||krn|krnqt|d�|d<t|�|d<|�|�q|S)z�Extract first two fields, MJD and seconds past midnight.
        convert timestamp (MJD & seconds past midnight) to Unix time
        Replace MJD+second with Unix time.r�l�@"��)�split�int�float�
ValueErrorr�SecondsInDay�str�append)	�lines�	starttime�endtime�lines1�linerZmjd�second�time�r�3/usr/lib64/python3.9/site-packages/ntp/statfiles.py�unixizes
zNTPStats.unixizecCst|��d�S)z"get Unix time from converted line.r)r
r)rrrr�	timestamp9szNTPStats.timestampcCs�i}t|�}d|krFd|kr&|d}nd}|D]}||dt|�<q.nD|D]>}|dkrh||d|d<qJ|t||d�|dt|�<qJ|S)zwReturn given percentiles of a given row in a given set of entries.
        assuming values are already split and sortedrr�p�dZp100)�lenr
r	)Zpercents�valuesZretZlength�valueZpercrrr�percentiles>s
"zNTPStats.percentilescCsd|d��r`|�d�r4|�d�\}}}}d||fSzt�|�\}}}|WStjy^Yn0|S)z,Produce appropriate label for an IP address.rz127.127.�.zREFCLOCK(type=%s,unit=%s))�isdigit�
startswithr�socketZ
gethostbyaddrZherror)�key�_Z
clock_typeZunitZhostnamerrr�ip_labelVs
zNTPStats.ip_labelc	Cs|durtj}||_|dur:|dur:tt���}||}n2|durT|durT||}n|durl|durl||}||_||_|p�tj�	|�|_
d|j
kr�t��|_
tj�
|�s�tj�d|�td��g|_g|_g|_g|_g|_g|_dD](}|�||�}|�||�}t|||�q�dS)z.Grab content of logfiles, sorted by timestamp.NZntpstatsz%ntpviz: ERROR: %s is not a directory
r)�
clockstats�	peerstats�	loopstats�rawstats�temps�gpsd)r�
DefaultPeriod�periodr	rrr�os�path�basename�sitenamer#Zgetfqdn�isdir�sys�stderr�write�
SystemExitr'r(r)r*r+r,�_NTPStats__load_stem�_NTPStats__process_stem�setattr)	�self�statsdirr2r.rr�stemrZ	processedrrr�__init__ms<



�zNTPStats.__init__cCs�g}z�tj�||�}|dkr,|dkr,|d7}t�|d�D]J}|jtj�|�krRq:|�d�rr|t�|d��	�7}q:|t|d��	�7}q:Wn"t
y�tj�
d|�Yn0|S)	Nr+r,r �*ZgzZrt�rz#ntpviz: WARNING: could not read %s
)r/r0�join�globr�getmtime�endswith�gzip�open�	readlines�IOErrorr4r5r6)r;r<r=r�patternZlogpartrrrZ__load_stem�s 
�zNTPStats.__load_stemc	Cs�g}|dks|dkr�|D]|}|��}dt|�kr2qzt|d�}WntyXYqYn0|j|krr|jkrnq|�dt|d��|�|�qnt	�
||j|j�}|��|S)Nr+r,�rr)rrr
rrr�insertr	rrr�sort)r;r=rrrrZ
time_floatrrrZ__process_stem�s 
zNTPStats.__process_stemc	Csb|jr|jS|jD]H}z0|d}||jvr4g|j|<|j|�|�WqtyXYq0q|jS)zoReturn a dictionary mapping peerstats IPs to entry subsets.
        This is very expensive, so cache the result�)�peermapr(r�
IndexError)r;�rowZ
ip_addressrrr�	peersplit�s


zNTPStats.peersplitc	CsRi}|jD]B}z*|d}||vr(g||<||�|�Wq
tyJYq
0q
|S)z9Return a dictionary mapping gps sources to entry subsets.rM)r,rrO)r;ZgpsmaprP�sourcerrr�gpssplit�s
zNTPStats.gpssplitc	CsRi}|jD]B}z*|d}||vr(g||<||�|�Wq
tyJYq
0q
|S)zAReturn a dictionary mapping temperature sources to entry subsets.rM)r+rrO)r;ZtempsmaprPrRrrr�
tempssplit�s
zNTPStats.tempssplit)NNNN)�__name__�
__module__�__qualname__�__doc__rr-rNr.rrr2�staticmethodrrrr&r>r8r9rQrSrTrrrrrs0



�
) rcCs*t|���rt|�St�|d�}t�|�S)zEAccept timestamps in ISO 8661 format or numeric POSIX time. UTC only.�%Y-%m-%dT%H:%M:%S)r
r!r	r�strptime�calendarZtimegm)Ztime_stringZtime_structrrr�iso_to_posix�sr]cCst�dt�|��S)z&ISO 8601 string in UTC from Unix time.rZ)r�strftime�gmtime)Z	unix_timerrr�posix_to_isosr`)rXZ
__future__rrr\rBrEr/r#r4rrr]r`rrrr�<module>sd