All Projects → vicanso → influxdb-nodejs

vicanso / influxdb-nodejs

Licence: MIT license
Simple influxdb client

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to influxdb-nodejs

Ohmgraphite
Export Open Hardware sensor data to Graphite / InfluxDB / Prometheus / Postgres / Timescaledb
Stars: ✭ 155 (+84.52%)
Mutual labels:  influxdb
Influxdb Client For Arduino
Simple library for sending measurements to an InfluxDB with a single network request. Supports ESP8266 and ESP32.
Stars: ✭ 176 (+109.52%)
Mutual labels:  influxdb
Go Runtime Metrics
Collect golang runtime metrics, pushing to InfluxDB or pulling with Telegraf
Stars: ✭ 245 (+191.67%)
Mutual labels:  influxdb
Influxdb exporter
A server that accepts InfluxDB metrics via the HTTP API and exports them via HTTP for Prometheus consumption
Stars: ✭ 159 (+89.29%)
Mutual labels:  influxdb
Frostmourne
frostmourne是基于Elasticsearch, InfluxDB数据,Mysql数据的监控,报警,分析系统. Monitor & alert & alarm & analyze for Elasticsearch && InfluxDB Log Data。主要使用springboot2 + vue-element-admin。 https://frostmourne-demo.github.io/
Stars: ✭ 166 (+97.62%)
Mutual labels:  influxdb
Pi Hole Monitoring
Monitoring Pi-Hole statistics with Grafana
Stars: ✭ 196 (+133.33%)
Mutual labels:  influxdb
Influxdata.net
InfluxData TICK stack .net library.
Stars: ✭ 142 (+69.05%)
Mutual labels:  influxdb
ioBroker.influxdb
Store history data in InfluxDB (not for Windows)
Stars: ✭ 33 (-60.71%)
Mutual labels:  influxdb
Influxdb Client Python
InfluxDB 2.0 python client
Stars: ✭ 165 (+96.43%)
Mutual labels:  influxdb
Snmpcollector
A full featured Generic SNMP data collector with Web Administration Interface for InfluxDB
Stars: ✭ 216 (+157.14%)
Mutual labels:  influxdb
Logcool
A high performance and near real time log collector.
Stars: ✭ 161 (+91.67%)
Mutual labels:  influxdb
Hargo
Hargo is a Go library and command line utility that parses HAR files, can convert to curl format, and serve as a load test driver.
Stars: ✭ 164 (+95.24%)
Mutual labels:  influxdb
Kafka Influxdb
High performance Kafka consumer for InfluxDB. Supports collectd message formats.
Stars: ✭ 206 (+145.24%)
Mutual labels:  influxdb
Influxdb.net
Cross-platform .NET library for InfluxDB distributed time-series database.
Stars: ✭ 159 (+89.29%)
Mutual labels:  influxdb
Icinga Vagrant
Vagrant boxes for Icinga 2, Icinga Web 2, modules, themes and integrations (Graphite, InfluxDB, Elastic, Graylog, etc.)
Stars: ✭ 248 (+195.24%)
Mutual labels:  influxdb
Appmetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
Stars: ✭ 1,986 (+2264.29%)
Mutual labels:  influxdb
Icingaweb2 Module Grafana
Grafana module for Icinga Web 2 (supports InfluxDB & Graphite)
Stars: ✭ 190 (+126.19%)
Mutual labels:  influxdb
ups-telegraf
Get data from USB-connected UPS with Telegraf
Stars: ✭ 21 (-75%)
Mutual labels:  influxdb
Netdata
Real-time performance monitoring, done right! https://www.netdata.cloud
Stars: ✭ 57,056 (+67823.81%)
Mutual labels:  influxdb
Pfsense Dashboard
A functional and useful dashboard for pfSense that utilizes influxdb, grafana and telegraf
Stars: ✭ 208 (+147.62%)
Mutual labels:  influxdb

influxdb-nodejs

Build Status Coverage Status npm Github Releases

An InfluxDB Node.js Client.

Installation

$ npm install influxdb-nodejs

Examples

View the ./examples directory for working examples.

API

API

New Client

// no auth
const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
// normal auth (user and password will be added to URL query parameters)
const Influx = require('influxdb-nodejs');
const client = new Influx('http://user:[email protected]:8086/mydb');
// basic auth (will be used http basic auth)
const Influx = require('influxdb-nodejs');
const client = new Influx('http://user:[email protected]:8086/mydb?auth=basic');

Write point

const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
// i --> integer
// s --> string
// f --> float
// b --> boolean
const fieldSchema = {
  use: 'i',
  bytes: 'i',
  url: 's',
};
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',
  })
  .then(() => console.info('write point success'))
  .catch(console.error);

