I am getting familiar with Influx/Grafana to create a reporting platform.
I’ve run through the docs and am able to successfully write and query data, however I would like to add a custom timestamp to data I’m injecting so that I can group like entries to graph the sum.
my basic write works, however whatever way I attempt to add a timestamp the write does not complete and fails silently…
I have tried using epoch as an integer as well as various iterations through datetime formats, but can’t seem to figure it out - any advice welcome pls
$ influxd version
InfluxDB v2.7.0 (git: 85f725f8b9) build_date: 2023-04-05T15:32:25Z
Here is the code I am trying to execute (the first ‘point1’ definition works, the second does nothing):
write_api = client.write_api(write_options=SYNCHRONOUS)
now = datetime.now()
print(now)
fmt = now.strftime(‘%Y-%m-%dT%H:%M:%SZ’)
print(fmt)
Thanks for your comment - unfortunately that does not help; however it did put me on the right track
swapping out the write_precision does something, as if you change and put in delibarately wrong errors as a time var, then you will get messages such as out of range
ns is the default & works from a syntax point of view, however I’ve not found any library that works to ns granularity for python (other than time.now_ns() - however you cannot parse any arg to this to convert a time from the past)
If I fabricate a ‘ns’ timestamp based on epoch (either by 10^9 or random string to pad the spaces) the write fails, however using time.now() works fine… very confusing
I did find another comment that references a similar issue:
so bit stuck now, can’t work out how to change the unit to anything other than ns & cannot reliably create a epoch integer string in the past to 19 digits that the client/API accepts !!!
Note: If I put the same fabricated ns strings into an online epoch calculator; output is as expected and works fine; so its something to do with how the client/api processes and parses timestamps
believe me I’ve tried LOTS !!!
I’ve tried calculating by multiplication & concatanating a suffix and converting back to an integer, same result
Im obviously missing something…
I’m going to have to go back to basics and build it up again, I’m assuming now it must be syntax so will trying specifying attributes as JSON/Dictionary see if I get anwhere
Final update is I presuming there is some kind of bug/incompatability issue:
I have now tried numerous approaches including a Influx Git process & that doesn’t work with time field added
Dictionary/JSON etc… no effect
Time added in natively with ns precision does not work for me either
This excercise was to ingest historical data for analysis, which I now cannot complete. I will therefor have to move forward with timestamp added as data is ingested by the system
I am working on a similar thing, and am also newbie to both python and influxdb. I want to put power prices that I get from a rest API formatted in json into my influxdb2 database. Power prices are decided one day ahead for every hour so I want to do an API call once a day and put the data for the next day, and therefore set the timestamp for each record