javascript - How to write(nodejs) multiple points having same timestamp in influxdb? - Stack Overflow

In my nodejs application, I am using influxdb (time series database) to save my log data. I used node-i

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?

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?

Share Improve this question asked Jun 28, 2016 at 0:42 fyasirfyasir 2,9702 gold badges24 silver badges36 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Influxdb is designed to hold only one point when the conditions(timestamps,measurement,tags) are identical, so you can acplish this in two different ways:

  1. insert points by different timestamps in js with microsecond(stackoverflow)

  2. 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)

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);
    }
);

Output:

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745410631a4626516.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信