File: //lib/python3.6/site-packages/glances/exports/__pycache__/glances_statsd.cpython-36.pyc
3
Eo�c � @ s\ d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
G dd� de�Zd d
� ZdS )zStatsd interface class.� )�Number)�range)�logger)�
GlancesExport)�StatsClientc s2 e Zd ZdZd � fdd� Zdd� Zdd� Z� ZS )
�Exportz,This class manages the Statsd export module.Nc s^ t t| �j||d� d| _| jdddgdgd�| _| js@td� | jdkrPd | _| j� | _dS )
zInit the Statsd export IF.)�config�argsN�statsd�host�port�prefix)ZmandatoriesZoptionszMissing STATSD configZglances) �superr �__init__r
Z load_conf�
export_enable�exit�init�client)�selfr r )� __class__� �$/usr/lib/python3.6/glances_statsd.pyr s
zExport.__init__c C s8 | j s
dS tjdj| j| j�� t| jt| j�| jd�S )z)Init the connection to the Statsd server.Nz.Stats will be exported to StatsD server: {}:{})r
) r r �info�formatr r r �intr
)r r r r r / s zExport.initc C s� x�t t|��D ]t}t|| t�s"qdj||| �}|| }y| jjt|�|� W q tk
r� } zt j
d| � W Y dd}~X qX qW t jdj|�� dS )z&Export the stats to the Statsd server.z{}.{}z#Can not export stats to Statsd (%s)NzExport {} stats to Statsd)r �len�
isinstancer r r Zgauge� normalize� Exceptionr �error�debug)r �name�columnsZpoints�iZ stat_nameZ
stat_value�er r r �export6 s $z
Export.export)NN)�__name__�
__module__�__qualname__�__doc__r r r% �
__classcell__r r )r r r s r c C s( | j dd�}|j dd�}|j dd�}|S )z(Normalize name for the Statsd convention�:� �%� �_)�replace)r! �retr r r r D s r N)
r) Znumbersr Zglances.compatr Zglances.loggerr Zglances.exports.glances_exportr r
r r r r r r r �<module>
s /