HEX
Server: LiteSpeed
System: Linux baran.dnsprotection.me 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
User: ddir12 (3618)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/glances/exports/__pycache__/glances_influxdb2.cpython-36.opt-1.pyc
3

Eo�cL�@sTdZddlZddlmZddlmZddlmZddlm	Z	m
Z
Gdd�de�ZdS)	z1InfluxDB (from to InfluxDB 1.8+) interface class.�N)�node)�logger)�
GlancesExport)�InfluxDBClient�WriteOptionscs:eZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Z�ZS)�Exportz.This class manages the InfluxDB export module.Nc	s�tt|�j||d�d|_d|_d|_d|_d|_d|_d|_	|j
dddddd	d
dgdd
dgd�|_|jsrtd�t
�jd�d|_	|j�|_dS)zInit the InfluxDB export IF.)�config�argsNZhttpZ	influxdb2�host�port�userZpassword�org�bucket�token�protocol�prefix�tags)ZmandatoriesZoptionsz!Missing INFLUXDB version 1 config�.r)�superr�__init__r
rrrrr�hostnameZ	load_conf�
export_enable�exitr�split�init�client)�selfrr	)�	__class__��'/usr/lib/python3.6/glances_influxdb2.pyrs zExport.__init__cCs�|js
dSdj|j|j|j�}yt|dd|j|jd�}Wn>tk
rv}z"t	j
d||f�tjd�WYdd}~Xn Xt	j
dj|j�j|j�j��|jtdd	d
ddd
dd�d�}|S)z+Init the connection to the InfluxDB server.Nz
{}://{}:{}F)�urlZenable_gzipZ
verify_sslr
rz+Cannot connect to InfluxDB server '%s' (%s)�z,Connected to InfluxDB server version {} ({})i�i'i�i��i0u)Z
batch_sizeZflush_intervalZjitter_intervalZretry_intervalZmax_retriesZmax_retry_delayZexponential_base)Z
write_options)r�formatrr
rrr
r�	ExceptionrZcritical�sysr�infoZhealth�version�messageZ	write_apir)rr r�eZwrite_clientrrrr6s(zExport.initc	sFg}tt||���dd�|D�}t|�dkr2dg}�x|D�]��dk	r^��fdd��D�}n�}xv|D]n}||dkrzqhyt||�||<Wqhttfk
r�yt||�||<Wnttfk
r�YnXYqhXqhW|j|j�}d|ko�|d|k�r"t||d�||d<|j	|d�|j
|d<|j|||d	��q:W|S)
z`Normalize data for the InfluxDB's data model.

        :return: a list of measurements.
        cSs$g|]}|jd�r|jd�d�qS)z.keyrr)�endswithr)�.0�krrr�
<listcomp>asz%Export._normalize.<locals>.<listcomp>rNcs4i|],}|jdj���r�||jdj��d��qS)z{}.�)�
startswithr#�replace)r+r,)�	data_dict�measurementrr�
<dictcomp>hsz%Export._normalize.<locals>.<dictcomp>�keyr)r2r�fields)�dict�zip�len�float�	TypeError�
ValueError�strZ
parse_tagsr�popr�append)	r�name�columns�points�retZ	keys_listr5r,rr)r1r2r�
_normalizeUs6


zExport._normalizecCs�|jdk	r|jd|}t|�dkr6tjdj|��nly&|jj|j|j|j	|||�dd�Wn4t
k
r�}ztjdj||��WYdd}~XnXtjdj|��dS)	z(Write the points to the InfluxDB server.Nrrz(Cannot export empty {} stats to InfluxDB�s)Ztime_precisionz'Cannot export {} stats to InfluxDB ({})zExport {} stats to InfluxDB)rr8r�debugr#r�writerr
rCr$)rr?r@rAr)rrr�export�s
&$z
Export.export)NN)	�__name__�
__module__�__qualname__�__doc__rrrCrG�
__classcell__rr)rrrs
7r)rKr%�platformrZglances.loggerrZglances.exports.glances_exportrZinfluxdb_clientrrrrrrr�<module>
s