项目作者: bripkens

项目描述 :
Drop-in Node.js admin endpoint to help you analyze production issues.
高级语言: JavaScript
项目地址: git://github.com/bripkens/admin.git
创建时间: 2017-03-03T17:11:24Z
项目社区:https://github.com/bripkens/admin

开源协议:MIT License

下载


admin Build Status js-semistandard-style Greenkeeper badge

Drop-in Node.js admin endpoint to help you analyze production issues.

Live Demo |
Usage |
FAQ |
Plugins |
Example project |
Changelog


Running apps in production can be challenging. Applications may crash, run into bugs or get slow. There are a variety of ways to approach such issues. Admin is a tool to help troubleshoot application issues. It is designed to provide detailed debugging information about running Node.js apps.

Admin provides debugging endpoints via an HTTP server. The functionality provided by this server is extensible as admin is a plugin system.

Instead of describing this at length, check out the live demo system on Heroku!

Contents

Installation

To use admin, the admin Node.js package and at least one plugin needs to be installed. The following example shows a typical setup.

  1. npm install --save admin \
  2. admin-plugin-config \
  3. admin-plugin-healthcheck \
  4. admin-plugin-environment \
  5. admin-plugin-index \
  6. admin-plugin-profile \
  7. admin-plugin-report \
  8. admin-plugin-terminate

Usage

To use admin, it needs to be configured and started with your application. The folowing code listing shows how this can be done.

  1. const admin = require('admin');
  2. admin.configure({
  3. http: { // optional
  4. bindAddress: '127.0.0.1', // default
  5. port: 2999 // default
  6. },
  7. plugins: [
  8. require('admin-plugin-index')(),
  9. require('admin-plugin-report')(),
  10. require('admin-plugin-environment')(),
  11. require('admin-plugin-profile')(),
  12. require('admin-plugin-terminate')(),
  13. require('admin-plugin-config')({
  14. config: {
  15. // An application config goes here. This config object will be
  16. // visible in the admin UI and via the admin REST endpoints.
  17. secret: '42',
  18. port: 8080
  19. }
  20. }),
  21. require('admin-plugin-healthcheck')({
  22. checks: {
  23. // Define multiple healthchecks which check critical components
  24. // in the system. The following example shows valid return values.
  25. random() {
  26. const v = Math.random();
  27. if (v > 0.8) {
  28. throw new Error('Random value >0.8');
  29. } else if (v > 0.3) {
  30. return "Healthy like an application that isn't used.";
  31. } else {
  32. return Promise.reject('Something bad happened here…');
  33. }
  34. }
  35. }
  36. })
  37. ]
  38. });
  39. admin.start();

FAQ

How do I inspect the admin UI when it only binds to localhost?

The easiest solution is to setup an SSH tunnel to the machine:

  1. SSH_KEY="~/.ssh/<my_key>"
  2. REMOTE_USER="<user>"
  3. REMOTE_HOST="<host>"
  4. ADMIN_PORT="<port>"
  5. ssh -i "$SSH_KEY" -Nf -L "$ADMIN_PORT:localhost:$ADMIN_PORT" "$REMOTE_USER@$REMOTE_HOST"
  6. curl "localhost:$ADMIN_PORT"