Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/evanshortiss/node-json-to-influx-line
Converts JSON input to InfluxDB line protocol format
https://github.com/evanshortiss/node-json-to-influx-line
Last synced: 4 days ago
JSON representation
Converts JSON input to InfluxDB line protocol format
- Host: GitHub
- URL: https://github.com/evanshortiss/node-json-to-influx-line
- Owner: evanshortiss
- Created: 2016-04-21T12:54:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-30T19:00:16.000Z (about 7 years ago)
- Last Synced: 2024-10-28T13:46:17.718Z (16 days ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 8
- Watchers: 3
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JSON to InfluxDB Line Protocol
Module that will convert a JSON Object to the line protocol format for
InfluxDB. Will perform any necessary escaping on strings as specified by the
protocol. You can read about the InfluxDB line protocol [here](https://docs.influxdata.com/influxdb/v0.12/write_protocols/write_syntax/#line-protocol).This module does not perform any I/O to InfluxDB. It is just a converter.
This is the initial version and has not been thoroughly tested in real world
scenarios, nor performance tested. A suite of unit tests are passing however.# Install
```
npm i json-influxdb-line
```# Usage
Any Object you want to convert to a line must be of the format:
```js
{
measurement: 'name-of-measure',
// Fields cannot contain sub-objects unless they are stringified
fields: {
c: '2',
d: 3
},
// Options. Tags cannot contain sub-objects unless they are stringified
tags: {
a: '1',
b: 2
},
// Optional. Any precision can be used (see InfluxDB API)
ts: Date.now()
}
```## Streaming
```js
var JsonInfluxDbStream = require('json-influxdb-line').JsonInfluxDbStream;var jsonToLine = new JsonInfluxDBLineStream();
// Get JSON (stringified objects), convert to line format, write to influxdb
getJsonStream()
.pipe(jsonToLine)
.pipe(influxApiStream);
```## Functional
```js
var convert = require('json-influxdb-line').convert;// This will create a String with the contents:
// measurement-name,foo=bar value=15 1461108623664
var line = convert({
// A measurement name
measurement: 'measurement-name',// Optional tags. Nested objects are not supported
tags: {
foo: 'bar'
},// Fields. Nested objects are not supported
fields: {
value: 15
},// Timestamp - can be omitted
ts: Date.now()
});
```# Contributions
All are welcome, just open a Pull Request and add tests where necessary.