Reputation: 2970
In my nodejs application, I am using influxdb (time series database) to save my log data. I used node-influx to write points in influxdb. But in my case, there are multiple log data which have same timestamp. In that case, only the last data is saved in the db.
I debugged the scripts and found javascript Date only contains milliseconds So in my case, multiple data have same timestamp as they vary on microseconds. So I need a Date format which give me the current date time with microseconds. Or is there any proper way to write multiple points having same timestamp in influxdb?
Upvotes: 2
Views: 5220
Reputation: 19298
According to the InfluxDB documentation, point data timestamp can be as fine grain as in nanoseconds.
Writing data using the HTTP API
The HTTP API is the primary means of putting data into InfluxDB. To write data send a POST request to the /write endpoint. The example below writes a single point to the mydb database. The data consist of the measurement cpu_load_short, the tag keys host and region with the tag values server01 and us-west, the field key value with a field value of 0.64, and the timestamp 1434055562000000000.
Note: timestamp 1434055562000000000
.
As for writing point in nanoseconds using the npm node-influx module, you can use set the precision as 'ns' (nano-seconds). That is, precision: 'ns'
. To write points through the influx node module, it does not require you to have date objects thou, so if you know the exact date timestamp value since epoch, you can just pass in as 64 bit integer values for it to write into influx.
See example code here.
var influx = require('influx');
var databaseWriter = influx({
host: 'XXX',
port: 'XXX',
protocol: 'XXX',
username: 'XXX',
password: 'XXX',
database: 'XXX'
});
this.databaseWriter.writePoints(
'influx_stackoverflow_solution',
[
// point #1
[
{
"value": 999,
"time" : 1422568543702900257
},
{
'tag1' : 'value_in_nanoseconds'
}
],
// point #2
[
{
"value": 8888,
"time" : 1422568543702900600
},
{
'tag1' : 'value_in_nanoseconds'
}
]
],
{ precision: 'ns' },
function(errmsg, returnValue) {
if (errmsg) return callback(new Error(errmsg));
callback(null, returnValue);
}
);
Upvotes: 1
Reputation: 1018
Influxdb is designed to hold only one point when the conditions(timestamps,measurement,tags) are identical, so you can accomplish this in two different ways:
insert points by different timestamps in js with microsecond(stackoverflow)
try to use different tags when you add multi points with same timestamps (influxdata_writing_data),such as
api_info,tag=tag1 elapse=0.234 1467085047286(timestamp is optional)
api_info,tag=tag2 elapse=0.478 1467085047286(timestamp is optional)
Upvotes: 4