2014-10-11 32 views
1

我只是嘗試InfluxDB。我正在使用他們的文檔中的修改示例來生成一些隨機測試數據,但是當我使用節點運行時,它會顯示[Error:No host available]。我試圖通過curl和Web控制檯連接到InfluxDB,他們都工作,所以我不知道它失敗的地方。InfluxDB [錯誤:無可用主機]

我剛剛安裝了influxdb和influx npm,所以有最新版本。

var influxdb = require('influx'); 
client = new influxdb.InfluxDB('localhost',8086, 'root', 'root', 'tempdb'); 

// start time of 24 hours ago 
var backMilliseconds = 86000 * 1000; 
var startTime = new Date() - backMilliseconds; 
var timeInterval = 60 * 1000; 
var eventTypes = ["click", "view", "post", "comment"]; 

var cpuSeries = { 
    name: "cpu_idle", 
    columns: ["time", "value", "hostName"], 
    points: [] 
}; 

var eventSeries = { 
    name: "customer_events", 
    columns: ["time", "customerId", "type"], 
    points: [] 
}; 

for (i = 0; i < backMilliseconds; i += timeInterval) { 
    // generate fake cpu idle host values 
    var hostName = "server" + Math.floor(Math.random() * 100); 
    var value = Math.random() * 100; 
    var pointValues = [startTime + i, value, hostName]; 
    cpuSeries.points.push(pointValues); 

    // generate some fake customer events 
    for (j = 0; j < Math.random() * 10; j += 1) { 
    var customerId = Math.floor(Math.random() * 1000); 
    var eventTypeIndex = Math.floor(Math.random() * 1000 % 4); 
    var eventValues = [startTime + i, customerId, eventTypes[eventTypeIndex]]; 
    eventSeries.points.push(eventValues); 
    } 
} 

client.writeSeries([cpuSeries, eventSeries],{},function(err){ 
    if(err) { 
     console.log("Cannot write data",err); 
    } 
}); 

回答