I have a csv file that contains historical measurements that I am trying to write to InfluxDB.
I have converted the timestamps to that which InfluxDB seems to like if I enter things manually.
Example data from CSV:
1490252400000000000,62
1490338800000000000,23
Timestamp and measurement, pretty simple.
I can manually insert things as such:
> insert portcount ports=62 1490252400000000000
> select * from portcount
name: portcount
time ports
---- -----
1490252400000000000 62
My python script simple runs through each line of the csv and extracts what is needed and then should write the points to the database.
Example:
import influxdb
from influxdb import client as influxdb
portcount = {}
with open(r'portcountlog.csv', 'r') as h:
for line in h:
log = line.strip('\n').split(',')
loglist = []
logentry = {}
logentry['measurement'] = "portcount"
logentry['time'] = log[0]
logentry['fields'] = {}
logentry['fields']['ports'] = log[1]
loglist.append(logentry)
print (loglist)
db.write_points(loglist)
When I try running it I can see the data is correct for the line but it seems as though something in the client is trying generate its own timestamp or something?
[user@itnetops scripts]$ python oldportcounts.py
[{'fields': {'ports': '2\r'}, 'time': '1489647600000000000', 'measurement': 'portcount'}]
Traceback (most recent call last):
File "oldportcounts.py", line 26, in <module>
db.write_points(loglist)
File "/usr/lib/python2.7/site-packages/influxdb/client.py", line 456, in write_points
tags=tags, protocol=protocol)
File "/usr/lib/python2.7/site-packages/influxdb/client.py", line 506, in _write_points
protocol=protocol
File "/usr/lib/python2.7/site-packages/influxdb/client.py", line 292, in write
data = make_lines(data, precision).encode('utf-8')
File "/usr/lib/python2.7/site-packages/influxdb/line_protocol.py", line 160, in make_lines
_convert_timestamp(point['time'], precision)
File "/usr/lib/python2.7/site-packages/influxdb/line_protocol.py", line 22, in _convert_timestamp
timestamp = parse(timestamp)
File "/usr/lib/python2.7/site-packages/dateutil/parser.py", line 1168, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "/usr/lib/python2.7/site-packages/dateutil/parser.py", line 578, in parse
if cday > monthrange(cyear, cmonth)[1]:
File "/usr/lib64/python2.7/calendar.py", line 121, in monthrange
day1 = weekday(year, month, 1)
File "/usr/lib64/python2.7/calendar.py", line 113, in weekday
return datetime.date(year, month, day).weekday()
OverflowError: signed integer is greater than maximum
Is it trying to convert the timestamp I provided? It shouldn’t have to convert since it is in the format that InfluxDB uses? Any suggestions or advice on getting this to work?