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

ps-web-perf-library

v1.1.0

Published

Library for sending web performance data to Elastic stack

Downloads

26

Readme

ps-web-perf-library

This is a tiny library for exporting web performance statistics from Performance API of a browser into Elasticsearch and Kibana.

Why

A browser can tell you a lot of information about web performance through its Performance API. But a typical setup is that you lose out on all these pieces of information because you do not gather them. However, with this library, you can collect and send performance entries to Elasticsearch and display them in Kibana.

Installation

Nothing special here, just use npm:

$ npm install ps-web-perf-library

or yarn:

$ yarn add ps-web-perf-library

Use samanpavel/ps-elastic-stack-setup Docker image to set up Elastic stack:

$ docker run -it --rm \
--env ELASTICURL=https://web-perf-xxxxxx.es.eu-central-1.aws.cloud.es.io \
--env ELASTICPORT=9243 \
--env ELASTICUSER=elastic \
--env ELASTICPASSWORD=mysecretpwd \
--env KIBANAURL=https://web-perf-xxxxxx.kb.eu-central-1.aws.cloud.es.io \
--env KIBANAPORT=9243 \
--env KIBANAUSER=elastic \
--env KIBANAPASSWORD=mysecretpwd \
samanpavel/ps-elastic-stack-setup

Usage

Typically, you want to use it along with some test framework like WDIO or Puppeteer.

The library needs Elastic credentials, you can prepare a .env file where your set them up:

ELASTICURL=
ELASTICPORT=
ELASTICUSER=
ELASTICPASSWORD=

An example how to use the library in code could be the following check where you navigate to a homepage:

require('dotenv').config();
const { exportWebPerfStats } = require('ps-web-perf-library');

it('Open homepage', async () => {
  await browser
    .url(browser.config.baseUrl);

  await expect('#menu')
    .toBeDisplayedInViewport();

  const perfEntries = await browser.execute(() => {
    return window.performance.getEntries();
  });

  await exportWebPerfStats(perfEntries);
});

Or a brief example in Puppeteer:

require('dotenv').config();
const { exportWebPerfStats } = require('ps-web-perf-library');

const perfEntries = await page.evaluate(() => performance.getEntries());
await exportWebPerfStats(perfEntries);

Performance statistics from performance.getEntries() method will end up in Elasticsearch, and will be displayed on Kibana dashboards.

If you want to disable sending statistics into Elastic stack, set up environment variable NOSTATS to true.

I also recommend running a standalone Chrome in a Docker container, e.g.:

$ docker run -d -p 4444:4444 --shm-size="2g" \
selenium/standalone-chrome:4.1.0-20211123

More on that here.

Kibana dashboards

There are two dashboards in Kibana:

Web Perf Request Statistics

image

Web Perf Navigation Statistics

image