GithubHelp home page GithubHelp logo

isabella232 / fastify-monitor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from npm/fastify-monitor

0.0 0.0 0.0 601 KB

a small fastify plugin to provide some very basic monitoring endpoints

JavaScript 100.00%

fastify-monitor's Introduction

@npmcorp/fastify-monitor

This is a fastify plugin to provide some simple monitoring endpoints for microservices.

Environment variables

This plugin accepts the following environment variables to override default behavior:

  • PING_RESPONSE: the string resonse to send for a successful /_monitor/ping request
  • BUILD_COMMIT: the commit hash of the current build
  • BUILD_MESSAGE: the commit message of the current build

Options

The following properties may be passed when registering the plugin:

  • app: a string used as an identifier for the microservice, will be returned as part of the status payload
  • monitor:
    • pingResponse: override the default "pong" (or PING_RESPONSE)
    • git:
      • commit: override the commit hash
      • message: override the commit message
    • checks: an array of additional checks to run

Checks

You may register additional checks to be performed each time either route is called. These checks are specified as an object with the following properties:

  • name: the name of your check, this will be used in the status response
  • fn: the function that performs your check, this may return a promise or a value directly
  • schema: the response schema for a successful run

A simple example would look like:

server.register(monitor, {
  checks: [{
    name: 'simple',
    fn: () => {
      return { some: 'data' }
    },
    schema: {
      type: 'object',
      properties: {
        some: {
          type: 'string'
        }
      }
    }
  }]
})

Routes

GET /_monitor/ping

Returns a 200 status code with the string specified by PING_RESPONSE, options.monitor.pingResponse or the default 'pong'.

Note that this route does not perform any additional checks, and is mostly useful as a signal that your service is up and responding (i.e. a livenessProbe in kubernetes).

GET /_monitor/status

Performs all configured checks. This route is useful as a signal that your app is able to perform expected duties (i.e. a readinessProbe in kubernetes). Useful additional checks are things like database connectivity and availability of other requried services.

If successful, returns a 200 status code with an object containing the following fields:

  • app: copied from the options when loading the plugin, will be omitted from response if not defined
  • pid: the running process pid process.pid
  • uptime: the uptime of the running process process.uptime()
  • mem: an object representing the memory usage of the running process process.memoryUsage()
  • git: an object representing the current build's commit, contains the following properties:
    • commit: the hash of the current commit as retrieved by git rev-parse HEAD (can be overridden by setting BUILD_COMMIT, or passing options.monitor.git.commit)
    • message: the message of the current commit as retrieved by git log --pretty=format:%s -n 1 (can be overridden by setting BUILD_MESSAGE or passing options.monitor.git.message)
  • checks: an object containing success statuses for every check run, each top level property will be the name of a check and its value the response from the check

If any check throws or rejects, returns a 500 status code with a JSON response.

fastify-monitor's People

Contributors

dependabot[bot] avatar nlf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.