o
    va
                     @   s`   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlZG dd de
ZdS )	zRiemann interface class.    N)Number)range)logger)GlancesExportc                       s2   e Zd ZdZd	 fdd	Zdd Zdd Z  ZS )
Exportz-This class manages the Riemann export module.Nc                    sR   t t| j||d | jdddgg d| _| jstd t | _	| 
 | _dS )zInit the Riemann export IF.)configargsZriemannhostport)Zmandatoriesoptions   N)superr   __init__Z	load_confexport_enablesysexitsocketZgethostnamehostnameinitclient)selfr   r   	__class__ A/usr/lib/python3/dist-packages/glances/exports/glances_riemann.pyr   &   s   	

zExport.__init__c              
   C   sX   | j sdS ztj| j| jd}|W S  ty+ } ztd|  W Y d}~dS d}~ww )z*Init the connection to the Riemann server.N)r	   r
   z"Connection to Riemann failed : %s )r   bernhardZClientr	   r
   	Exceptionr   Zcritical)r   r   er   r   r   r   =   s   zExport.initc                 C   s   t t|D ]?}t|| tsq| j|d ||  || d}t| z| j| W q t	yE } zt
d|  W Y d}~qd}~ww dS )zWrite the points in Riemann. )r	   serviceZmetricz#Cannot export stats to Riemann (%s)N)r   len
isinstancer   r   r   debugr   sendr   error)r   namecolumnsZpointsidatar   r   r   r   exportH   s   
zExport.export)NN)__name__
__module____qualname____doc__r   r   r)   __classcell__r   r   r   r   r   "   s
    r   )r-   r   r   Znumbersr   Zglances.compatr   Zglances.loggerr   Zglances.exports.glances_exportr   r   r   r   r   r   r   <module>   s   