hapi-k8s-health
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:
server.register
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 astring
orvoid
. Example:
Default:
- livenessProbes: object containing the probes you want your liveness endpoint to execute. A probe is a function returning a
Promise
object of astring
orvoid
. Example:
Default:
- 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 endpointsauth: 'simple'Or for each endpoint:auth:auth:
- metricsName: metrics naming. Override the default metrics names:// Default valuesmetricsName: