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_cassandra.cpython-36.pyc
3

Eo�c@�@s�dZddlZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZdd	l
mZdd
lmZGdd�de�ZdS)
z!Cassandra/Scylla interface class.�N)�datetime)�Number)�logger)�
GlancesExport)�PlainTextAuthProvider)�Cluster)�uuid_from_time)�InvalidRequestcs>eZdZdZd�fdd�	Zdd�Zdd�Z�fd	d
�Z�ZS)�Exportz6This class manages the Cassandra/Scylla export module.Ncs~tt|�j||d�d|_d|_d|_d|_d|_d|_|j	ddddgd	d
ddd
gd�|_
|j
sjtjd�|j
�\|_|_dS)zInit the Cassandra export IF.)�config�argsN���	cassandra�host�port�keyspace�protocol_version�replication_factor�table�username�password)ZmandatoriesZoptions)�superr
�__init__rrrrrrZ	load_conf�
export_enable�sys�exit�init�cluster�session)�selfrr)�	__class__��'/usr/lib/python3.6/glances_cassandra.pyrs
zExport.__init__c!CsN|js
dSt|j|jd�}y,t|jgt|j�t|j�|d�}|j	�}WnDt
k
r�}z(tjd|j|j|f�t
jd�WYdd}~XnXy|j|j�WnLtk
r�tjdj|j��d|j|jf}|j|�|j|j�YnXtjdj|jj|jj�|j��y|jd	|j�Wn&t
k
�rDtjd
|j�YnX||fS)z,Init the connection to the Cassandra server.N)rr)rr�
auth_providerz0Cannot connect to Cassandra cluster '%s:%s' (%s)rz+Create keyspace {} on the Cassandra clusterz_CREATE KEYSPACE %s WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '%s' }zBStats will be exported to Cassandra cluster {} ({}) in keyspace {}z�CREATE TABLE %s (plugin text, time timeuuid, stat map<text,float>, PRIMARY KEY (plugin, time)) WITH CLUSTERING ORDER BY (time DESC)z Cassandra table %s already exist)rrrrrr�intrrZconnect�	ExceptionrZcriticalrrZset_keyspacerr	�info�formatr�executeZmetadataZcluster_nameZ	all_hostsr�debug)r r$rr�e�cr"r"r#r7s@

zExport.initcCs�tjdj|��dd�tt||��j�D�}y8dj|j�}|jj|�}|jj	||t
tj��|f�Wn4t
k
r�}ztjdj||��WYdd}~XnXdS)z*Write the points to the Cassandra cluster.zExport {} stats to CassandracSs$i|]\}}t|t�rt|�|�qSr")�
isinstancer�float)�.0�k�vr"r"r#�
<dictcomp>nsz!Export.export.<locals>.<dictcomp>z4INSERT INTO {} (plugin, time, stat) VALUES (?, ?, ?)z(Cannot export {} stats to Cassandra ({})N)rr*r(�dict�zipZ	iteritemsrrZpreparer)rrZnowr&�error)r �name�columnsZpoints�dataZstmtZqueryr+r"r"r#�exportis z
Export.exportcs&|jj�|jj�tt|�j�dS)z"Close the Cassandra export module.N)rZshutdownrrr
r)r )r!r"r#rys

zExport.exit)NN)	�__name__�
__module__�__qualname__�__doc__rrr9r�
__classcell__r"r")r!r#r
s
2r
)r=rrZnumbersrZglances.loggerrZglances.exports.glances_exportrZcassandra.authrZcassandra.clusterrZcassandra.utilrrr	r
r"r"r"r#�<module>
s