1.5.1 • Published 4 years ago

@chreeio/fastify-status v1.5.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

fastify-status

Build Master status npm version LICENCE

Fastify plugin exposing overall server status: version, health and custom data.

Installation

npm i @chreeio/fastify-status

Features

  • HTTP endpoint serving overall health, custom health checks, version and custom properties.
  • Three-valued (ok, degraded, failing) overall health calculated from custom health checks.
  • Health checks can execute scheduled or on-demand when service status is requested via HTTP.
  • Customizable Fastify onRequest hook executed when the overall health is failing.

Usage

Simply import the plugin and register it:

import fastify from 'fastify'
import fastifyStatus from '@chreeio/fastify-status'

const app = fastify()

app.register(fastifyStatus, {
  route: {
    expose: true,
  },
})

Please take a look at the test folder for more involved examples.

Options

When registering fastify-status, you can set the following options. Please note, that each setting is optional.

OptionDescripton
route.exposeWhether to expose an HTTP endpoint serving status information or not. Set to false by default.
route.pathThe path of the HTTP status endpoint. Set to /status by default.
route.customOptionsAdditional customization for the HTTP status endpoint. Please refer to https://www.fastify.io/docs/latest/Routes/#routes-option regarding the permitted HTTP route options.
health.updateIntervalThe interval between subsequent health checks in milliseconds. If not set, then health checks will be performed on each request to the exposed status endpoint. By default, this setting is not set.
health.checksAn arbitrary number of custom health checks. If an update interval is set, then these checks will be scheduled. Otherwise, they are executed on each request to the status endpoint.
health.overallStatusCalculatorA function calculating the overall health of the service using the values provided by the checks. By default, this function sets the overall health to failing if there's a failing check and degraded if there's a degraded check.
failingStatusRequestHookA Fastify onRequest hook (https://www.fastify.io/docs/latest/Hooks/#onrequest) which is executed on each request if the current overall health of the service is failing. Note, that this hook is only registered if there's an update interval set for the health checks. By default, this hook will return 503 - Service Unavailable to every request.
versionA string to string mapping of version information.
customPropertiesAny additional custom properties. These are going to be appended to the response of the status endpoint.

Acknowledgements

This is an open source project maintained by Chree. For more projects maintained or supported by Chree, please head over to the Chree Open Source page.

Licence

This package is licensed under MIT.