Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 36 additions & 9 deletions lib/influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,21 @@ function millisecondsSince(start) {
return diff[0] * 1000 + diff[1] / 1000000;
}

// data passed in from statsd
// deploys.display.newstuff,product=Marvellous\ Marbles,product_id=1:2|g
// determines the "real" key, appends type of metric to real key
// returns reassembled data
function influxKey(key, type) {
// find the actual key
var k = key.substr(0, key.indexOf(','));
if (!k) {
return key;
}
var rest = key.replace(k, '');

return k + '.' + type + rest;
}

InfluxdbBackend.prototype.log = function (msg) {
util.log('[influxdb] ' + msg);
}
Expand Down Expand Up @@ -187,7 +202,7 @@ InfluxdbBackend.prototype.processFlush = function (timestamp, metrics) {
if (!self.includeStatsdMetrics && key.match(statsPrefixRegexp)) { continue; }

var value = counters[key],
k = key + '.counter';
k = influxKey(key, 'counter');

if (value) {
points.push(self.assembleEvent(k, [{value: value, time: timestamp}]));
Expand All @@ -206,7 +221,7 @@ InfluxdbBackend.prototype.processFlush = function (timestamp, metrics) {
if (!self.includeStatsdMetrics && key.match(statsPrefixRegexp)) { continue; }

var value = gauges[key],
k = key + '.gauge';
k = influxKey(key, 'gauge');

if (!isNaN(parseFloat(value)) && isFinite(value)) {
points.push(self.assembleEvent(k, [{value: value, time: timestamp}]));
Expand All @@ -223,7 +238,7 @@ InfluxdbBackend.prototype.processFlush = function (timestamp, metrics) {

for (histoKey in histoMetrics) {
var value = histoMetrics[histoKey],
k = key + '.timer.histogram.' + histoKey;
k = influxKey(key, 'timer.histogram.' + histoKey);

points.push(self.assembleEvent(k, [{value: value, time: timestamp}]));
}
Expand All @@ -235,7 +250,7 @@ InfluxdbBackend.prototype.processFlush = function (timestamp, metrics) {
// Iterate over normal metrics:
for (timerKey in timerMetrics) {
var value = timerMetrics[timerKey],
k = key + '.timer' + '.' + timerKey;
k = influxKey(key, 'timer' + '.' + timerKey);

points.push(self.assembleEvent(k, [{value: value, time: timestamp}]));
}
Expand Down Expand Up @@ -462,7 +477,7 @@ InfluxdbBackend.prototype.httpPOST_v09 = function (points) {
if (!points.length) { return; }

var self = this,
query = {u: self.user, p: self.pass},
query = {u: self.user, p: self.pass, db: self.database},
protocolName = self.protocol == http ? 'HTTP' : 'HTTPS',
startTime;

Expand Down Expand Up @@ -500,10 +515,18 @@ InfluxdbBackend.prototype.httpPOST_v09 = function (points) {
self.log(e);
});

var payload = JSON.stringify({
database: self.database,
points: points
});
var points_to_payload = function(points) {
// {"database":"statsd","points":[{"measurement":"my.test.cnt,host=server1,name=abc.gauge","fields":{"value":56}}]}
lines = '';
for (p in points) {
p = points[p];
var l = p['measurement'] + ' value=' + p['fields']['value'];
lines += l + "\n";
}
return lines;
};

var payload = points_to_payload(points);

self.influxdbStats.payloadSize = Buffer.byteLength(payload);

Expand All @@ -512,6 +535,10 @@ InfluxdbBackend.prototype.httpPOST_v09 = function (points) {
return 'Payload size ' + size + ' KB';
});

self.logDebug(function () {
return "Payload: \n" + payload;
});

req.write(payload);
req.end();
}
Expand Down