I’m a bit confused why Influx is wanting to store my tag values as field values. I’m using the Python api and writing data with the following code for the very first write. This should set source and type as tags. Hoping someone can see something that I’m missing.
measurement = "filter"
current_filter_change = 0 # first time we are writing to DB
# write record to DB
filter_tags = {"source": "python_app", "type": "change"}
filter_fields = {"current_filter_change": current_filter_change}
influxdb_write(measurement, filter_tags, filter_fields)
and then the following for all subsequent writes:
filter_tags = {"type": "reading", "source": "python_app"}
filter_fields = {"adc": values[3], "voltage": voltage , "psi": psi, "pump1_rpm": current_pump1_rpm,
"current_filter_change": current_filter_change}
influxdb_write(measurement, filter_tags, filter_fields)
The function influxdb_write is just a wrapper for the proper format:
def influxdb_write(measurement, tags, fields):
global client
# Expecting measurement to be a name, tags to be a json object, and fields to be a json object.
# We will not pass time and let the database handle that.
# >>> example json_body = [
# {
# "measurement": "cpu_load_short",
# "tags": {
# "host": "server01",
# "region": "us-west"
# },
# "time": "2009-11-10T23:00:00Z",
# "fields": {
# "value": 0.64
# }
# }
# ]
# >>> client.write_points(json_body, time_precision='s')
json_body = [
{
"measurement": measurement,
"tags": tags,
"fields": fields
}
]
print(json_body)
result = client.write_points(json_body,'s')
if result == False:
log("ERROR!!! Write result for {0} is {1}".format(measurement,result))
send_sms_alert("InfluxDB", "Cannot reach server.")
The output of the print statement looks good as well…
[{'fields': {'current_filter_change': 0}, 'tags': {'source': 'python_app', 'type': 'change'}, 'measurement': 'filter'}]
[{'fields': {'current_filter_change': 0, 'psi': 2.53, 'pump1_rpm': 1400, 'adc': 4810, 'voltage': 0.6}, 'tags': {'source': 'python_app', 'type': 'reading'}, 'measurement': 'filter'}]
However, running a select * from filter
in InfluxCLI I see:
> select * from filter order by desc
name: filter
time adc current_filter_change psi pump1_rpm source source_1 type type_1 voltage
---- --- --------------------- --- --------- ------ -------- ---- ------ -------
2018-06-15T05:31:01Z 0 python_app change
2018-06-15T05:29:52Z 4806 0 2.52 1400 python_app reading 0.6
I’m never writing the source and type as field values, but Influx is storing them as such.
show field keys
has the following entries:
name: filter
fieldKey fieldType
-------- ---------
adc integer
current_filter_change integer
psi float
pump1_rpm integer
source string
type string
voltage float
as does show tag keys
:
name: filter
tagKey
------
source
type
Please help me understand why Influx would create the source and type tags, but never store any data in them as I’m expecting.