-
Notifications
You must be signed in to change notification settings - Fork 9
/
converter.js
38 lines (32 loc) · 1.02 KB
/
converter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
var util = require('./util')
, inherits = require('util').inherits
, Transform = require('stream').Transform;
/**
* Stream that takes a JSON Object input and outputs it as line protocol
* that is compatible with InfluxDB
* @param {Object} opts
*/
function JsonInfluxLineStream (opts) {
Transform.call(this, opts);
// The stream expects input to be an object, and will also output objects
this._writableState.objectMode = true;
this._readableState.objectMode = true;
this.opts = opts;
}
inherits(JsonInfluxLineStream, Transform);
module.exports = JsonInfluxLineStream;
/**
* Transforms an input JSON Object to the line protocol format
* @param {Object} data
* @param {String} encoding
* @param {Function} done
*/
JsonInfluxLineStream.prototype._transform = function (data, encoding, done) {
done(null, util.generateLineProtocolString({
measurement: data.measurement,
tags: util.generateTagString(data.tags),
fields: util.generateFieldString(data.fields),
ts: data.ts
}));
};