How to use the influx.InfluxDB function in influx

To help you get started, we’ve selected a few influx examples, based on popular ways it is used in public projects.

github autopilotpattern / nodejs-example / serializer / lib / index.js View on Github external
function setupDb () {
  const influxServer = Piloted.service('influxdb');
  if (!influxServer && internals.failCount > 10) {
    internals.failCount = 0;
    Piloted.refresh();
  }

  if (!influxServer) {
    internals.failCount++;
    internals.db = bufferedDb;
    return setTimeout(setupDb, 1000);
  }

  internals.db = new Influx.InfluxDB({
    host: influxServer.address,
    port: influxServer.port,
    username: process.env.INFLUXDB_USER,
    password: process.env.INFLUXDB_PWD
  });

  internals.db.createDatabase(internals.dbName)
  .then(() => {
    bufferedDb.drain();
  })
  .catch((err) => {
    console.error(`Error creating Influx database!`);
    console.error(err);

    // Influx may not be entirely ready
    setTimeout(setupDb, 1000);
github FeliceGeracitano / webperf-dashboard / packages / lighthouse / src / influxdb.ts View on Github external
import * as influx from 'influx';
import { IDB, IDBPayload } from './types';
import Logger from './logger';
const console = new Logger('[DB Connector]: ');

// DB instance
const DBNAME = 'lighthouse';
const DB = new influx.InfluxDB({
  host: process.env.HOST || 'localhost',
  database: DBNAME
});

export default {
  init: async () => {
    try {
      const names = await DB.getDatabaseNames();
      if (names.indexOf(DBNAME) === -1) {
        console.log('Database does not exist. Creating database');
        return DB.createDatabase(DBNAME);
      }
      console.log('Database exist. Connection ready');
      return Promise.resolve();
    } catch (err) {
      return Promise.reject('Database: Failed to initialise Connection');
github inventid / iaas / src / metrics / influx.js View on Github external
function setup() {
  const influxConnection = config.get("metrics.influx.dsn");
  const influx = new InfluxDB(influxConnection);
  log('debug', `Connecting influx to ${influxConnection}`);

  let queue = [];
  let lastWrite = new Date();
  let lastPrintedError;

  function drainQueue() {
    const queueToSend = queue;
    queue = [];
    lastWrite = new Date();
    if (queueToSend.length > 0) {
      log('info', `Draining queue for influx. Writing ${queueToSend.length} points.`);
      influx.writePoints(queueToSend).catch(err => {
        // limit an error to once every 30 seconds
        if (!lastPrintedError || (new Date() - lastPrintedError) > 30) {
          log('error', `Error saving data to InfluxDB! ${err.stack}`);
github numbat-metrics / numbat-collector / lib / output-influx.js View on Github external
var InfluxOutput = module.exports = function InfluxOutput(opts)
{
	assert(opts && _.isObject(opts), 'you must pass an options object');
	assert(opts.hosts && _.isArray(opts.hosts), 'you must pass an array in the `hosts` option');
	assert(opts.username && _.isString(opts.username), 'you must pass a `username` option');
	assert(opts.password && _.isString(opts.password), 'you must pass a `password` option');
	assert(opts.database && _.isString(opts.database), 'you must pass a `database` option');

	stream.Writable.call(this, { objectMode: true });
	if (!opts.requestTimeout) opts.requestTimeout = 65000; // in ms
	if (!opts.batchTimeout) opts.batchTimeout = 30000; // in ms

	this.options = opts;
	this.client = new Influx.InfluxDB(opts);

	this.batch = {};
	this.batchLength = 0;
	// Default to 1 to be backwards-compatible.
	this.batchSize = opts.batchSize || 1;

	this.batchTimeout = opts.batchTimeout;
	this.nextBatchTime = Date.now() + opts.batchTimeout;
	this.resetTimer();

	this.log = bole('influx-9');
	this.log.info('influx output configured for ' + opts.database);
};
util.inherits(InfluxOutput, stream.Writable);
github tkeffer / weert-js / server / server.js View on Github external
*/
const config = require("./config/config");
const MeasurementManager = require("./services/measurement_manager");
const auth_router_factory = require("./routes/auth_routes");
const packet_router_factory = require("./routes/packet_routes");
const stats_router_factory = require("./routes/stats_routes");
const about_router_factory = require("./routes/about_routes");
const subsampling = require("./services/subsampling");
const retention_policies = require("./config/retention_policies");
// This type of metadata should probably be in a database,
// but for now, retrieve it from a JSON file
const measurement_config = require("./meta_data/measurement_config");

// Set up the database and its managers
const Influx = require("influx");
const influx = new Influx.InfluxDB(config.influxdb);

influx
  .getDatabaseNames()
  .then(names => {
    // Check to see if the chosen database has been created
    if (!names.includes(config.influxdb.database)) {
      // The database does not exist. Create it.
      debug(`Creating database '${config.influxdb.database}'`);
      return influx.createDatabase(config.influxdb.database);
    } else {
      debug(`Database '${config.influxdb.database}' already exists.`);
      return Promise.resolve();
    }
  })
  .then(() => {
    // Having created or made sure the database exists, set up the retention policies
github petre2dor / piGarden / util / InfluxDB.js View on Github external
'use strict'

const Influx = require('influx')

module.exports = new Influx.InfluxDB({
                        host: '127.0.0.1',
                        database: 'piGarden'
                    })
github boyney123 / garie-lighthouse / src / influx / influx.js View on Github external
const Influx = require('influx');

module.exports =
	process.env.INFLUXDB_URL ?
		new Influx.InfluxDB( process.env.INFLUXDB_URL )
		: new Influx.InfluxDB({
			host: process.env.HOST || 'localhost',
			database: 'lighthouse'
		});
github openintegrationhub / openintegrationhub / services / reports-analytics / src / server / index.js View on Github external
async setupTimeseries(schemas) {
        this.influx = new Influx.InfluxDB({
            host: process.env.INFLUX_HOST,
            database: conf.influxDatabase,
            schema: [
                defaultMeasurement,
                ...schemas,
            ],
        });

        const dbs = await this.influx.getDatabaseNames();

        if (!dbs.includes(conf.influxDatabase)) {
            await this.influx.createDatabase(conf.influxDatabase);
        }
    }
github sitespeedio / sitespeed.io / lib / plugins / influxdb / sender.js View on Github external
constructor({ protocol, host, port, database, username, password }) {
    this.client = new Influx.InfluxDB({
      protocol,
      host,
      port,
      database,
      username,
      password
    });
  }

influx

InfluxDB Client

MIT
Latest version published 8 months ago

Package Health Score

77 / 100
Full package analysis

Popular influx functions

Similar packages