admin管理员组

文章数量:1401122

I just started experimenting with influxDB and influxDB node module.

I have the following code, that inserts some random data every second. I get no errors but yet no data is added to my time series.

The code is:

var influxdb = require('influxdb');
var sleep = require('sleep');
var connection = influxdb('172.21.5.67', 8086);
connection.auth({ name: 'root', password: 'root' });

var db;
var ISCSIDataSeries;

function random (low, high) {
    return Math.floor(Math.random() * (high - low) + low);
}

function doInsert(i) {
    if (db == undefined) {
        db = connection.database('test');
        console.log('established the db connection');
    }

    if (ISCSIDataSeries == undefined) {
        ISCSIDataSeries = db.series('SCSIData');
        console.log('the series SCSIData is established');
    }

    var reads = random(1000, 10000);
    var writes = random(2000, 20000);
    var IOS = random(100000, 1000000);

    ISCSIDataSeries.writePoints({
        'columns': ['Volume', 'Reads', 'Writes'],
        'points':  [reads, writes, IOS]
    });

    db.save();
}

var i = 0;
while (i < 10) {
    sleep.sleep(1);
    doInsert(i);
    i ++;
}

console.log('so long folks');

At the end of the run I see no data entered. Any experience with this package?

I just started experimenting with influxDB and influxDB node module.

I have the following code, that inserts some random data every second. I get no errors but yet no data is added to my time series.

The code is:

var influxdb = require('influxdb');
var sleep = require('sleep');
var connection = influxdb('172.21.5.67', 8086);
connection.auth({ name: 'root', password: 'root' });

var db;
var ISCSIDataSeries;

function random (low, high) {
    return Math.floor(Math.random() * (high - low) + low);
}

function doInsert(i) {
    if (db == undefined) {
        db = connection.database('test');
        console.log('established the db connection');
    }

    if (ISCSIDataSeries == undefined) {
        ISCSIDataSeries = db.series('SCSIData');
        console.log('the series SCSIData is established');
    }

    var reads = random(1000, 10000);
    var writes = random(2000, 20000);
    var IOS = random(100000, 1000000);

    ISCSIDataSeries.writePoints({
        'columns': ['Volume', 'Reads', 'Writes'],
        'points':  [reads, writes, IOS]
    });

    db.save();
}

var i = 0;
while (i < 10) {
    sleep.sleep(1);
    doInsert(i);
    i ++;
}

console.log('so long folks');

At the end of the run I see no data entered. Any experience with this package?

Share Improve this question edited Jan 6, 2020 at 2:56 ottomeister 5,8282 gold badges25 silver badges27 bronze badges asked May 15, 2014 at 22:52 rezareza 6,35818 gold badges91 silver badges133 bronze badges 1
  • There is a good article influxdata./blog/getting-started-with-node-influx how to start with InfluxDB. – Aliaksei Maniuk Commented Aug 16, 2018 at 14:35
Add a ment  | 

1 Answer 1

Reset to default 7

I'm one of the maintainers of InfluxDB. We don't use node so I wasn't familiar with the library, but I tried your snippet and indeed it doesn't work. It turns out that the influxdb library isn't up to date and was last updated four months ago, during which InfluxDB api went through significant changes. I remend you switch to the influx package instead which seems to be more actively maintained. I modified your code snippet to work with the other package and it works succesfuly:

var influxdb = require('influx');
var sleep = require('sleep');

var root = new influxdb.InfluxDB('localhost', 8086, 'root', 'root');
root.createDatabase('SCSIData', function(err) {
  if (err && err.message.indexOf("exist") == -1) {
    console.log("Cannot create db", err);
    process.exit(1);
  };

  var client = new influxdb.InfluxDB('localhost', 8086, 'root', 'root', 'SCSIData');

  function random (low, high) { return Math.floor(Math.random() * (high - low) + low); }

  function doInsert(i) {
    var reads = random(1000, 10000);
    var writes = random(2000, 20000);
    var IOS = random(100000, 1000000);


    client.writePoint("series.name", {
      'Volume': IOS,
      'Reads': reads,
      'Writes': writes
    }, function(err) {
      if (err) {
        console.log("Cannot write data", err);
        process.exit(1);
      }
    });
  }

  var i = 0;
  while (i < 10) {
    doInsert(i);
    i++;
  }

  client.query("select count(Reads) from series.name", function(err, result) {
    if (err) {
      console.log("Cannot write data", err);
    }

    console.log("result", result)
    console.log("Number of points: ", result[0].points[0][1]);
  })

});

console.log('so long folks');

本文标签: javascriptInfluxDB node module not inserting dataStack Overflow