Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dnlup/fastify-doc

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dnlup/fastify-doc

A Fastify plugin for sampling process metrics.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

fastify-doc

npm version Tests codecov Known Vulnerabilities

A Fastify plugin for sampling process metrics.

It uses the module @dnlup/doc behind the scenes.

It decorates the Fastify instance with a Sampler instance that you can use to get process metrics.

A new sample of the metrics is available when the Sampler emits a sample event.

See @dnlup/doc documentation for more details.

Install

npm i @dnlup/fastify-doc

Usage

Example 1

const fastify = require('fastify')()
const metrics = require('@dnlup/fastify-doc')

fastify.register(metrics)

fastify.register(function myReporter (instance, opts, next) {
  instance.metrics.on('sample', () => {
    // sendCpuUsage(instance.metrics.cpu.usage)
    // ...send other metrics as well
  })

  next()
})

fastify.get('/', (request, reply) => {
  reply.send({ ok: true })
})

fastify.listen(3000)

Example 2

const fastify = require('fastify')()
const metrics = require('@dnlup/fastify-doc')

fastify.register(async function myReporter (instance, opts) {
  await instance.register(metrics)

  instance.metrics.on('sample', () => {
    // sendCpuUsage(instance.metrics.cpu.usage)
    // ...send other metrics as well
  })
})

fastify.get('/', (request, reply) => {
  reply.send({ ok: true })
})

fastify.listen(3000)

Plugin options

The options are the same of @dnlup/doc (reported here for convenience):

  • options <Object>
    • sampleInterval <number>: sample interval (ms) to get a sample. On each sampleInterval ms a sample event is emitted. Default: 500 on Node < 11.10.0, 1000 otherwise. Under the hood the package uses monitorEventLoopDelay when available to track the event loop delay and this allows to increase the default sampleInterval.
    • autoStart <boolean>: start automatically to collect metrics. Default: true.
    • unref <boolean>: unref the timer used to schedule the sampling interval. Default: true.
    • gcOptions <Object>: Garbage collection options
    • eventLoopDelayOptions <Object>: Options to setup monitorEventLoopDelay. Default: { resolution: 10 }
    • collect <Object>: enable/disable the collection of specific metrics.
      • cpu <boolean>: enable cpu metric. Default: true.
      • resourceUsage <boolean>: enable resourceUsage metric. Default: false.
      • eventLoopDelay <boolean>: enable eventLoopDelay metric. Default: true.
      • eventLoopUtilization <boolean>: enable eventLoopUtilization metric. Default: true on Node version 12.19.0 and newer.
      • memory <boolean>: enable memory metric. Default: true.
      • gc <boolean>: enable garbage collection metric. Default: false.
      • activeHandles <boolean>: enable active handles collection metric. Default: false.

If options.collect.resourceUsage is set to true, options.collect.cpu will be set to false because the cpu metric is already available in the resource usage metric.

Decorators

metrics

A Sampler instance.

eventLoopUtilizationSupported

  • <boolean>

Whether the Node.js version in use supports the eventLoopUtilization metric.

resourceUsageSupported

  • <boolean>

Whether the Node.js version in use supports the resourceUsage metric.

gcFlagsSupported

  • <boolean>

Whether the Node.js version in use supports GC flags.

Hooks

onClose

Stops the Sampler instance when closing the server.

License

ISC

Keywords

FAQs

Package last updated on 17 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc