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

netrix

v2.0.1

Published

Lightweight, pluggable metrics aggregator

Downloads

5

Readme

npmBuild StatusCoverage Status

netrix

Lightweight, pluggable metrics aggregator, loosely modelled on statsd.

NOTE: UDP payloads. Loses metrics under heavy load.

const netrix = require('netrix');

netrix.createServer([options])

  • options <Object> Optional.
    • port <number> Listen UPD port. Default 49494.
    • flushInterval <number> Interval at which metrics are aggregated and reported. Default 1000ms.
  • Returns <Promise> Resolve with a running instance of

class NetrixServer

const {NetrixServer} = require('netrix');

This class implements the metrics accumulator and aggregation server. It runs the UDP/datagram server to which all NetrixClient instances send their metrics. See bin/eg-server.

new NetrixServer([options])

options Same as netrix.createServer([options])

NetrixServer is an EventEmitter with the following events.

Event: 'error'

  • <Error>

Emitted when an error occurs on the datagram server.

Event: 'metric'

  • <string> Metric type 'c' or 'g' for counter or gauge.
  • <string> Metric name.
  • <number> Metric value.

Emitted for every metric arriving from netrix.Client instances.

Event: 'flush'

  • <number> Timestamp.
  • <Object> Aggregated metrics.
  • <Object> Raw metrics.

Emitted at flushInterval and contains aggregated results from all metrics accumulated since the previous flush.

The counter metrics are scaled up or down to a per-second sample even if the flushInterval is not 1000ms.

The counter metrics are reset to zero at each flush boundary so that the counting can resume appropriately.

The gauge metric values remain unchanged until the client sends an update.

Example metrics object:

{
  counters: {
    'netrix.bytes.received': 5773742,  // builtin, bytes received since last flush
    'netrix.frames.received': 5674,    // frames received since last flush
    'netrix.metrics.received': 481618, // metrics received since last flush
    counter1: 481618 // user counter from client.increment('counter1');
  },
  gauges: {
    'netrix.flush.lag': 3 // builtin, flush timer lag ms
  }
}

server.start()

  • Returns <Promise>

Starts the server.

server.stop()

  • Returns <Promise>

Stops the server.

server.reset()

Removes all counters and gauges. Bear in mind that under normal operation once a counter or gauge is created it remains in place and is reported with each flush even if there was no change in value.

class NetrixClient

See bin/eg-client.

new NetrixClient([options])

  • options <Object> Optional.
    • host <string> Hostname of the server. Default 'localhost'
    • port <number> Server port. Default 49494.
    • flushInterval <number> Efficienttly accumulate metrics before sending every default 50ms.
    • maxDatagram <number> Multiple metrics sent in each datagram. Limits size. Default 1024 bytes.
  • Returns <netrix.Client>

maxDatagram can theoretically be set as high as 65507 bytes BUT large datagrams simply vanished on OSX laptop. If you decide to deviate from the default do some in-situ benchmarking to determine your sweetspot.

client.start()

  • Returns <Promise>

Start the client.

client.stop()

  • Return <Promise>

Stop the client.

client.increment(metricName[, value])

  • metricName <string> For example 'service1.login.failures'.
  • value Optional. Defaults incrementing counter by 1.

Each call to increment() on the client will result in the counter being incremented at the server. Once the server arrives at the flush boundary the total will be reported in the flush event and the counter will be set back to zero at the server.

client.gauge(metricName, value)

  • metricName <string> For example 'host1.cpu.percent_idle'
  • value The percentage idle.

Each call to gauge() on the client will result in the corresponding guage data being accumulated at the server. These accumulated values will be averaged and reported in the flush event.

client.metric(metricName, value, customTypeCode)

  • metricName
  • value
  • customType <string> Not a guage ('g') or counter ('c').

This allows for the sending of things other than gauge and counter metrics. The server ignores these. But they do cause the metric event to fire and they can be found in each flush event in the raw data.