Skip to content
This repository was archived by the owner on Oct 27, 2018. It is now read-only.
Closed
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: 2 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ influxdb:
retentionPolicy: 'default'
# Acceptable version are: '0.8' and '0.9'
version: '0.9'
# Only applies with version '0.9'
use_json: true


modules:
Expand Down
47 changes: 43 additions & 4 deletions lib/influxdb.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ class Client

init: ->
useUDP = @config.get('influxdb.use_udp').get() ? false
version = @config.get('influxdb.version').get() ? '0.9'
use_json = @config.get('influxdb.use_json').get() ? false

@send = if useUDP then @sendUDP() else @sendHTTP()
if useUDP
@send = @sendUDP()
else if version == '0.9' and use_json == false
@send = @sendLineHTTP()
else
@send = @sendHTTP()

write: (metrics) ->
@send @metricsJson metrics
@send metrics

sendHTTP: ->
version = @config.get('influxdb.version').get() ? '0.9'
use_json = @config.get('influxdb.use_json').get() ? false
host = @config.get('influxdb.host').get() ? 'localhost'
port = @config.get('influxdb.port').get() ? 8086
database = @config.get('influxdb.database').get() ? 'bucky'
Expand All @@ -32,8 +40,28 @@ class Client
u: username
p: password

(metricsJson) ->
client form: metricsJson, (error, response, body) ->
(metrics) ->
client form: @metricsJson metrics, (error, response, body) ->
logger.log error if error

sendLineHTTP: ->
host = @config.get('influxdb.host').get() ? 'localhost'
port = @config.get('influxdb.port').get() ? 8086
database = @config.get('influxdb.database').get() ? 'bucky'
username = @config.get('influxdb.username').get() ? 'root'
password = @config.get('influxdb.password').get() ? 'root'
logger = @logger
endpoint = 'http://' + host + ':' + port + '/write'
client = request.defaults
method: 'POST'
url: endpoint
qs:
u: username
p: password
db: database

(metrics) ->
client body: @metricsLine metrics, (error, response, body) ->
logger.log error if error

sendUDP: ->
Expand Down Expand Up @@ -74,6 +102,17 @@ class Client
# @logger.log(JSON.stringify(data, null, 2))
JSON.stringify data

metricsLine: (metrics) ->
data = []
for key, desc of metrics
row = @parseRow desc
continue unless row
[val, unit, sample] = row

data.push key + ' ' + 'value=' + [[parseFloat val]]

return data.join('\n')

parseRow: (row) ->
re = /([0-9\.]+)\|([a-z]+)(?:@([0-9\.]+))?/

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bucky-server",
"version": "0.5.0",
"version": "0.5.1",
"description": "Server to collect stats from the client",
"main": "./start.js",
"bin": "./start.js",
Expand Down