项目作者: julie-ng

项目描述 :
Simple health check endpoint for Express per IETF response format
高级语言: JavaScript
项目地址: git://github.com/julie-ng/standard-healthcheck.git
创建时间: 2020-02-19T12:18:50Z
项目社区:https://github.com/julie-ng/standard-healthcheck

开源协议:MIT License

下载


standard-healthcheck

CI
Test Coverage
codecov
Maintainability

This tiny library exposes a health check endpoint in a standard response format per Internet Engineering Task Force (IETF). The proposed standard includes a few properties not included in standard extensions:

  • description
  • version number (important for debugging)
  • uptime
  • details about dependent downstream services

Example Output

Example JSON response from https://nodejs-demo.onazure.io/health

  1. {
  2. "status": "pass",
  3. "description": "A multipurpose dummy node.js app for cloud architecture demos",
  4. "version": "0.2.1",
  5. "details": {
  6. "uptime": {
  7. "component_type": "system",
  8. "observed_value": 74401.282209224,
  9. "human_readable": "0 days, 20 hours, 40 minutes, 1 seconds",
  10. "observed_unit": "s",
  11. "status": "pass",
  12. "time": "2020-02-20T13:05:11.307Z"
  13. },
  14. "env": {
  15. "WEBSITE_HOSTNAME": "azure-nodejs-demo.azurewebsites.net",
  16. "WEBSITE_INSTANCE_ID": "c33cdebf5b0f427fdd331f28322f183c95c5320c0c952d9194ad7ce9867c2eaa"
  17. }
  18. }
  19. }

For details about schema, see IETF draft document.

Usage

  1. npm install --save standard-healthcheck

Then import the library in your Express.js application and add the route to your app:

  1. const healthcheck = require('standard-healthcheck')
  2. app.get('/health', healthcheck({
  3. version: '1.0',
  4. description: 'My demo app',
  5. includeEnv: ['NODE_ENV']
  6. })

Optional: Environment variables

The proposed standard because is friendly for debugging. You can ask standard-healthcheck to output some environment variables (not recommended for production!) via the includeEnv optional property.

But it will ignore variables ending with SECRET, PASSWORD, _KEY and _PASS for security reasons.