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

koa-healthcheck

v1.3.2

Published

A simple middleware to monitor an koa2 api.

Downloads

11

Readme

koa-healthcheck

A simple koa middleware to monitor the API.

Install

npm i --save koa-healthcheck

Configuration

Check structure

Every check object must looks like:

const check = {
  name: 'The optional check name',
  type: 'The check type',
  configuration: {},
};

Attributes:

  • name: optional, he's used in the response of the '/healtcheck' to identify the state of each check. Default value is no-name- with ine index of this check.
  • type: required, if the type isn't defined, the check will be skipped.
  • configuration: required, contain a specific configuration for your check.

DB check

A DB check object must looks like:

const mySequelizeConf = {
  database: 'my-db',
  username: null,
  password: null,
  options: {
    storage: './tests.sqlite',
    dialect: 'sqlite'
  },
};

const myDBCheck = {
  type: 'db',
  configuration: mySequelizeConf
};

Ping check

A ping check object must looks like:

const myPingCheck = {
  type: 'ping',
  configuration: {
    url: 'http://my-awesome-site.io/another-url',
  },
};

How to use it

In the index of your project:

const Koa = require('koa');
// Import the middleware:
const healthcheckPlugin = require('koa-healthcheck');

const app = new Koa();
const myChecks = [myDBCheck, myPingCheck]; 
const versionOfMyApp = '1.2.3';

// Just setup the middleware:
healthcheckPlugin(app, myChecks, versionOfMyApp);

app.listen(3456); // enjoy !

Features

Ping

Check if the API is up and return "pong"

GET http://my-api.com/ping
HTTP/1.1 200 OK
"pong"

Healthcheck

Check the state of whole dependencies of your app.

Return and object of states.

GET http://my-api.com/healthcheck
HTTP/1.1 200 OK
{
    "my-first-check": 0,
    "my-second-check": 0,
    "my-third-check": 0
}

The key is the name of the test. The value possible are :

  • 0 when the check is OK
  • 1 when the check is KO

Version

Return the current version of your application based on the setup.

GET http://my-api.com/version
HTTP/1.1 200 OK
"X.Y.Z"

Metrics

Return the amont of request returned with 2XX, 4XX and 5XX status.

GET http://my-api.com/metrics
HTTP/1.1 200 OK
{
    "Http2XX": 2,
    "Http4XX": 1,
    "Http5XX": 1
}

Test it

npm run test

Dependencies

To be able to monitor databases (Mysql, Postrges, sqlite) we're using Sequelize.