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

Monitor a process by executing a command line. This is the default AMP's behavor
if no AMP script is found.

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

[amp_foo]
enable=true
regex=\/usr\/bin\/foo
refresh=10
one_line=false
command=foo status
    )check_outputSTDOUTCalledProcessError)uto_ascii)logger)
GlancesAmpc                       s>   e Zd ZdZdZdZdZdZdZd fdd	Z	d	d
 Z
  ZS )AmpzGlances' Default AMP. z1.1Z	Nicolargozcontact@nicolargo.comNc                    s"   |  | _tt| j||d dS )zInit the AMP.)nameargsN)
capitalizeNAMEsuperr	   __init__)selfr   r   	__class__ >/usr/lib/python3/dist-packages/glances/amps/glances_default.pyr   6   s   
zAmp.__init__c              
   C   s(  t d| j| d z| d}W n  ty4 } zt d| j| |  W  Y d}~S d}~ww |du rT| dtdd |D td	d |D  |  S z$d
}|	dD ]}|t
t|	 td7 }q\| t|  W |  S  ty } z| |j W Y d}~|  S d}~ww )zUpdate the AMPz%{}: Update AMP stats using command {}Zservice_cmdZcommandz&{}: Error while executing command ({})NzCPU: {:.1f}% | MEM: {:.1f}%c                 S      g | ]}|d  qS )Zcpu_percentr   .0pr   r   r   
<listcomp>J       zAmp.update.<locals>.<listcomp>c                 S   r   )Zmemory_percentr   r   r   r   r   r   K   r   r
   ;)stderr)r   debugformatr   getOSErrorresultZ
set_resultsumsplitr   r   r   r   rstripr   output)r   Zprocess_listresemsgcmdr   r   r   update;   s2   z
Amp.update)NN)__name__
__module____qualname____doc__r   ZVERSIONZDESCRIPTIONZAUTHORZEMAILr   r+   __classcell__r   r   r   r   r	   -   s    r	   N)r/   
subprocessr   r   r   Zglances.compatr   r   Zglances.loggerr   Zglances.amps.glances_ampr   r	   r   r   r   r   <module>   s   