Class: Timer

Timer

Timers are a combination of Meters and Histograms. They measure the rate as well as distribution of scalar events.


Since they are frequently used for tracking how long certain things take, they expose an API for that: See example 1.


But you can also use them as generic histograms that also track the rate of events: See example 2.


new Timer( [properties])

Parameters:
Name Type Argument Description
properties TimerProperties <optional>

See TimerProperties.

Implements:
Source:
Examples
var Measured = require('measured')
var timer = new Measured.Timer();
http.createServer(function(req, res) {
    var stopwatch = timer.start();
    req.on('end', function() {
        stopwatch.end();
    });
});
var Measured = require('measured')
var timer = new Measured.Timer();
http.createServer(function(req, res) {
   if (req.headers['content-length']) {
       timer.update(parseInt(req.headers['content-length'], 10));
   }
});

Methods


getType()

The type of the Metric Impl. MetricTypes.

Implements:
Source:
Returns:

The type of the Metric Impl.

Type
string

ref()

Refs the backing timer again. Idempotent.

Source:

reset()

Resets all values. Timers initialized with custom options will be reset to the default settings.

Source:

start()

Source:
Returns:

Returns a Stopwatch that has been started.

Type
Stopwatch

toJSON()

toJSON output:

  • meter: See Meter#toJSON output docs above.

  • histogram: See Histogram#toJSON output docs above.
  • Implements:
    Source:
    Returns:
    Type
    any

    unref()

    Unrefs the backing timer. The meter will not keep the event loop alive. Idempotent.

    Source:

    update(value)

    Updates the internal histogram with value and marks one event on the internal meter.

    Parameters:
    Name Type Description
    value number
    Source: