monitor-dog
Wraps dogstatsd to provide environment based event scoping (prefixing) and timers.
Usage
// Assume `process.env.MONITOR_PREFIX === 'myProject'`, then all events// triggered via monitor dog will be prefixed with `myProject.`.var monitor = ; // Trigger an increment (`myProject.requests`)monitor; // Trigger an increment with additional parametersmonitor; // Trigger an increment with tags as objectmonitor; // Trigger a gauge event (`myProject.404s`)monitor; // Time requests...var timer = monitor;;
Interval Monitoring
Creating specialized periodic interval monitors (similar to the sockets monitor) is fairly straight-forward. Here's an example of how it is done:
var monitor = ;var IntervalMonitor = ;var util = ; /** * 1. Subclass the IntervalMonitor class */ { IntervalMonitor;}util; /** * 2. Define your run function to periodically monitor what you wish */MyCustomMonitorprototype { // ... Perform custom periodic reporting here using this.monitor} // 3. Instantiate and start your new interval monitor!monitorstart;
API Documentation
.set, .increment, .decrement, .histogram, .gauge
These methods behave exactly as you would expect on a regular dogstatsd Client.
.timer(name, [startNow])
Creates and returns new timer with the given name
. Optional boolean
startNow
can be provided to start the timer at a later date using the
.start
method.
Synchronous
// Create the timervar sumTimer = monitor; // Perform a computationvar sum = 0;for var i = 0; i < 1000000; i sum = i; // Call .stop() to send a histogram event named 'sum.time'// with the recorded duration...sumTimer;
Asynchronous
var requestTimer = monitor;;
Delayed Use
var delayedTime = monitor; // ... Do some other stuff ... delayedTimerstart; // ... Do some more stuff ... delayedTimer;
.startSocketsMonitor(), .stopSocketsMonitor()
Automatically track number of open & pending sockets and open files.
// start monitoring once you start web server// default interval defined by `process.env.MONITOR_INTERVAL`monitor; // stop monitoring before stopping web servermonitor;
.captureStreamEvents()
Capture stream events: open
, data
, error
, end
.
monitor;
License
MIT