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: //usr/lib/python3.6/site-packages/glances/exports/__pycache__/glances_influxdb.cpython-36.pyc
3

Eo�c��@s\dZddlZddlmZddlmZddlmZddlm	Z	ddl
mZGdd	�d	e�ZdS)
z0InfluxDB (up to InfluxDB 1.7.x) interface class.�N)�node)�logger)�
GlancesExport)�InfluxDBClient)�InfluxDBClientErrorcs:eZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Z�ZS)�Exportz.This class manages the InfluxDB export module.Ncs�tt|�j||d�d|_d|_d|_d|_d|_d|_d|_	|j
dddddd	gd
ddgd
�|_|jsntd�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
rrrrr�hostnameZ	load_conf�
export_enable�exitr�split�init�client)�selfrr	)�	__class__��&/usr/lib/python3.6/glances_influxdb.pyrszExport.__init__cCs�|js
dS|jdk	r(|jj�dkr(d}nd}y6t|j|j|d|j|j|jd�}dd�|j	�D�}Wn@t
k
r�}z$tjd|j|f�t
jd	�WYdd}~XnX|j|kr�tjd
j|j��ntjd|j�t
jd	�|S)z+Init the connection to the InfluxDB server.NZhttpsTF)rr�sslZ
verify_sslZusernamerZdatabasecSsg|]}|d�qS)�namer)�.0�irrr�
<listcomp>JszExport.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)rr�lowerrrrr
rrZget_list_databaserrZcritical�sysr�info�formatZ_baseurl)rr rZ
get_all_db�errrr5s.


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)r"�krrrr$csz%Export._normalize.<locals>.<listcomp>rNcs4i|],}|jdj���r�||jdj��d��qS)z{}.�)�
startswithr)�replace)r"r,)�	data_dict�measurementrr�
<dictcomp>jsz%Export._normalize.<locals>.<dictcomp>�keyr)r1r�fields)�dict�zip�len�float�	TypeError�
ValueError�strZ
parse_tagsr�popr�append)	rr!�columns�points�retZ	keys_listr4r,rr)r0r1r�
_normalizeWs6


zExport._normalizecCs�|jdk	r|jd|}t|�dkr6tjdj|��ndy|jj|j|||�dd�Wn4tk
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)	rr7r�debugr)rZwrite_pointsrA�	Exception)rr!r>r?r*rrr�export�s
$z
Export.export)NN)	�__name__�
__module__�__qualname__�__doc__rrrArE�
__classcell__rr)rrrs
"7r)
rIr'�platformrZglances.loggerrZglances.exports.glances_exportrr
rZinfluxdb.clientrrrrrr�<module>
s