Skip to content

Latest commit

 

History

History

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

API Reference

Top-Level Exports

Importing

Every function described above is a top-level export. You can import any of them like this:

import { createHealthMonitor } from '@meltwater/mlabs-health'

createHealthMonitor(targets, options)

Creates a new health monitor.

Arguments

  1. targets (object): Health checks to use.
  2. options (object):
    • delay (number): Milliseconds before health emits first event. Default: 0.
    • timeout (number): Milliseconds before health check times out with error. Default: 5000 (5 seconds).
    • ttl (number): Seconds to cache health check result. Default: 60 (1 minute).
    • cache (object|null): Default cache instance. Default: an in memory cache with the above ttl.
    • strategy: Health strategy for health. Default: the all-healthy strategy.
    • createHealthCheck: Function to wrap all targets with. Default: the createHealthCheck function provided in this module.

Returns

(object): The health monitor.


createHealthCheck(target)

Creates a health check for use by a health monitor.

  1. target (any): Thing to convert to health check.
  2. options (object):
    • timeout (number): Milliseconds before health check times out with error. Default: 60000 (1 minute).
    • ttl (number): Seconds to cache health check result. Default: 60 (1 minute).
    • cache (object|null): Default cache instance. Default: an in memory cache with the above ttl.

Returns

(function): An asynchronous health check function.


createHealthy(options)

Creates a function which maps health status objects to a boolean healthy status.

Arguments

  1. options (object):
    • minAvailability (number): Minimum availability before unhealthy. Default: 0.9.
    • minReliability (number): Minimum reliability before unhealthy. Default: 0.9.
    • maxDowntime (number): Maximum downtime (in milliseconds) before unhealthy. Default: 5 minutes.

Returns

(function): Function that maps status to boolean.


healthLogging(options)

Logs all events in the status stream for all health checks in the health monitor.

Arguments

  1. options (object):
    • healthMonitor (object): The health monitor to use.
    • log (object): A Bunyan compatible logger. Default: a new logger.

Returns

(undefined)