Simple monitoring tool

preface

At ordinary times, when we do business processing, we want to see a real-time business request, watch the usage of CPU and memory of some interfaces, and make a targeted interface optimization to do a monitoring system. But how do you do it if you’re doing a small project and you don’t have the resources. Let’s take a look at Nest’s nest-Status-Monitor package.

Nest. Js Chinese document is posted to facilitate further study of Nest Chinese document

Status monitoring package Nest-status-monitor


Install dependencies

  • Start by installing the required dependencies in our Nest project

  • Yarn add nest-status-monitor Specifies the status monitoring package

  • Yarn add @nestjs/platform-socket. IO Specifies the socket package to be used in 6.10.14. The version of the status monitoring package is incompatible with the latest socket package, so install the old version

implementation

  • Status Monitoring Configuration

    /* statusmonitor. ts */ export default {pageTitle: 'Nest. Js Monitoring ', // '/status', ignoreStartsWith: '/health/alive', spans: [ { interval: 1, // Every second retention: 60, // Keep 60 datapoints in memory }, { interval: 5, // Every 5 seconds retention: 60, }, { interval: 15, // Every 15 seconds retention: 60, }, ], chartVisibility: { cpu: true, mem: true, load: true, responseTime: true, rps: true, statusCodes: true, }, healthChecks: [], };Copy the code
  • Is referenced in the mian. Ts file and registered

    /* main.ts */ import { StatusMonitorModule } from 'nest-status-monitor'; import statusMonitorConfig from './config/statusMonitor'; async function bootstrap() { ... / / register condition monitoring StatusMonitorModule. SetUp (statusMonitorConfig),} the bootstrap ();Copy the code

The effect

  • Start the project YARN Run start:dev

  • In the browser type http://localhost:3000/api/status this is the address of the display Settings. You can also according to their own needs to set the environment

  • As shown above, I just tested sending two 400 requests and one 200 request, which is clearly shown at the bottom.

conclusion

  • At this point, we have a small tool that can monitor the server in real time without much development cost.
  • You know the gadgets that support Nest open source, and you can communicate in the comments section. Learn from each other ~(~ ▽ ~)~*

reference

  • Chinese Version of Nest