Reputation: 1545
I try to run influxdb as a Docker container. I am using docker-compose for that:
influxdb:
image: influxdb:1.7.7-alpine
ports:
- "8083:8083"
- "8086:8086"
- "8090:8090"
volumes:
- ./influxdb-data:/var/lib/influxdb
networks:
- mynet
expose:
- "8086"
environment:
TZ: Europe/Prague
The problem is the timezone. I don't know how to start InfluxDB in my local timezone, here you can see the problem:
[michal@motoko ~]$ LC_ALL=C date
Fri Aug 23 07:38:44 CEST 2019
[michal@motoko ~]$ LC_ALL=C influx -host 'localhost'
Connected to http://localhost:8086 version 1.7.7
InfluxDB shell version: 1.7.7
> use test Using database test
> insert test value=4
> precision rfc3339
> select * from test
name: test
time value
---- ----
2019-08-23T05:39:09.017460215Z 4
>
As you can see (correct) real time at my machine is "07:38:44" while timestamp stored in database is "05:39:09". I am in UTC+2 timezone.
Can InfluxDB in Docker run in my local timezone? I've tried to set TZ
variable but InfluxDB probably needs /etc/timezone
. I haven't found InfluxDB configuration parameter for that.
Or do I need to use tz()
in every query? This works correctly:
> select * from test tz('Europe/Prague')
name: test
time value
---- -----
2019-08-23T07:39:09.017460215+02:00 4
Upvotes: 4
Views: 4535
Reputation: 135
In InfluxDB, the timestamp for your data point in nanosecond-precision Unix time. The timestamp is optional in line protocol. If you do not specify a timestamp for your data point InfluxDB uses the server’s local nanosecond timestamp in UTC. So, when you insert the data, you don't specify the timestamp. The timestamp for the data was the real time on your machine. But you can try with:
SELECT_clause [INTO_clause] FROM_clause [WHERE_clause] [GROUP_BY_clause] [ORDER_BY_clause] [LIMIT_clause] [OFFSET_clause] [SLIMIT_clause] [SOFFSET_clause] tz('<time_zone>')
The tz() clause returns the UTC offset for the specified timezone.
Or you can just change the default of your docker container.
Upvotes: 2
Reputation: 79
In the docker-compose insert this:
environment:
- TZ=Europe/Prague
Then inside container check if the variable TZ
is present and date is changed. To check, connect to container docker exec -it influxdb-container bash
and
date
Tue Jun 28 21:57:31 CEST 2022
Upvotes: 0
Reputation: 3434
As mentioned on the comments, InfluxDB timezone is immutable by default. But as you mentioned, you can set your timezone using tz() command.
A possible solution is store your timezone on InfluxDB and use it within your queries.
Upvotes: 2