????
Current Path : /usr/lib/python3.6/site-packages/glances/exports/__pycache__/ |
Current File : //usr/lib/python3.6/site-packages/glances/exports/__pycache__/glances_zeromq.cpython-36.opt-1.pyc |
3 Eo�cg � @ sd d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z ddl Z ddlmZ G dd � d e�Z dS ) zZeroMQ interface class.� N)�b)�logger)� GlancesExport)� json_dumps)�asbytesc s: e Zd ZdZd� fdd� Zdd� Zdd� Zd d � Z� ZS )�Exportz,This class manages the ZeroMQ export module.Nc sT t t| �j||d� d| _| jddddgg d�| _| js@td� d| _| j� | _ dS ) zInit the ZeroMQ export IF.)�config�argsNZzeromq�host�port�prefix)ZmandatoriesZoptionszMissing ZEROMQ config) �superr �__init__r Z load_conf� export_enable�exit�context�init�client)�selfr r )� __class__� �$/usr/lib/python3.6/glances_zeromq.pyr s zExport.__init__c C s� | j s dS dj| j| j�}y&tj� | _| jjtj�}|j |� W n> t k r~ } z"tjd||f � t jd� W Y dd}~X nX tjd| � |S )z*Init the connection to the CouchDB server.Nztcp://{}:{}z'Cannot connect to ZeroMQ server %s (%s)� z!Connected to the ZeroMQ server %s)r �formatr r �zmqZContextr ZsocketZPUBZbind� Exceptionr Zcritical�sysr �info)r Z server_uriZ publisher�er r r r . s zExport.initc C s, | j dk r| j j� | jdk r(| jj� dS )zClose the socket and contextN)r �closer Zdestroy)r r r r r A s zExport.exitc C s� t jdj|�� tt||��}|i kr*dS t| j�t|�tt|��g}y| j j |� W n4 tk r� } zt jdj||�� W Y dd}~X nX dS )z&Write the points to the ZeroMQ server.zExport {} stats to ZeroMQFz%Cannot export {} stats to ZeroMQ ({})NT) r �debugr �dict�zipr r r r r Zsend_multipartr �error)r �name�columnsZpoints�data�messager r r r �exportH s $z Export.export)NN) �__name__� __module__�__qualname__�__doc__r r r r( � __classcell__r r )r r r s r )r, r Zglances.compatr Zglances.loggerr Zglances.exports.glances_exportr Zglances.globalsr r Zzmq.utils.strtypesr r r r r r �<module> s