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.
Here's a quick example of a web service that counts requests and response times, and publishes them to an InfluxDB server:
const crow = ;const request = ;const webService = ;// one registry to rule them all, publishing once a minute.const metrics = crowMetrics;// publish metrics to InfluxDB.metricsevents;// track heap-used as a gauge.// the function will be called on-demand, once a minute.const heapUsed = metrics;metrics;// my website.const requestCount = metrics;const requestTime = metrics;webService;
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 = crowMetrics;
creates a new registry, and a
Metrics object to create and update metrics.
const heapUsed = metrics;const requestCount = metrics;const requestTime = metrics;
These lines define metrics, creating a
Distribution object, each with optional tags. Updating a counter then becomes the single line:
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:
Check out the API documentation for more details.
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.
Apache 2 (open-source) license, included in
@robey - Robey Pointer email@example.com