o
    Ìv›a^  ã                   @   sP   d Z ddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
 G dd„ de
ƒZdS )	aË  
Systemd AMP
===========

Monitor the state of the systemd system and service (unit) manager.

How to read the stats
---------------------

active: Number of active units. This is usually a fairly basic way to tell if the
unit has started successfully or not.
loaded: Number of loaded units (unit's configuration has been parsed by systemd).
failed: Number of units with an active failed status.

Source reference: https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units

Configuration file example
--------------------------

[amp_systemd]
# Systemd
enable=true
regex=\/usr\/lib\/systemd\/systemd
refresh=60
one_line=true
systemctl_cmd=/usr/bin/systemctl --plain
é    )Úcheck_outputÚCalledProcessError)Úlogger)Ú	iteritemsÚto_ascii)Ú
GlancesAmpc                   @   s,   e Zd ZdZdZdZdZdZdZdd„ Z	d	S )
ÚAmpzGlances' Systemd AMP.ZSystemdz1.0z*Get services list from systemctl (systemd)Z	Nicolargozcontact@nicolargo.comc              
   C   s*  t  d | j|  d¡¡¡ zt|  d¡ ¡ ƒ}W n! ttfy9 } zt  d | j|¡¡ W Y d}~|  ¡ S d}~ww i }t	|ƒ d¡dd… D ]/}| ¡ }t
|ƒdkrvtddƒD ]}z|||   d7  < W qX tyu   d||| < Y qXw qGd	}t|ƒD ]\}	}
|d
 |	|
¡7 }q}| j|dd |  ¡ S )zUpdate the AMPz#{}: Update stats using systemctl {}Zsystemctl_cmdz({}: Error while executing systemctl ({})NÚ
é   iøÿÿÿé   z	Services
z{}: {}
ú )Z	separator)r   ÚdebugÚformatÚNAMEÚgetr   ÚsplitÚOSErrorr   r   ÚlenÚrangeÚKeyErrorr   Z
set_resultÚresult)ÚselfZprocess_listÚresÚeÚstatusÚrÚcolumnÚcÚoutputÚkÚv© r!   ú>/usr/lib/python3/dist-packages/glances/amps/glances_systemd.pyÚupdateD   s0   €ëÿ€z
Amp.updateN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZVERSIONZDESCRIPTIONZAUTHORZEMAILr#   r!   r!   r!   r"   r   7   s    r   N)r'   Ú
subprocessr   r   Zglances.loggerr   Zglances.compatr   r   Zglances.amps.glances_ampr   r   r!   r!   r!   r"   Ú<module>   s   