npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

monitor-dog

v2.0.0

Published

A helpful wrapper for dogstatsd.

Downloads

76

Readme

monitor-dog

Build Status Dependency Status devDependency Status

NPM

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 = require('monitor-dog');

// Trigger an increment (`myProject.requests`)
monitor.increment('requests');

// Trigger an increment with additional parameters
monitor.increment('requests', 1, ['env:prod', 'host': '127.0.0.1']);

// Trigger an increment with tags as object
monitor.increment('requests', 1, {env: 'prod', host: '127.0.0.1'});

// Trigger a gauge event (`myProject.404s`)
monitor.gauge('404s');

// Time requests...
var timer = monitor.timer('request.time');
request('http://example.com', function(req, res) {
  // Triggers a histogram event to `myProject.request.time`
  timer.stop();
});

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 = require('monitor-dog');
var IntervalMonitor = require('monitor-dog/lib/interval-monitor');
var util = require('util');

/**
 * 1. Subclass the IntervalMonitor class
 */
function MyCustomMonitor = function(monitor, prefix, interval) {
  IntervalMonitor.call(this, monitor, prefix, interval);
}
util.inherits(MyCustomMonitor, IntervalMonitor);

/**
 * 2. Define your run function to periodically monitor what you wish
 */
MyCustomMonitor.prototype.run = function() {
  // ... Perform custom periodic reporting here using this.monitor
}

// 3. Instantiate and start your new interval monitor!
(new MyCustomMonitor(monitor)).start();

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 timer
var sumTimer = monitor.timer('sum.time');

// Perform a computation
var 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.stop();
Asynchronous
var requestTimer = monitor.timer('request.time');
request('/some/endpoint', function (err, res) {
  requestTimer.stop();
});
Delayed Use
var delayedTime = monitor.timer('delayed.timer', false);

// ... Do some other stuff ...

delayedTimer.start();

// ... Do some more stuff ...

delayedTimer.stop();

.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.startSocketsMonitor();

// stop monitoring before stopping web server
monitor.stopSocketsMonitor();

.captureStreamEvents()

Capture stream events: open, data, error, end.

monitor.captureStreamEvents('some-name', yourStream);

License

MIT