【问题标题】:InfluxDB node module not inserting dataInfluxDB 节点模块未插入数据
【发布时间】:2014-05-15 22:52:23
【问题描述】:

我刚开始尝试使用 influxDB 和 influxDB 节点模块。

我有以下代码,每秒插入一些随机数据。 我没有收到任何错误,但我的时间序列中没有添加任何数据。

代码是:

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

在运行结束时,我没有看到任何数据输入。 有使用过这个包的经验吗?

【问题讨论】:

标签: javascript node.js database influxdb


【解决方案1】:

我是 InfluxDB 的维护者之一。我们不使用节点,所以我不熟悉该库,但我尝试了您的 sn-p,确实它不起作用。事实证明,influxdb 库不是最新的,最后一次更新是在四个月前,在此期间 InfluxDB api 经历了重大变化。我建议您改用the influx package,它似乎得到了更积极的维护。我修改了您的代码 sn-p 以与其他软件包一起使用,并且成功运行:

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

【讨论】:

  • 非常感谢。这确实有效,我将切换到这个包。
  • 我用过这段代码。但是无法连接influxdb?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-27
  • 2021-05-23
  • 2021-08-15
  • 2017-11-09
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多