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

中文文档
0.1.4发布于 2025/11/17ISCTypeScriptESM + CJS构建来源已验证近 30 天下载 4766
原始使用文档
文档目录6 节
  1. GOV.UK Frontend Vitals Signs
  2. About The Project
  3. Getting Started
  4. Installation
  5. frontendVitalSignsInit(server, options)
  6. Parameters

Coverage


GOV.UK Frontend Vitals Signs

This package enables GOV UK LOGIN frontend Node.js applications to add frontend vital signs monitoring
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. `frontendVitalsInit(server, options)`

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.

(back to top)

Getting Started

Installation

  1. Install NPM package

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

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

    If using ES6 Imports or TypeScript:

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

Example:


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

frontendVitalSignsInit(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
}


frontendVitalSignsInit(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 the maximum event loop delay recorded within the interval. This is 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.

(back to top)

版本与发布记录

@govuk-one-login/frontend-vital-signs 共发布 7 个版本,首次发布于 2024/08/01;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.4latest2025/11/171 年前
0.1.32025/01/311.8 年前
0.1.22025/01/141.8 年前
0.1.12025/01/101.9 年前
0.1.02024/12/171.9 年前
0.0.42024/08/012 年前

关于 @govuk-one-login/frontend-vital-signs 的常见问题

如何安装 @govuk-one-login/frontend-vital-signs?

在项目目录运行 npm install @govuk-one-login/frontend-vital-signs,或使用 pnpm add / yarn add / bun add。

@govuk-one-login/frontend-vital-signs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@govuk-one-login/frontend-vital-signs 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@govuk-one-login/frontend-vital-signs 可以商用吗?

@govuk-one-login/frontend-vital-signs 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@govuk-one-login/frontend-vital-signs 的下载量有多少?

根据 npm 官方下载统计,@govuk-one-login/frontend-vital-signs 在 2026/10/17 – 2026/11/15 这 30 天内被下载 4,766 次,日均约 159 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@govuk-one-login/frontend-vital-signs 还在维护吗?

最新版本 0.1.4 发布于 2025/11/17(1 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/08/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。