Collect Stats into InfluxDB
Last updated 5 years ago by defunctzombie .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install influx-collector 
SYNC missed versions from official npm registry.

influx-collector Build Status

InfluxDB stats collector for node.js

For InfluxDB 0.9.x use version 1.x.x of this module.

For InfluxDB <= 0.8.x use version 0.x.x of this module.

Note that the API changed between 0.x and 1.x to move the series name into the constructor.


// set some env var (i.e INFLUX_STATS_URI)

var Stats = require('influx-collector');

// create a stats collector
var mem_stats = Stats('process-memory-usage', process.env.INFLUX_STATS_URI);

// example stat collection of process memory usage
setInterval(function() {
    var mem = process.memoryUsage();

    // collect this stat into the 'process-memory-usage' series
    // first argument is the data points
    // second (optional) argument are the tags
        rss: mem.rss,
        heap_total: mem.heapTotal,
        heap_used: mem.heapUsed
    }, {
        app: 'my-app'
}, 10 * 1000);

// make sure to handle errors to avoid uncaughtException
// would be annoying if stats crashed your app :)
mem_stats.on('error', function(err) {
    console.error(err); // or whatever you want


influx-collector is configured via the URI string. The following options can be set by specifying them as query parameters in the URI

Param Default Description
autoFlush yes Specify no to avoid stats flushing automatically. See flushing below.
flushInterval 5000 Stats are flushed every flushInterval milliseconds.
instantFlush no Flush stats to server on collection.
time_precision Time precision when writing data. Only relevant if you are specifying the time field.

Flushing and Batches

By default, stats are flushed in batches every flushInterval milliseconds. This allows for many stats to be collected and flushed at once. You can override these behaviors via the autoFlush and interval options as query parameters. You can also turn on instantFlush which will send the stats to InfluxDB as soon as they are collected (every collect call will be an http request). I do not recommend this approach for high frequency stats.

Example of a 10 second flush interval


To manually flush the stats at any time (or if autoFlush is off), use the .flush method on your stats instance.


  • Make sure to attach and error handler so stats don't crash your entire app.
  • Useful to log pid and app names/tags for generic stats so you can group by later.
  • Grafana is amazing.

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

6 Versions

  • 1.0.0                                ...           5 years ago
  • 0.3.1                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (0)

Copyright 2014 - 2016 © |