Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How send proper timestamp to influxdb with influxdb-python

I have influxdb database test with measurement:

name: mes1
time          Amount     Buy_order_id Price     
----          ------     ------------ -----     
1529832177822 0.02294    132868375    130117.83 

I would like to make graph in Grafana, but all data are in year 1970. I have other measurement:

name: cpu_load_short
time                Bool_value Float_value Int_value String_value host     region
----                ---------- ----------- --------- ------------ ----     ------
1257894000000000000 true       0.64        3         Text         server01 us-west

This time works fine. I figure out, that time in measurement cpu_load_short are stored in ns, but data in measurement mes1 are stored in ms.

I receiveing time for mes1 from websocket. Time for cpu_load_short is generated from python:

datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')

All data are sent to influxdb via influxdb-python. I tried to adjust time for mes1 and add six zeros in the end of number:

'1529832177822' -> '1529832177822000000'

but I received:

OverflowError: signed integer is greater than maximum

How can I send data to influxdb and make graph from it, so the data will be in proper format and the right date? Maybe I missing something but I can't figure out why I cant send data to my database in ns but I can send it with datetime. Could anybody explain me, where is the problem?

like image 660
dorinand Avatar asked Jun 24 '18 23:06

dorinand


1 Answers

I have encountered the same issue and was able to solve it, let me try to guide you.

When you write your points to InfluxDB using the influxdb-python client you can specify the time precision in the write_points method. (http://influxdb-python.readthedocs.io/en/latest/api-documentation.html#influxdb.DataFrameClient.write_points)

An example:

from influxdb import InfluxDBClient
client = InfluxDBClient(host=host, port=port, database=database)
client.write_points(value, time_precision='ms')

This will convert your ms to ns for you. Hope this helps.

like image 139
Stanko Avatar answered Sep 22 '22 08:09

Stanko