Query influxdb with multi where condition

const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
client.query('http')
  .where('spdy', '1')
  .where('method', ['GET', 'POST'])
  .where('use', 300, '>=')
  .then(console.info)
  .catch(console.error);
// => influx ql: select * from "http" where "spdy" = '1' and "use" >= 300 and ("method" = 'GET' or "method" = 'POST')

Query influxdb using functon

const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
client.query('http')
  .where('spdy', '1')
  .addFunction('count', 'url')
  .then(console.info)
  .catch(console.error);
// => select count("url") from "http" where "spdy" = '1'

client.query('http')
  .where('spdy', '1')
  .addFunction('bottom', 'use', 5)
  .then(console.info)
  .catch(console.error);
// select bottom("use",5) from "http" where "spdy" = '1'

Write points to influxdb in queue

const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
function loginStatus(account, ip, type) {
  client.write('login')
    .tag({
      type,  
    })
    .field({
      account,
      ip,  
    })
    .queue();
  if (client.writeQueueLength >= 10) {
    client.syncWrite()
      .then(() => console.info('sync write queue success'))
      .catch(err => console.error(`sync write queue fail, ${err.message}`));
  }
}

setInterval(() => {
  loginStatus('vicanso', '127.0.0.1', 'vip');
}, 5000);

Sub query

const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
client.query('http')
  .addFunction('max', 'use')
  .addGroup('type')
  .subQuery()
  .addFunction('sum', 'max')
  .then((data) => {
    // { name: 'http', columns: [ 'time', 'sum' ], values: [ [ '1970-01-01T00:00:00Z', 904 ] ] }
    console.info(data.results[0].series[0]);
  }).catch(console.error);

Multi query

const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
const reader = client.query('request');
reader.set({
  limit: 2,
});
reader.multiQuery();
reader.measurement = 'login';
reader.set({
  limit: 1,
  tz: 'America/Chicago',
});
reader.set({
  format: 'json',
});
reader.then(data => {
  console.info(JSON.stringify(data));
}).catch(console.error);

Use influxdb for express

const express = require('express');
const app = express();
const _ = require('lodash');
const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
const onHeaders = require('on-headers');

// set the http stats schema
client.schema('http', {
  use: 'integer',
  code: 'integer',
  bytes: 'integer',
  url: 'string',
});
client.on('writeQueue', () => {
  // sync write queue if the length is 100
  if (client.writeQueueLength === 100) {
    client.syncWrite()
      .then(() => {
        console.info('sync write success');
      })
      .catch(console.error);
  }
});

function httpStats(req, res, next) {
  const start = Date.now();
  onHeaders(res, () => {
    const code = res.statusCode;
    const use = Date.now() - start;
    const method = req.method;
    const bytes = parseInt(res.get('Content-Length') || 0, 10);
    const tags = {
      spdy: _.sortedIndex([100, 300, 1000, 3000], use),
      type: code / 100 | 0,
      method,
    };
    const fields = {
      use,
      code,
      bytes,
      url: req.url,
      route: req.route.path
    };
    // use queue for better performance
    client.write('http')
      .tag(tags)
      .field(fields)
      .queue();
  });
  next();
}

client.createDatabase().catch(err => {
  console.error('create database fail err:', err);
});

app.use(httpStats);

app.use((req, res, next) => {
  setTimeout(next, _.random(0, 5000));
});

app.get('/users/me', (req, res) => {
  res.json({
    account: 'vicanso',
    name: 'Tree Xie',
  });
});

app.get('/book/:id', (req, res) => {
  const {
    id,
  } = req.params;
  res.json({
    id: id,
    name: 'my book',
    author: 'vicanso',
  });
});

app.get('/order/:id', (req, res) => {
  res.status(400).json({
    error: 'The id is not valid',
  });
});

app.get('/author/:id', (req, res) => {
  res.status(500).json({
    error: 'The database is disconnected',
  });
});

let server;
const finish = () => {
  console.info(`listen on http://127.0.0.1:${server.address().port}/`);
};
if (process.env.PORT) {
  server = app.listen(process.env.PORT, finish);
} else {
  server = app.listen(finish);
}

Influxdb Charts

HTTP Spdy(experss demo)

HTTP Type(experss demo)

HTTP Error(experss demo)

Comparison

  • influx It's complex for me. Before developing this module, I used influx, which was not straightforward; and its batch function can not be saved as queue. What's more, the function of query is too simple, just like I write influx ql.

  • influent I have never used this module, but I have read its API. In my opinion, this module is not so convenient.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].