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

@govuk-one-login/frontend-vital-signs

v0.0.4

Published

<!-- Improved compatibility of back to top link: See: https://github.com/othneildrew/Best-README-Template/pull/73 -->

Downloads

181

Readme

About The Project

The GDS Frontend Vitals Signs node package exposes custom metrics (vital-signs) about the health of our Node applications.

The purpose of this package is to make it easy for our FE services to scale in response to demand.

The package is owned by the DI Frontend Capability team, part of the development of this tool involves ongoing discovery with the pods responsible for maintaining the frontend repositories that make up the One Login journey.

Getting Started

Installation

  1. Install NPM package

    npm install @govuk-one-login/frontend-vitals-signs
  2. Import the package in your Node.js application's startup file (example: app.js or index.js):

    const { frontendVitalsInit } = require("@govuk-one-login/frontend-vital-signs");

    If using ES6 Imports or TypeScript:

    import frontendVitalsInit from "@govuk-one-login/frontend-vital-signs";
  3. Configure the server to use the frontendVitalsInit function. This function initialises the frontend vitals monitoring.

Example:


const server = app.listen(port, () => {
 console.log(`Example app listening on port ${port}`);
});

frontendVitalsInit(server, {
 interval: 10000, 
 logLevel: "info",
 metrics: ["requestsPerSecond", "avgResponseTime"],
 staticPaths: [/^\/assets\/.*/, "/ga4-assets", "/javascript", "/stylesheets"], 
});

Example Log:

{
 "level": 30,
 "time": 1722506607855,
 "pid": 22457,
 "hostname": "GDS...",
 "name": "@govuk-one-login/frontend-vital-signs",
 "version": "0.0.3",
 "eventLoopDelay": 10.982777381738174,
 "eventLoopUtilization": {
   "idle": 9972.082872000003,
   "active": 29.954044017529668,
   "utilization": 0.002994794387287299
 },
 "requestsPerSecond": { "dynamic": 0, "static": 0 },
 "avgResponseTime": { "dynamic": null, "static": null },
 "maxConcurrentConnections": 0
}

frontendVitalsInit(server, options)

Parameters

  • server (required): The HTTP or HTTPS server instance that you want to monitor.

  • options (optional): An object containing the following properties:

    • interval (optional, number): The interval in milliseconds for logging metrics. The default value is 10000 (10 seconds).

    • logLevel (optional, string): The log level for the metrics logger. The default value is 'info', which is the level that the metrics are logged at. The available log levels are:

      • fatal: Logs critical errors that may cause the application to crash.
      • error: Logs error messages indicating something went wrong.
      • warn: Logs warnings about potential issues that are not errors but might need attention.
      • info: Logs informational messages about the application's operation.
      • debug: Logs debug information useful for development.
      • trace: Logs detailed information for debugging purposes.
      • silent: Suppresses all logging output.
    • metrics (optional, array): An array of strings specifying which metrics to log. Possible values include:

      • "requestsPerSecond": Logs the number of requests per second.
      • "avgResponseTime": Logs the average response time.
      • "maxConcurrentConnections": Logs the maximum number of concurrent connections.
      • "eventLoopDelay": Logs lag building up due to Node's event loop getting overloaded by asynchronous operations.
      • "eventLoopUtilization": Logs the time the event loop spends in active and idle states.
    • staticPaths (optional, array): An array of strings or regular expressions representing paths to your static files. These paths are used to differentiate between static and dynamic requests.

      • Strings provided are converted to regular expressions with the format ^{string_value}, meaning the path is treated as the starting part of the URL. For example, the string '/static' is treated as '^/static' and will match any URL that starts with /static.