Skip to content

Latest commit

 

History

History
96 lines (82 loc) · 2.45 KB

api.md

File metadata and controls

96 lines (82 loc) · 2.45 KB

influxdb-nodejs

Build Status Coverage Status npm Github Releases

A simple client for influxdb, including these features:

  • Writing multiple points

  • Querying from multi influxdb servers and writing with influxdb-relay

  • Schema for fields and tags

Installation

$ npm install influxdb-nodejs

Examples

Writing multiple points and set schema for measurment

const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
const fieldSchema = {
  use: 'integer',
  bytes: 'integer',
  url: 'string',
};
const tagSchema = {
  spdy: ['speedy', 'fast', 'slow'],
  method: '*',
  // http stats code: 10x, 20x, 30x, 40x, 50x
  type: ['1', '2', '3', '4', '5'],
};
client.schema('http', fieldSchema, tagSchema, {
  // default is false
  stripUnknown: true,
});
client.write('http')
  .tag({
    spdy: 'fast',
    method: 'GET',
    type: '2',
  })
  .field({
    use: 300,
    bytes: 2312,
    url: 'https://github.com/vicanso/influxdb-nodejs',
  })
  .queue();

client.write('http')
  .tag({
    spdy: 'slow',
    method: 'GET',
    type: '2',
  })
  .field({
    use: 3000,
    bytes: 2312,
    url: 'https://github.com/vicanso/influxdb-nodejs',
  })
  .queue();

client.synceWrite()
  .then(() => console.info('sync write queue success'))
  .catch(err => console.error(`sync write queue fail, err:${err.message}`));

Using influxdb-relay for high availability (2 influxdb server and 2 influxdb-relay)

const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:9086,127.0.0.1:9097/mydb', {
  loadBalancingAlgorithm: 'round-robin',
});
client.startHealthCheck();
client.write('http')
  .tag({
    spdy: 'fast',
    method: 'GET',
    type: '2',
  })
  .field({
    use: 300,
    bytes: 2312,
    url: 'https://github.com/vicanso/influxdb-nodejs',
  })
  .then(() => console.info('write point to influxdb-relay success'))
  .catch(err => console.error(`write point to influxdb-relay fail, err:${err.message}`));