In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use Nest.js to achieve simple version request monitoring in node". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Usually, when we do business processing, we want to see the actual situation of business requests on a time side, take a look at the usage of some interfaces, such as cpu memory, and make a monitoring system when making targeted interface optimization. But how can it be realized if you don't have so many resources to start a small project on your own? Here we take a look at nest-status-monitor, a third-party package from Nest.
Installation dependency
First install the required dependencies in our Nest project
Yarn add nest-status-monitor status Monitoring package
The socket package that yarn add @ nestjs/platform-socket.io 6.10.14 needs to use. Here, the old version is installed because the status monitoring package is incompatible with the latest socket package.
Realize
Status monitoring configuration
/ * statusMonitor.ts * / export default {pageTitle: 'Nest.js Monitoring', / / configure port port: 3000, / / remember to add global route'/ api' path:'/ 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: [],}
Referenced in the mian.ts file and registered
/ * main.ts * / import {StatusMonitorModule} from 'nest-status-monitor';import statusMonitorConfig from'. / config/statusMonitor';async function bootstrap () {. / / Registration status monitoring StatusMonitorModule.setUp (statusMonitorConfig),} bootstrap (); effect
Start the project yarn run start:dev
Enter http://localhost:3000/api/status in the browser. This is the set display address. You can also set it according to your own needs and environment.
As shown in the figure above, I have just tested and sent two 400 requests and a 200 request, which are clearly shown at the bottom.
This is the end of the content of "how to use Nest.js to implement simple version request monitoring in node". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.