Domanda

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?

È stato utile?

Soluzione

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 recommend 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');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top