File: //usr/lib/python3.6/site-packages/glances/exports/__pycache__/glances_influxdb.cpython-36.opt-1.pyc
3
Eo�c� � @ s\ d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z ddl
mZ G dd � d e�ZdS )
z0InfluxDB (up to InfluxDB 1.7.x) interface class.� N)�node)�logger)�
GlancesExport)�InfluxDBClient)�InfluxDBClientErrorc s: e Zd ZdZd� fdd� Zdd� Zdd� Zd d
� Z� ZS )�Exportz.This class manages the InfluxDB export module.Nc s� t t| �j||d� d| _d| _d| _d| _d| _d| _d| _ | j
dddddd gd
ddgd
�| _| jsntd� t
� jd�d | _ | j� | _dS )zInit the InfluxDB export IF.)�config�argsNZhttp�influxdb�host�port�user�password�db�protocol�prefix�tags)ZmandatoriesZoptionsz!Missing INFLUXDB version 1 config�.r )�superr �__init__r
r r r r r �hostnameZ load_conf�
export_enable�exitr �split�init�client)�selfr r )� __class__� �&/usr/lib/python3.6/glances_influxdb.pyr s zExport.__init__c C s� | j s
dS | jdk r(| jj� dkr(d}nd}y6t| j| j|d| j| j| jd�}dd� |j � D �}W n@ t
k
r� } z$tjd| j|f � t
jd � W Y dd}~X nX | j|kr�tjd
j|j�� ntjd| j � t
jd � |S )z+Init the connection to the InfluxDB server.NZhttpsTF)r r �sslZ
verify_sslZusernamer Zdatabasec S s g | ]}|d �qS )�namer )�.0�ir r r �
<listcomp>J s zExport.init.<locals>.<listcomp>z-Cannot connect to InfluxDB database '%s' (%s)� z-Stats will be exported to InfluxDB server: {}z6InfluxDB database '%s' did not exist. Please create it)r r �lowerr r r r
r r Zget_list_databaser r Zcritical�sysr �info�formatZ_baseurl)r r r Z
get_all_db�er r r r 5 s.
zExport.initc sF g }t t||��� dd� |D �}t|�dkr2dg}�x|D �]��dk r^� �fdd�� D �}n� }xv|D ]n}|| dkrzqhyt|| �||<