Timestamp issued when trying to write into influxdb
cobras opened this issue · comments
Specifications
- Client Version: 1.29.0
- InfluxDB Version: 2.4.0
- Platform: Linux/Debian
When I try to write into a bucket. I'm facing a timestamps issue. When I look into InfluxDB->Data Explorer the _time field show me bad values.
Code sample to reproduce problem
const influxdb = new InfluxDB(influxInfo)
const writeApi = influxdb.getWriteApi(INFLUX_ORG, INFLUX_BUCKET)
writeApi.useDefaultTags({ region: 'sensor' })
const data = [{
time: '2022-09-28 15:00:26.416',
raw: 500,
comp: 5.1757612228393555,
trigger: 128
}, {
time: '2022-09-28 10:29:32.426',
raw: 501,
comp: 5.201683521270752,
trigger: 128
}, {
time: '2022-09-28 12:39:32.436',
raw: 502,
comp: 5.302785758972168,
trigger: 128
}];
const st = []
data.forEach(item => {
const pt = new Point('b1')
.tag('raw', item.raw)
.floatField('value', item.comp)
.timestamp(new Date(item.time))
st.push(pt)
})
try {
writeApi.writePoints(st)
await writeApi.close()
} catch (e) {
console.error(e)
if (e instanceof HttpError && e.statusCode === 401) {
console.log('Run ./onboarding.js to setup a new InfluxDB database.')
}
console.log('\nFinished ERROR')
}
console.log('WRITE FINISHED')
Expected behavior
I expect _time to show:
2022-09-28T15:00:26.416Z
2022-09-28T10:29:32.426Z
2022-09-28T12:39:32.436Z
Actual behavior
I have
2022-09-28T14:00:00.000Z
2022-09-28T09:00:00.000Z
2022-09-28T11:00:00.000Z
Additional info
May be I make it in the wrong way because I'm new to influxDB
Hi, thank you for using the client and reporting an issue. The time in your timestamps does not include a timezone, new Date('2022-09-28 15:00:26.416')
is in your local time zone. Append Z
to your time strings to match your expectations, it should be new Date('2022-09-28 15:00:26.416Z')
.
The hour roundings in your results are caused by the explorer UI, it OOTB aggregates points into time windows for which the mean value is computed:
Switch to Script Editor
, and delete the row with |> aggregateWindow ...
to observe the exact points that were sent.