Skip to content

add influxdb 1.0 support #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ You can configure the following settings in your StatsD config file.
influxdb: {
host: '127.0.0.1', // InfluxDB host. (default 127.0.0.1)
port: 8086, // InfluxDB port. (default 8086)
version: 0.8, // InfluxDB version. (default 0.8)
version: 0.8, // InfluxDB version. (default 0.8, can be 1.0)
ssl: false, // InfluxDB is hosted over SSL. (default false)
database: 'dbname', // InfluxDB database instance. (required)
username: 'user', // InfluxDB database username.
Expand Down
67 changes: 66 additions & 1 deletion lib/influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ function InfluxdbBackend(startupTime, config, events) {
}
}

if (self.version >= 0.9) {
if (self.version > 1) {
self.assembleEvent = self.assembleEvent_v1;
self.httpPOST = self.httpPOST_v1;
} else if (self.version >= 0.9) {
self.assembleEvent = self.assembleEvent_v09;
self.httpPOST = self.httpPOST_v09;
} else {
Expand Down Expand Up @@ -402,6 +405,13 @@ InfluxdbBackend.prototype.assembleEvent_v09 = function (name, events) {
return payload;
}

InfluxdbBackend.prototype.assembleEvent_v1 = function (name, events) {
var self = this;
var payload = name + " " + "value=" + events[0]['value']

return payload;
}

InfluxdbBackend.prototype.httpPOST_v08 = function (points) {
/* Do not send if there are no points. */
if (!points.length) { return; }
Expand Down Expand Up @@ -516,6 +526,61 @@ InfluxdbBackend.prototype.httpPOST_v09 = function (points) {
req.end();
}

InfluxdbBackend.prototype.httpPOST_v1 = function (points) {
/* Do not send if there are no points. */
if (!points.length) { return; }

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

self.logDebug(function () {
return 'Sending ' + points.length + ' different points via ' + protocolName;
});

self.influxdbStats.numStats = points.length;

var options = {
hostname: self.host,
port: self.port,
path: '/write?' + querystring.stringify(query),
method: 'POST',
agent: false // Is it okay to use "undefined" here? (keep-alive)
};

var req = self.protocol.request(options);

req.on('socket', function (res) {
startTime = process.hrtime();
});

req.on('response', function (res) {
var status = res.statusCode;

self.influxdbStats.httpResponseTime = millisecondsSince(startTime);

if (status >= 400) {
self.log(protocolName + ' Error: ' + status);
}
});

req.on('error', function (e, i) {
self.log(e);
});

var payload = points.join('\n')

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

self.logDebug(function () {
var size = (self.influxdbStats.payloadSize / 1024).toFixed(2);
return 'Payload size ' + size + ' KB';
});

req.write(payload);
req.end();
}
InfluxdbBackend.prototype.configCheck = function () {
var self = this,
success = true;
Expand Down