Node JS class for publishing metrics as time series data (TSD). (2c)

NodeJS Client for TSD Aggregator

npm tsd-metrics-client

tsd = require('tsd-metrics-client')
var m = new tsd.TsdMetrics();
m.incrementCounter("c1", 3);
m.decrementCounter("c1", 1);
m.setGauge("g1", 12);

There are limited set of configs related to the query log file. They are managed through the following global variables:

 * Sets a flag to output the metrics to console in addition to the query file (mainly for testing)
 * Default: false
 * @type {boolean}
tsd.TsdMetrics.LOG_CONSOLE_ECHO = <true/false>;
 * The name of the query log file 
 * Default: "tsd-query.log"
 * @type {string}
tsd.TsdMetrics.LOG_FILE_NAME = <log_file_name>;
 * Sets the maximum number of log files backup to retain.
 * Default: 10
 * @type {number}
tsd.TsdMetrics.LOG_BACKUPS = <number>;
 * Sets the maximums size of log in bytes before rolling a new file
 * Default: 32 MB
 * @type {number}
tsd.TsdMetrics.LOG_MAX_SIZE = <number_in_bytes>;

The TsdMetrics class extends EventEmitter, and current emit the following two events

  • "error": Emitted when error case occurs. Parameter passed is an Error object with the details.
  • "logEvent": Emitted right after writing the metrics event details to disk. The parameter passed is an object with details that were serialized to disk.

To build tsd-metrics-client.ts:

1 - Install Typesript compiler

npm install -g typescript

2 - Modify tsd-metrics-client.ts

3 - Compile tsd-metrics-client.ts using ./compile script. The compiled JS will be dropped in /lib

4 - To run tests, execute npm install (only first time) then npm test