ipc-healthcheck v1.3.0
IPC-HealthCheck
Health Check server and client for nodejs applications using ipc via unix and windows sockets.
Contents
Install
NodeJS version >=14 is required for this module.
Install via npm:
npm install ipc-healthcheck
Server
Include the server
const HealthcheckServer = require('ipc-healthcheck/healthcheck-server');
Create Server
Creating a new server object Parameter:
namespace
: String - Health check server name clients can connect to.respondTime
: int - Time in ms the server gives the client to respondintervalTime
: int - Time in ms the server waits between every requestsilent
: boolean - Turns debug messages on or off. true = no debug messages
const server = new HealthcheckServer(namespace, respondTime, intervalTime, silent);
Server Methods
The server has the following methods:
startServer()
Start the socket server and starts sending requests to all connected clients. (void)
server.startServer()
stopServer()
Stops sending requests and stops the server. (void)
server.stopServer()
Events
The server does fire the following events:
- serviceRegistered - A new service has registered with the server
- serviceCrashed - A service didn't answer the health check request
- serviceNotify - A service send a message to the server
- serviceDetached - A new service has registered with the server
serviceRegistered
A new client connected and registered to the Server. Healthcheck messages are now sent to this client.
Parameters
service
: Object - Service objectname
: String - Name with which the service is registeredid
: String - ID the Server has given this service
server.on('serviceRegistered', (service) => {
//do stuff
});
serviceCrashed
A client that registered at the Server did not answer the last 3 health check requests and might be crashed.
Parameters:
service
: Object - Service objectname
: String - Name with which the service is registeredid
: String - ID the Server has given this servicelastrespond
: Date - Time the service did the last respond to a request.
server.on('serviceCrashed', (service) => {
//do suff
});
serviceNotify
This event triggers, when a client sends an message to the server.
Parameters:
msg
: String - Message the client send to the Serverservice
: Object - Service objectname
: String - Name with which the service is registeredid
: String - ID the Server has given this servicelastrespond
: Date - Time the service did the last respond to a request.
server.on('serviceNotify', (msg, service) => {
//do stuff
});
serviceDetached
A client that was connected to the server called the detach function and disconnected. This client will not receive any healthcheck messages.
Parameters:
service
: Object - Service objectname
: String - Name with which the service is registeredid
: String - ID the Server has given this servicelastrespond
: Date - Time the service did the last respond to a request.
server.on('serviceDetached', (service) => {
//do stuff
});
Client
Include the client
const HealthcheckClient = require('ipc-healthcheck/healthcheck-client');
Create Client
Creating a new client object
Parameter:
namespace
: String - Health check server name the client should connect toserviceID
: _String - The name with which the client registers with the serversilent
: boolean - Turns debug messages on or off. true = no debug messages
const healthcheckclient = new HealthcheckClient(namespace,serviceID,silent);
Client Methods
The client has the following methods:
startListening()
Client connect to the server and starts listening to health check requests. (void)
client.startListening();
notify()
Sends a message to the server (void)
Parameters:
msg
: String - The message that should be send to the server
client.notify(msg);
detach()
Tell the server to not get any requests anymore and disconnect. (void)
client.detach();
Examples
You can find examples in this repo.