basic plugin for healthcheck
diff --git a/healthcheck/index.js b/healthcheck/index.js new file mode 100644 index 0000000..1713bdf --- /dev/null +++ b/healthcheck/index.js
@@ -0,0 +1,29 @@ +'use strict'; + +var toobusy = require('toobusy-js'); +var debug = require('debug')('gateway:healthcheck'); + +const HEALTHCHECK_URL = '/healthcheck'; + +module.exports.init = function(config, logger, stats) { + return { + onrequest: function(req, res, next) { + var healthcheck_url = config['healthcheck_url'] || HEALTHCHECK_URL + if(healthcheck_url == req.url) { + var statusCode = (this.toobusy() ? 503 : 200) + debug(statusCode) + var healthInfo = { + memoryUsage: process.memoryUsage(), + cpuUsage: process.cpuUsage(), + uptime: process.uptime(), + pid: process.pid + } + res.writeHead(statusCode, { 'Content-Type': 'application/json' }) + res.write(JSON.stringify(healthInfo)) + res.end() + } + else + next() + } + } +}
diff --git a/healthcheck/package.json b/healthcheck/package.json new file mode 100644 index 0000000..001c9c5 --- /dev/null +++ b/healthcheck/package.json
@@ -0,0 +1,22 @@ +{ + "name": "edgemicro-healthcheck", + "version": "1.0.0", + "description": "A basic plugin for healthcheck", + "dependencies": { + "debug": "^2.2.0", + "toobusy-js": "^0.5.1" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/apigee/microgateway-plugins.git" + }, + "author": "srinandan", + "license": "ISC", + "bugs": { + "url": "https://github.com/apigee/microgateway-plugins/issues" + }, + "homepage": "https://github.com/apigee/microgateway-plugins#readme" +}