datalogd.plugins.influxdb2_datasink module¶
- class datalogd.plugins.influxdb2_datasink.InfluxDB2DataSink(url='http://localhost:8086', token='', org='default', bucket='default', measurement='measurement', run_id=None, field_key=None, field_value=None)[source]¶
Bases:
DataSinkConnection to a InfluxDB 2.x (or 1.8+) database for storing time-series data.
Note that this doesn’t actually run the InfluxDB database service, but simply connects to an existing InfluxDB database via a network (or localhost) connection. See the getting started documentation for details on configuring a new database server.
The
urlparameter should be a string specifying the protocol, server ip or name, and port. For example,url="http://localhost:8086".The authentication
tokenparameter needs to be specified to allow commits to the database. See the token documentation to see how to create and obtain tokens.Parameters for
org,bucketmust correspond to a valid organisation and bucket created in the database for which the authentication token is valid. See the documentation for organisations and buckets for details.The
measurementparameter specifies the data point measurement (or “table”) the data will be entered into, and does not need to already exist. See the documentation on data elements for details.A
run_idparameter may be passed which will be added as a tag to the data points. It may be used to identify data obtained from this particular run of the data logging session. If no value is provided, a value will be generated from a YYYYMMDD-HHMMSS formatted time stamp.The data point field key will be attempted to be determined automatically from the incoming data dictionaries. If the data dictionary contains a
nameorlabelkey, then its value will be used as the database point field key. Alternatively, a field key will be generated from the values oftypeandidif present. Finally, a default field key ofdatawill be used. To instead specify the data entry which should provide the field key, specify it as thefield_keyparameter. If the field is specified by a parameter or taken from a name or label, then those will not also be included in the entry’s database keys. However, if the field name is automatically built from type and id values, these will still be part of the entries keys.Similarly, the data point field value will use the value from the incoming data dictionary’s
valuefield if present. To instead specify the data entry which should provide the field value, specify it as thefield_valueparameter. The value won’t also appear in the database entry’s keys.- Parameters:
url – Protocol, host name or IP address, and port number of InfluxDB server.
token – API token used to authenticate with the InfluxDB server.
org – Name of InfluxDB organisation in which to store data.
bucket – Name of InfluxDB bucket in which to store data.
measurement – Name for the InfluxDB measurement session.
run_id – A tag to identify commits from this run.
field_key – A field from the incoming data used to determine the data point field key.
field_value – A field from the incoming data used to determine the data point field value.
- receive(data)[source]¶
Commit data to the InfluxDB database.
Multiple items of data can be submitted at once if
datais a list. A typical format ofdatawould be:[ {'type': 'temperature', 'id': '0', 'value': 22.35}, {'type': 'humidity', 'id': '0', 'value': 55.0}, {'type': 'temperature', 'id': '1', 'value': 25.80}, ]
In the above case (assuming the
field_keyandfield_valueparameters were not supplied when initialising the plugin), the InfluxDB data point field would be generated as<type>_<id> = <value>, and only the globalrun_idparameter would be entered into the data point keys.If a
nameorlabelfield is present, then it will instead be used as the InfluxDB data point field key. For example:[ {'name': 'Temperature', 'type': 'temperature', 'id': '0', 'value': 22.35}, {'name': 'Humidity', 'type': 'humidity', 'id': '0', 'value': 55.0}, ]
In this case, the InfluxDB data point field would be generated as
<name> = <value>, and the remaining fields (typeandid) would be added as data point field keys, along with therun_id.A timestamp for the commit will be generated using the current system clock if a “timestamp” field does not already exist.
- Parameters:
data – Data to commit to the database.