0.1.3 • Published 10 years ago

ft-metrics v0.1.3

Weekly downloads
1
License
BSD
Repository
-
Last release
10 years ago

#FtMetrics

FtMetrics is a node module/express middleware that allows you to simply integrate some basic metrics that comply with the Origami Metrics spec

##How to use

###Requireing the object

var ftMetrics = require('ft-metrics');

There is also a configure method that you can use to override some default settings.

var ftMetrics = require('ft-metrics');
ftMetrics.configure({
	movingAveragePeriod: 120 , //seconds to keep moving average for, default 1 minute
	maxSampleSize: 4000, //limits the number of events to keep track of during a moving average period - defaults to 10000.
});

###Gathering metrics

#####Counter

Log a value representing a count, e.g. number of running processes, items in a queue, bytes of disk space remaining, seconds since last new content, etc

ftMetrics.count(key, optionalUnits, optionalDescription)

Examples:

ftMetrics.count('something', 'visits', 'blah description');
ftMetrics.count('something');
ftMetrics.count('something');
ftMetrics.count('something_else');

#####Booleans Log a simple true/false value

ftMetrics.setFlag('some-boolean', false);
ftMetrics.setFlag('some-boolean', true);
ftMetrics.setFlag('some-other-boolean', true, 'A description of the boolean');

#####Response time stats The most common use case for gathering moving average statistics is to measure the response times of an endpoint. FtMetrics provides middleware that will automatically keep track of response times for a given route.

server.get('/v1/someRoute', ftMetrics.monitor(), someAction);

You can also group multiple routes to the same key, by specifying a key to use.

server.get('/route/to/action', ftMetrics.monitor('someAction'), someAction);
server.get('/anotherroute/to/action', ftMetrics.monitor('someAction'), someAction);

#####Manually tracking moving averages. You can also manually calculate stats around some other processes that aren't routes e.g. connecting to a backend service.

var process = ftMetrics.createProcess('blah');
process.start();
process.end();

###Displaying Metrics

You can get an object representation of all the gathered metrics with the getJSON method.

var metrics = ftMetrics.getJSON();

There is also an express method that can be used to handle the __metrics endpoint as per the Origami spec.

server.get('/__metrics', ftMetrics.endpoint);
0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago