Skip to content

Commit

Permalink
Merge pull request #3 from stephenmcd/master
Browse files Browse the repository at this point in the history
Added SSL support.
  • Loading branch information
bernd committed Sep 27, 2014
2 parents 5eff7e4 + 39f9718 commit 745a5e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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)
ssl: false, // InfluxDB is hosted over SSL. (default false)
database: 'dbname', // InfluxDB database instance. (required)
username: 'user', // InfluxDB database username. (required)
password: 'pass', // InfluxDB database password. (required)
Expand Down
18 changes: 13 additions & 5 deletions lib/influxdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* influxdb: {
* host: '127.0.0.1', // InfluxDB host. (default 127.0.0.1)
* port: 8086, // InfluxDB port. (default 8086)
* ssl: false, // InfluxDB is hosted over SSL. (default false)
* database: 'dbname', // InfluxDB database instance. (required)
* username: 'user', // InfluxDB database username. (required)
* password: 'pass', // InfluxDB database password. (required)
Expand All @@ -29,7 +30,8 @@
*/
var util = require('util'),
querystring = require('querystring'),
http = require('http');
http = require('http'),
https = require('https');

function InfluxdbBackend(startupTime, config, events) {
var self = this;
Expand All @@ -46,6 +48,7 @@ function InfluxdbBackend(startupTime, config, events) {

self.host = self.defaultHost;
self.port = self.defaultPort;
self.protocol = http;
self.flushEnable = self.defaultFlushEnable;
self.proxyEnable = self.defaultProxyEnable;
self.proxySuffix = self.defaultProxySuffix;
Expand All @@ -58,6 +61,10 @@ function InfluxdbBackend(startupTime, config, events) {
self.pass = config.influxdb.password;
self.database = config.influxdb.database;

if (config.influxdb.ssl) {
self.protocol = https;
}

if (config.influxdb.flush) {
self.flushEnable = config.influxdb.flush.enable;
}
Expand Down Expand Up @@ -293,10 +300,11 @@ InfluxdbBackend.prototype.httpPOST = function (points) {
if (!points.length) { return; }

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

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

var options = {
Expand All @@ -307,13 +315,13 @@ InfluxdbBackend.prototype.httpPOST = function (points) {
agent: false // Is it okay to use "undefined" here? (keep-alive)
};

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

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

if (status !== 200) {
self.log('HTTP Error: ' + status);
self.log(protocolName + ' Error: ' + status);
}
});

Expand Down

0 comments on commit 745a5e5

Please sign in to comment.