@visulima/health-check
Version:
A library built to provide support for defining service health for node services. It allows you to register async health checks for your dependencies and the service itself, provides a health endpoint that exposes their status, and health metrics.
44 lines (41 loc) • 1.34 kB
JavaScript
import ping from 'pingman';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const DISPLAY_NAME = "Ping check for";
const pingCheck = /* @__PURE__ */ __name((host, options) => async () => {
try {
const response = await ping(host.replace(/^https?:\/\//, ""), options);
if (!response.alive) {
return {
displayName: `${DISPLAY_NAME} ${host}`,
health: {
healthy: false,
message: `Ping failed for ${host}.`,
timestamp: (/* @__PURE__ */ new Date()).toISOString()
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meta: response
};
}
return {
displayName: `${DISPLAY_NAME} ${host}`,
health: {
healthy: true,
message: `${DISPLAY_NAME} ${host} was successful.`,
timestamp: (/* @__PURE__ */ new Date()).toISOString()
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
meta: response
};
} catch (error) {
return {
displayName: `${DISPLAY_NAME} ${host}`,
health: {
healthy: false,
message: error.message,
timestamp: (/* @__PURE__ */ new Date()).toISOString()
}
};
}
}, "pingCheck");
export { pingCheck as default };