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

@5app/health-check-helpers

v1.4.1

Published

System health check helpers

Downloads

791

Readme

health-check-helpers

A set of functions to help determine if a service is healthy or not

Usage

npm install --save @5app/health-check-helpers

Then, in your application, you can import and use any number of helpers:

const {kueStats} = require('@5app/health-check-helpers');
const queueInstance = require('./queueInstance'); // your Kue instance

async function serviceHealth() {
	try {
		const {completeCount, failedCount} = await kueStats(queueInstance);

		return {
			healthy: true,
			kue: {
				completeCount,
				failedCount,
			},
		};
	} catch (error) {
		return {
			healthy: false,
			kue: {
				error: error.message,
			},
		};
	}
}

Motivation

We ended up duplicating the same code multiple times between microservices, so we thought why not extracting it into modules and reuse it across multiple projects.

Helpers

This package includes helpers to fetch some system basic stats (CPU, memory, pid), stats about Kue, and MySQL (work in progress).

kueStats

Provide basic stats about Kue. This is the equivalent of the /stats endpoint of Kue REST API.

Example:

{
	completeCount: 42,
	failedCount: 1,
	inactiveCount: 0,
	activeCount: 0,
	delayedCount: 0
}

processMetadata

Information about the current process and platform:

Example:

{
  platform:{
      type: 'linux',
      freeMemory: '324.320 MB',
      totalMemory: '5957.363 MB',
      startedOn: new Date('2019-04-03T18:13:37.794Z')
   },
   process:{
      pid: 16,
      cpuUsage:{
         user: 1370000,
         system: 780000
      },
      startedOn: new Date('2019-04-09T14:13:53.726Z')
   }
}

healthCheckServer

Creates a basic http server to handle application health checking requirements. This server needs to be started in the main thread of your application (e.g. your server) and by default it will allow checking if the process is responsive or not. You can add the list of your app dependencies to this server to allow checking if these dependencies are healthy or not.

Example:

const {healthCheckServer, bullStats} = require('@5app/health-check-helpers');

healthCheckServer({
	port: 8888, // this is optional and it will default to the value of the environement variable `HEALTHCHECK_PORT` if specified, otherwise it falls back to the port `9999`
	dependencies: [
		{
			name: 'bull', // dependency name
			check: () => bullStats(myQueueObject),
		},
	],
});

The check functions can be sync or async. They will be called by the server without parameters every time the server gets a request.

Note: currently the server provides 1 endpoint (/) for general health status and doesn't provide special readiness, liveness, and debug endpoints.

Other tools

bin/check.js

A simple script for making health check queries is available in the root of the repository. You can use it from your Dockerfile to ping the instance of healthCheckServer using the following command:

HEALTHCHECK --retries=2 --interval=10s --timeout=5s --start-period=5s CMD node node_modules/@5app/health-check-helpers/bin/check.js

This can replace checks that you would traditionally make with curl.

You can configure the script using the following environment variables:

| Setting | Environement variable | Default value | | --------------- | --------------------- | ------------------------------------------------------- | | server port | HEALTHCHECK_PORT | 9999, the same as the default port of healthCheckServer | | server host | HEALTHCHECK_HOST | localhost | | request timeout | HEALTHCHECK_TIMEOUT | 50000 milliseconds | | request path | HEALTHCHECK_PATH | / |