[英]InfluxDB node module not inserting data
我剛剛開始試驗 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');
在運行結束時,我看到沒有輸入數據。 這個包有經驗嗎?
我是 InfluxDB 的維護者之一。 我們不使用節點,所以我不熟悉該庫,但我嘗試了您的代碼段,確實不起作用。 事實證明, influxdb
庫不是最新的,最后一次更新是在四個月前,在此期間 InfluxDB api 經歷了重大變化。 我建議你改用influx 包,它似乎得到了更積極的維護。 我修改了您的代碼片段以與其他包一起使用,並且成功運行:
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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.