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

barometer

v1.0.0

Published

Lightweight module to extract performance metrics from a webpage

Downloads

3

Readme

barometer

barometer is a very small 2.4KB script that will automatically generate browser-side performance metrics and forward them in an efficient manner to a collection service.

Motivation / Justification / Rationale

Every website monitoring tool I've seen that is said to work with single page applications latches in to various frameworks in order to generate metrics. The approach taken with this project is to measure end user experience rather than the performance of functions within any particular framework. This enables us to ship a tiny script in the head of our webpages to collect rich data across any type of web page or application.

Getting Started

  1. Grab the script in /dist/barometer.min.js.
  2. Embed the script in the <head> of your webpage, before everything else.
  3. Attach the url of your collector service to window.barometer.url.
<!DOCTYPE html>
  <head>
    <script type="text/javascript">--PASTE-SCRIPT-HERE--</script>
    <script type="text/javascript">window.barometer.url='https://foobar'</script>
    ...

If you want to see the generated metrics in your console, you can set window.barometer.debug to any truthy value.

Metric Payload

Metrics are gathered in the format used by a statsd / graphite / grafana stack - there are two types, gauges and counters. The buffered metric payloads sent to the collection service of your choosing look like this:

// Content-Type: application/json
{
  "gauges": {
    "foo.bar.baz": [ 123 ],
    "foo.bar.boo": [ 123 , 456 ]
  },
  "counters": {
    "foo.bar.baz": [ 5 ]
  }
}

What metrics are gathered?

  • PageChange - When the page loads, or whenever a navigation event occurs, we log a counter for the page visit and a gauge for how long the page load took. The page load is a measure of the time between the navigation event firing, the event loop lagging for over 25ms and finally the event loop freeing up for 125ms. Basically we wait for the page to get busy, then we wait for it to finish being busy.
  • PageLoad - We use window.performance to get details of the initial page load.
  • XhrStats - We monkey-patch over XMLHttpRequest in order to identify every AJAX request, the destination, the transition between states, final response size and timing.

How are the metrics transmitted?

  • Metrics are batched up and dispatched in bulk.
  • Whenever a metric is batched, we wait 5 seconds before transmitting the whole batch.
  • If a new metric is generated and we're about to send the batch, the timer is reset.
  • If we have over 100 metrics, the batch will be sent regardless.
  • If the users mouse leave the HTML document, we flush the buffer.
  • If the user navigates away from the page, we attempt to flush the buffer.

Storing Additional Metrics

This module exposes a mechanism for other pieces of Javascript to generate metrics:

window.barometer = {
  url: null,
  debug: null,
  count: function (metric),
  gauge: function (metric, value) { }
}

Other scripts on the page can use this, drastically reducing the barriers to entry for logging application metrics.

What could a complete metrics stack look like?

  1. barometer - client-side metric gathering tool
  2. A DIY service to receive and expand metrics, and provide application security.
  3. statsd - A network daemon for statistic aggregation
  4. Graphite - An enterprise-ready monitoring tool
  5. Grafana - A tool for querying and visualizing time series and metrics