Modern Influxdb backend for metrics
$ npm install metrics-influx
"use strict";
var InfluxMetrics = require('metrics-influx');
var reporter = new InfluxMetrics.Reporter({ tags: { 'server': 'one' } });
var c = new InfluxMetrics.Counter();
reporter.addMetric('test.counter', c);
c.inc();
var g = new InfluxMetrics.Gauge();
reporter.addMetric('test.gauge', g);
g.set(10);
var h = new InfluxMetrics.Histogram();
reporter.addMetric('test.histogram', h);
h.update(50);
var m = new InfluxMetrics.Meter();
reporter.addMetric('test.meter', m);
m.mark(1);
var t = new InfluxMetrics.Timer();
reporter.addMetric('test.timer', t);
t.update(50);
reporter.report(true); // Send metrics to InfluxDB
To reset the values of Counters, Histograms and Timers at specific times and intervals, Reporter.resetMetric can be used. It resets the given metric periodically at a specified interval, starting at the specified time within the next 24 hours. The time must be given in UTC. If startHour < 0, the interval will be started immediately, with the metric reset once. If an error occurs during the reset, the interval is stopped.
Syntax: Reporter.resetMetric(metricToReset, intervalHour, intervalMinute, intervalSecond, startHour, startMinute, startSecond)
const c1 = new InfluxMetrics.Counter();
reporter.addMetric('measurement.name', c1);
// Reset the metric c1 every 10h 30m 5s, starting at 12.55pm
// If the current time of day > 12.55pm, will start immediately
reporter.resetMetric(c1, 10, 30, 5, 12, 55, 0);
The options
object accepts the following fields:
Parameter | Type | Default | Description |
---|---|---|---|
host | string | 127.0.0.1 |
InfluxDB host |
port | number |
8089 (udp ) / 8086 (http ) |
InfluxDB port |
username | string | null |
InfluxDB username |
password | string | null |
InfluxDB password |
database | string | null |
InfluxDB database |
consistency | string | null |
one /quorum /all /any
|
tags | object | {} |
Tags to add to influxdb measurements |
tagger | function | none |
Function invoked with the metric key and expected to return the tags for
it in the form {tag1: value1, tag2: value2, ...}
|
precision | string | n |
n /u /ms /s /m /h
|
bufferSize | number | 0 |
Number of points to keep before sending to InfluxDB |
scheduleInterval | number | null |
This is the time in ms to flush any buffered metrics |
skipIdleMetrics | boolean | false |
Suppress sending of metrics if there has been no new updates from previous report |
This module is based on the metrics library by Mike Ihbe and the node-metrics-influxdb backend by Brandon Hamilton.
MIT License
Copyright (c) 2017 Juhana S.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.