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

crow-metrics

v4.3.3

Published

small metrics collector for node.js servers

Downloads

783

Readme

crow-metrics

Build Status

Crow is a library for collecting metrics about your server, similar to Twitter's Ostrich or Netflix's Servo.(*) It helps you track things like:

  • How many requests am I handling per second?
  • How many requests am I handling concurrently?
  • What is the 90th percentile of latency in my database queries?

On a period of your choosing (for example, minutely) these metrics are summarized. You can then publish them to a graphing or monitoring system like Riemann, InfluxDB, Graphite, or Prometheus.

The goal of crow is to make it dead simple to collect and report these metrics, and to motivate you to add them everywhere!

To have your server also serve up a little webpage of graphs, check out crow-metrics-viz.

(*) Servo? Crow? Get it? Ha ha ha.

Example

Here's a quick example of a web service that counts requests and response times, and publishes them to an InfluxDB server:

const crow = require("crow-metrics");
const request = require("request");

const webService = express();

// one registry to rule them all, publishing once a minute.
const metrics = crow.Metrics.create({ period: 60000 });

// publish metrics to InfluxDB.
metrics.events.attach(crow.exportInfluxDb({ hostname: "influxdb.prod.example.com:8086", database: "prod" }));

// track heap-used as a gauge.
// the function will be called on-demand, once a minute.
const heapUsed = metrics.gauge("heap_used");
metrics.setGauge(heapUsed, () => process.memoryUsage().heapUsed);

// my website.
const requestCount = metrics.counter("request_count");
const requestTime = metrics.distribution("request_time_msec");
webService.get("/", (request, response) => {
  // count incoming requests:
  metrics.increment(requestCount);

  // time how long it takes to respond:
  metrics.time(requestTime, () => {
    response.send("Hello!\n");
  });
});

How does it work?

Metrics consist of counters, gauges, and distributions, all described in the API documentation. They're defined and collected in a Registry (usually there is only one). On a configurable period, these metrics are summarized and sent to listeners. The listeners can push the summary to a push-based service like Graphite, or post the results to a web service for a poll-based service like Prometheus.

In the example above:

const metrics = crow.Metrics.create({ period: 60000 });

creates a new registry, and a Metrics object to create and update metrics.

const heapUsed = metrics.gauge("heap_used");
const requestCount = metrics.counter("request_count");
const requestTime = metrics.distribution("request_time_msec");

These lines define metrics, creating a Gauge, Counter, and Distribution object, each with optional tags. Updating a counter then becomes the single line:

metrics.increment(requestCount);

The collected metrics are pushed once per minute into the events object, so this line attaches a listener that will post those results to an influxDB instance:

metrics.events.attach(crow.exportInfluxDb({ hostname: "influxdb.prod.example.com:8086", database: "prod" }));

Check out the API documentation for more details.

Requirements

The code is written in typescript and compiled into ES7, using async/await and the "perf_tools" module for microsecond-level timing, so it requires at least nodejs 8.

License

Apache 2 (open-source) license, included in LICENSE.txt.

Authors

@robey - Robey Pointer [email protected]