Repository URL to install this package:
|
Version:
2.0.0-beta3-2-armbian20.08.0-trunk1 ▾
|
wiperf
/
usr
/
local
/
lib
/
python3.7
/
dist-packages
/
influxdb
/
__pycache__
/
helper.cpython-37.pyc
|
|---|
B
§:0]Úbã @ sx d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZmZ ddl m Z ddl
mZ dd lZG d
d de
Zd S )zHelper class for InfluxDB.é )Úabsolute_import)Údivision)Úprint_function)Úunicode_literals)Ú
namedtupleÚdefaultdict)Údatetime)ÚwarnNc s^ e Zd ZdZdZ fddZdd Zeddd Zed
d Z edd
Z
edd Z Z
S )ÚSeriesHelperaï Subclass this helper eases writing data points in bulk.
All data points are immutable, ensuring they do not get overwritten.
Each subclass can write to its own database.
The time series names can also be based on one or more defined fields.
The field "time" can be specified when creating a point, and may be any of
the time types supported by the client (i.e. str, datetime, int).
If the time is not specified, the current system time (utc) will be used.
Annotated example::
class MySeriesHelper(SeriesHelper):
class Meta:
# Meta class stores time series helper configuration.
series_name = 'events.stats.{server_name}'
# Series name must be a string, curly brackets for dynamic use.
fields = ['time', 'server_name']
# Defines all the fields in this time series.
### Following attributes are optional. ###
client = TestSeriesHelper.client
# Client should be an instance of InfluxDBClient.
:warning: Only used if autocommit is True.
bulk_size = 5
# Defines the number of data points to write simultaneously.
# Only applicable if autocommit is True.
autocommit = True
# If True and no bulk_size, then will set bulk_size to 1.
retention_policy = 'your_retention_policy'
# Specify the retention policy for the data points
time_precision = "h"|"m"|s"|"ms"|"u"|"ns"
# Default is ns (nanoseconds)
# Setting time precision while writing point
# You should also make sure time is set in the given precision
Fc sð | j sàd| _ yt| d}W n$ tk
r@ td | j¡Y nX xNdD ]F}yt| d| t|| W qH tk
r td || j¡Y qHX qHW t|dd| _t|d d
| _ddd
dddd
g}| j|krâtd | jd |¡¡t|dd
| _ t|dd
| _
| jr| j
std | j¡y:t|d| _| jdk rV| jrVtd | j¡ d| _W n tk
rt d| _Y nX | jstd | j¡ t
t| _d| jkr°| j d¡ t| jdg| j | j | _dt| j | jj_tt| | ¡S )zÂInitialize class attributes for subsequent constructor calls.
:note: *args and **kwargs are not explicitly used in this function,
but needed for Python 2 compatibility.
TZMetazMissing Meta class in {0}.)Úseries_nameÚfieldsÚtagsÚ_zMissing {0} in {1} Meta class.Z
autocommitFÚtime_precisionNÚhÚmÚsÚmsÚuÚnsz9In {0}, time_precision is set, but invalid use any of {}.ú,Úretention_policyÚclientz8In {0}, autocommit is set to True, but no client is set.Z bulk_sizeé z<Definition of bulk_size in {0} forced to 1, was less than 1.éÿÿÿÿzIDefinition of bulk_size in {0} has no affect because autocommit is false.Útime)N)Ú__initialized__ÚgetattrÚAttributeErrorÚformatÚ__name__ÚsetattrÚ_autocommitÚ_time_precisionÚjoinÚ_retention_policyÚ_clientÚ
_bulk_sizer r ÚlistÚ_datapointsÚ_fieldsÚremover Ú_tagsÚ_typeÚlenÚ__new__Ú__defaults__Úsuperr
)ÚclsÚargsÚkwargsZ_metaÚattrZallowed_time_precisions)Ú __class__© ú5/tmp/pip-install-4lg_ekbd/influxdb/influxdb/helper.pyr/ 7 sb
zSeriesHelper.__new__c K sÐ | j }| d| ¡ ¡}t|j}t|j}t| ¡ }||ksTtd |j| ¡ ¡|| |ksvtd || | ¡|j |j
jf | |jf d|i|¡ |j
rÌtdd |j ¡ D |jkrÌ| ¡ dS )zÁCall to constructor creates a new data point.
:note: Data points written when `bulk_size` is reached per Helper.
:warning: Data points are *immutable* (`namedtuples`).
r z<Expected arguments to contain all tags {0}, instead got {1}.z(Got arguments not in tags or fields: {0}c s s | ]}t |V qd S )N)r. )Ú.0Zseriesr7 r7 r8 ú <genexpr> s z(SeriesHelper.__init__.<locals>.<genexpr>N)r6 ÚpopÚ_current_timestampÚsetr, r* ÚkeysÚ NameErrorr r) Z_series_nameÚappendr- r" ÚsumÚvaluesr' Úcommit)ÚselfÚkwr2 Ú timestampr
r r>