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 🙏

© 2021 – Pkg Stats / Ryan Hefner

hapi-k8s-health

v1.1.1

Published

Hapi plugin for k8s metrics and health check

Downloads

6,480

Readme

hapi-k8s-health

npm version Build Status

Hapi plugin to expose health and metrics endpoint for kubernetes or other orchestration platform

Requirements

Works with Hapi v17 or higher

Installation

npm i hapi-k8s-health

In your code:

import { Server } from '@hapi/hapi'
import { HealthPlugin } from 'hapi-k8s-health'


const server = new Server({
    port: 8080
})

server.register({
    plugin: HealthPlugin,
    options: options: {
      livenessProbes: {
        status: () => Promise.resolve('Yeah !')
      },
      readinessProbes: {
        sequelize: () => container.sequelize.authenticate()
      }
    }
})

Features

Metrics endpoint

Exposes Prometheus formatted metrics for http requests and, by default, the default prom-client metrics for node.js.

http metrics

  • http_request_count: Counter total http requests by:

    • path
    • method
    • returned http code
  • http_current_request_count: Gauge number of http requests currently running by:

    • method
  • http_request_duration_seconds: Histogram histogram of http requests duration in seconds by:

    • path
    • method
    • returned http code
  • http_request_duration_ms: Summary summary of http requests duration in milliseconds by:

    • path
    • method
    • returned http code

Liveness endpoint

Endpoint /liveness used by kubernetes to status whether or not the server is alive. Default probe shoule be enough for most cases.

Readiness endpoint

Endpoint /readiness used by kubernetes to status whether or not the server is ready to accept connections. You should probably check your database connection here, for example.

Options

  • prometheusRegister: custom Prometheus register from prom-client library. Defaults to default register
  • collectDefaultMetrics: whether or not the plugin should exposee prom-client default node.js metrics. Default to true
  • defaultMetricsOptions: prom-client options for default metrics. Defaults to {}
  • readinessProbes: object containing the probes you want your readiness endpoint to execute. A probe is a function returning a Promise object of a string or void. Example:
{
    database: () => Promise.resolve('It works'),
    queuer: () => Promise.resolve()
}

Default:

{
    status: Promise.resolve('OK')
}
  • livenessProbes: object containing the probes you want your liveness endpoint to execute. A probe is a function returning a Promise object of a string or void. Example:
{
    database: () => Promise.resolve('It works'),
    queuer: () => Promise.resolve()
}

Default:

{
    status: Promise.resolve('OK')
}
  • livenessRoute: the route you want for your liveness probes. Default: /liveness
  • readinessRoute: the route you want for your readiness probes. Default: /readiness
  • metricsRoute: the route you want for your metrics. Default: /metrics
  • monitorProbes: whether or not you want your probes to be monitored by metrics. Default to false
  • monitorAllRoutesByDefault: whether or not you want all routes to be monitored by default. Default to true
  • exposeLiveness: should the liveness probe be active. Default to true
  • exposeReadiness: should the readiness probe be active. Default to true
  • exposeMetrics: should the metrics endpoint be active. Default to true
  • probesSuccessCode: http status code when successfully executes all probes of liveness or readiness endpoints.Defaults to 200
  • probesErrorCode: http status code when one of the probes of liveness or readiness endpoints throws an error. Defaults to 500
  • auth: hapi route auth option. Can either be for all endpoints
    auth: 'simple'
    auth: {
      mode: 'try',
      strategy: 'jwt'
    }
    Or for each endpoint:
    auth: {
      liveness: false,
      readiness: 'simple',
      metrics: {
        mode: 'try',
        strategies: ['jwt', 'simple']
      }
    }
  • metricsName: metrics naming. Override the default metrics names:
    // Default values
    metricsName: {
      requestCounter: 'http_request_count',
      requestSummary: 'http_request_duration_ms',
      requestDurationHistogram: 'http_request_duration_seconds',
      currentRequests: 'http_current_request_count'
    }