I have a weird issue. I’m importing data and setting the timestamps on the imported data. When I do not specify a time precision the series cardinality lines up properly but the rfc3339 times reported back are 1970’s times. When I specify the time precision then the time lines up properly using rfc3339 but the cardinality reported is much higher than what is reported by a ‘show series’. This is using 1.7.4-1 from influxdb’s xenial repository.
Here’s a script I wrote to test this
DATABASE = 'cardi'
HOST = '127.0.0.1'
PORT = 8086
USER = 'root'
PASSWORD = 'root'
from influxdb import InfluxDBClient
from random import randint
def influxdb_insert(db, json):
if not db:
raise Exception("pass in a db object")
if not json:
raise Exception("pass in a json object")
# Will cause the cardinality to be correct but rfc3339 times to be 1970
# db.write_points(json)
# Will cause the cardinality to be higher than it should but rfc3339 to be correct
db.write_points(json, time_precision='s')
if __name__ == "__main__":
client = InfluxDBClient(host=HOST, port=PORT, username=USER, password=PASSWORD, database=DATABASE)
client.drop_database(DATABASE)
client.create_database(DATABASE)
client.switch_database(DATABASE)
json_list = []
epoch = 1545441300
time_interval = 60
meter_start = 10005
meters = 100
records_per_meter = 5000
record = 0
total_records = meters * records_per_meter
for meter in range(meter_start, meter_start + meters):
while record <= records_per_meter:
json_list.append({
"measurement": "meter",
"tags": {
"MeterNumber": meter
},
"time": epoch,
"fields": {
"MeterValue": randint(1, 100)
}})
epoch += time_interval
record += 1
if len(json_list) == records_per_meter:
influxdb_insert(client, json_list)
json_list = []
record = 0
Running with time_precision=‘s’ I get the following results
influx -database cardi -execute 'show series' |grep meter |wc -l;
100
influx -execute 'show series exact cardinality on cardi';
150
influx -execute 'select COUNT(MeterValue) FROM cardi.autogen.meter'
500000
influx -precision 'rfc3339' -database 'cardi' -execute 'select * from meter limit 10'
time MeterNumber MeterValue
2018-12-22T01:15:00Z 10005 72
2018-12-22T01:16:00Z 10005 33
2018-12-22T01:17:00Z 10005 56
2018-12-22T01:18:00Z 10005 54
2018-12-22T01:19:00Z 10005 8
2018-12-22T01:20:00Z 10005 72
2018-12-22T01:21:00Z 10005 30
2018-12-22T01:22:00Z 10005 54
2018-12-22T01:23:00Z 10005 84
2018-12-22T01:24:00Z 10005 36
Running this with no time_precision set provides the following results.
influx -database cardi -execute 'show series' |grep meter |wc -l;
100
influx -execute 'show series exact cardinality on cardi';
100
influx -execute 'select COUNT(MeterValue) FROM cardi.autogen.meter'
500000
influx -precision 'rfc3339' -database 'cardi' -execute 'select * from meter limit 10'
time MeterNumber MeterValue
1970-01-01T00:00:01.5454413Z 10005 96
1970-01-01T00:00:01.54544136Z 10005 70
1970-01-01T00:00:01.54544142Z 10005 53
1970-01-01T00:00:01.54544148Z 10005 31
1970-01-01T00:00:01.54544154Z 10005 28
1970-01-01T00:00:01.5454416Z 10005 52
1970-01-01T00:00:01.54544166Z 10005 70
1970-01-01T00:00:01.54544172Z 10005 59
1970-01-01T00:00:01.54544178Z 10005 37
1970-01-01T00:00:01.54544184Z 10005 14