How to use influx - 10 common examples

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

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

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 CommonGarden / Grow-IoT / imports / api / influx / influx.js View on Github external
}

console.log('Influx URL: ' + INFLUX_URL);

if (INFLUX_URL) {
  // See: https://www.npmjs.com/package/influx
  // See: https://docs.influxdata.com/influxdb/v1.2/concepts/schema_and_data_layout/
  const influx = new Influx.InfluxDB({
    host: INFLUX_URL,
    database: 'events',
    schema: [
      {
        measurement: 'events',
        fields: {
          value: Influx.FieldType.FLOAT,
          message: Influx.FieldType.STRING,
        },
        tags: [
          'thing', 'environment', 'type'
        ]
      }
    ]
  });

  influx.getDatabaseNames()
    .then(names => {
      if (!names.includes('events')) {
        return influx.createDatabase('events');
      }
    })
    .catch(err => {
      console.error(err);
github stefanwalther / speedy / docker / speedy / src / index.js View on Github external
SPEEDY_DB_NAME: process.env.INFLUXDB_DB,
  SPEEDY_DB_PORT: process.env.INFLUXDB_HTTP_BIND_ADDRESS || 8086,
  SPEEDY_INTERVAL: process.env.SPEEDY_INTERVAL || '* * * * *',
  SPEEDY_MAX_TIME: process.env.SPEEDY_MAX_TIME || 5000
};

const influx = new Influx.InfluxDB({
  host: settings.SPEEDY_DB_HOST,
  database: settings.SPEEDY_DB_NAME,
  schema: [
    {
      measurement: 'speed_test',
      fields: {
        download: Influx.FieldType.INTEGER,
        upload: Influx.FieldType.INTEGER,
        originalUpload: Influx.FieldType.INTEGER,
        originalDownload: Influx.FieldType.INTEGER,
        executionTime: Influx.FieldType.FLOAT
      },
      tags: [
        'interval',
        'isp',
        'host'
      ]
    }
  ]
});

console.log('speedy settings:', settings);

// run it every minute
schedule.scheduleJob(settings.SPEEDY_INTERVAL, () => {
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'
		});

influx

InfluxDB Client

MIT
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis

Popular influx functions