This is a fastify plugin to provide some simple monitoring endpoints for microservices.
This plugin accepts the following environment variables to override default behavior:
PING_RESPONSE
: the string resonse to send for a successful/_monitor/ping
requestBUILD_COMMIT
: the commit hash of the current buildBUILD_MESSAGE
: the commit message of the current build
The following properties may be passed when registering the plugin:
app
: a string used as an identifier for the microservice, will be returned as part of the status payloadmonitor
:pingResponse
: override the default"pong"
(orPING_RESPONSE
)git
:commit
: override the commit hashmessage
: override the commit message
checks
: an array of additional checks to run
You may register additional checks to be performed each time either route is called. These checks are specified as an object with the following properties:
name
: the name of your check, this will be used in the status responsefn
: the function that performs your check, this may return a promise or a value directlyschema
: the response schema for a successful run
A simple example would look like:
server.register(monitor, {
checks: [{
name: 'simple',
fn: () => {
return { some: 'data' }
},
schema: {
type: 'object',
properties: {
some: {
type: 'string'
}
}
}
}]
})
Returns a 200
status code with the string specified by PING_RESPONSE
, options.monitor.pingResponse
or the default 'pong'
.
Note that this route does not perform any additional checks, and is mostly useful as a signal that your service is up and responding (i.e. a livenessProbe
in kubernetes).
Performs all configured checks. This route is useful as a signal that your app is able to perform expected duties (i.e. a readinessProbe
in kubernetes). Useful additional checks are things like database connectivity and availability of other requried services.
If successful, returns a 200
status code with an object containing the following fields:
app
: copied from the options when loading the plugin, will be omitted from response if not definedpid
: the running process pidprocess.pid
uptime
: the uptime of the running processprocess.uptime()
mem
: an object representing the memory usage of the running processprocess.memoryUsage()
git
: an object representing the current build's commit, contains the following properties:commit
: the hash of the current commit as retrieved bygit rev-parse HEAD
(can be overridden by settingBUILD_COMMIT
, or passingoptions.monitor.git.commit
)message
: the message of the current commit as retrieved bygit log --pretty=format:%s -n 1
(can be overridden by settingBUILD_MESSAGE
or passingoptions.monitor.git.message
)
checks
: an object containing success statuses for every check run, each top level property will be the name of a check and its value the response from the check
If any check throws or rejects, returns a 500
status code with a JSON response.