o
    va                     @   sL   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 G dd de	Z
dS )	a  
SystemV AMP
===========

Monitor the state of the Syste V init system and service.

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

Running: Number of running services.
Stopped: Number of stopped services.
Upstart: Number of service managed by Upstart.

Source reference: http://askubuntu.com/questions/407075/how-to-read-service-status-all-results

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

[amp_systemv]
# Systemv
enable=true
regex=\/sbin\/init
refresh=60
one_line=true
service_cmd=/usr/bin/service --status-all
    )check_outputSTDOUT)logger)	iteritems)
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SystemVz1.0z&Get services list from service (initd)Z	Nicolargozcontact@nicolargo.comc           
   
   C   s@  t d| j| d zt| d tdd}W n t	y< } zt d| j| W Y d}~|  S d}~ww dddd}|d	D ]9}| }t
|d
k rUqH|d dkrd|d  d7  < qH|d dkrs|d  d7  < qH|d dkr|d  d7  < qHd}t|D ]\}}	|d||	7 }q| j|dd |  S )zUpdate the AMPz!{}: Update stats using service {}Zservice_cmd)stderrzutf-8z&{}: Error while executing service ({})Nr   )runningstoppedupstart
      +r	   -r
   ?r   z	Services
z{}: {}
 )Z	separator)r   debugformatNAMEgetr   splitr   decodeOSErrorlenr   Z
set_resultresult)
selfZprocess_listresestatusrloutputkv r%   >/usr/lib/python3/dist-packages/glances/amps/glances_systemv.pyupdateC   s2    z
Amp.updateN)
__name__
__module____qualname____doc__r   ZVERSIONZDESCRIPTIONZAUTHORZEMAILr'   r%   r%   r%   r&   r   6   s    r   N)r+   
subprocessr   r   Zglances.loggerr   Zglances.compatr   Zglances.amps.glances_ampr   r   r%   r%   r%   r&   <module>   s   