TLDR

Making: github.com/midwayjs/pa… , welcome PR, Issue and Star.

Pandora. Js is a Node.js application monitoring manager produced by Alibaba, which enables you to use your Own Node.js application at your fingertips. Our goal is to make the application manageable, measurable and traceable.

We have been using Node.js and participating in the operation and maintenance work since 2014. Pandora. In the process of development, we used a lot of open source software from the community, and this open source of Pandora.js is a feedback to the community. It is hoped that Pandora. Js can make Node.js better applied in professional business scenarios, and give it better basic monitoring operation and maintenance capabilities to serve large-scale business scenarios (just like what we did in the BOSS field of Taobao).

At the same time, this is alibaba’s first open source Node.js software that uses the type system. It uses TypeScript and brings unprecedented logical robustness to Pandora. Js.

You are welcome to try it and build your Node.js operation and maintenance infrastructure based on Pandora.

What is the Pandora. Js

As mentioned earlier, Pandora. Js is a Node.js application monitoring manager. It integrates various types of capabilities such as monitoring, link tracing, debugging, process management, and so on. It’s too messy to go through one by one, but it’s divided into several broad categories:

  1. Make business easier to track
    • Based on Open-tracing, a business link tracing system is implemented.
    • Track every request link in real time so that every request is no longer a black box. At runtime, you can intuitively see where the interface or page is slow, where the error is, and where the timeout is.
    • Real-time tracking of usage and errors of various base middleware such as MySQL, Mongose, Redis, etc.
  2. Make your application more measurable
    • The common Metrics system in the software industry is realized.
    • It comes with a variety of monitoring metrics, from operating system metrics to Node.js Runtime, from HTTP QPS to middleware usage.
    • Support for a variety of Metrics types, based on which you can easily construct your business Metrics.
  3. Make the system more robust
    • A fail-drill extension that simulates the unusable state of most basic middleware. This is from Taobao for many times to promote the precipitation down in the broken network exercise tools.
    • Remote debugging extension, dashboard-based ability to debug your online processes in real time, online business problems no longer blind.
  4. Make your application easier to manage
    • Process management management capabilities, provides the basic process daemon and Cluster capabilities.
    • Basic service management capabilities to meet middleware management scenarios, such as dependency management and standard start-stop interface.
    • Provides basic capabilities for interprocess communication.

All of the capabilities and data mentioned above are available through RESTFul interfaces or text logs, which you can easily integrate into your monitoring management system (we will open source our proprietary monitoring management platform in the near future for better compatibility).

Such generalizations are still a little boring and difficult to understand. Next, I will introduce several main features of the Pandor. js dashboard interface, which is a stand-alone visual instrument that is compatible with Pandor. js. Then at the end of the article is an example that can run ~

Service link tracing – Trace

Link tracing is the first heavyweight feature to be introduced. It allows you to trace the entire process of each business request and visually see at runtime where interfaces or pages are slow, where errors occur, and where timeouts occur.

It sounds awesome, but it’s really easy to use. You simply launch your application with pandora. js and open the Pandora.js dashboard to see all the details of your business link:

Easily identify slow links and faulty links

Yes, where is the most time-consuming, at a glance

Application of measurement

Default application Metrics – built-in Metrics

Pandora. Js provides you with nearly 100 default monitoring metrics right out of the box, making it easy to start monitoring your application.

By default, node.js Runtime indicators, operating system indicators, HTTP Incoming indicators, etc.

Node.js metrics, which contain a number of runtime metrics

Operating system indicators, including Load, CPU, memory, disk, network, and TCP

Custom application Metrics – Custom Metrics

Applications run in production, and there is so much data we want to know and observe. In the past, we wrote a lot of log files, and it was very difficult to view the analysis. Pandora. Js Metrics provides multiple metric types such as Gauge (instantaneous), Counter (Counter), Meter (flow rate), and Histogram (Histogram), so you can easily accomplish most application or business Metrics.

Here’s an example:

Get a Gravatar for the Profile of the user. And then I want to count how many were successful and how many were unsuccessful. (This example is attached at the end of the article)

const {MetricsClientUtil} = require('dorapan'); / / dorapan Pandora is a client SDK const client = MetricsClientUtil. GetMetricsClient (); Const successCounter = client.getCounter('custom', 'custom.gravatar.success'); const failCounter = client.getCounter('custom', 'custom.gravatar.fail'); / /... Some code omitted here const userAvatars = {}; const promises = []; for(const user of rows) { const profileUrl = gravatar.profile_url(user.email); promises.push(urllib.request(profileUrl, { followRedirect: true, dataType: 'json' }).then((res) => { if(typeof res.data === 'object') { successCounter.inc(1); userAvatars[user.email] = res.data; } else { failCounter.inc(1); }})); } await Promise.all(promises);Copy the code

You can already see the Custom grouping in Metrics:

There are, of course, more Metrics types to practice; see the documentation for details.

A simple example

The demonstration of this example relies on two components:

  1. Pandora. Js command-line tool: to launch and monitor the application.
  2. Pandora. Js Dashboard: Standalone GUI for Pandora. Js.

The installation

You’d better install it on Linux, and Pandora. Js depends on Node.js >= 8.0.0 (the current LTS version). We can also partially implement the metrics on macOS. If you’re a Windows user, ALL I can say is welcome PR).

  1. Install the Pandora. Js command line tool:
$ npm i pandora -gCopy the code

When you’re ready, you’ll get a Pandora command.

  1. Install the Pandora. Js dashboard
$ npm i pandora-dashboard -gCopy the code

You can then launch the Pandora. Js dashboard.

$ pandora start --name dashboard `pandora-dashboard-dir`Copy the code

There is command Substitution in Pandora-dashboard-dir, which is a global command injected by pandora.js. The directory that outputs the Pandora. Js dashboard, which is then launched as a normal project.

After installing Dashboard, open http://127.0.0.1:9081 and you can see the Dashboard application, Pandora. Js Dashborad itself.

Start a simple MySQL CRUD example

I found a simple example of Node.js MySQL CRUD for the rest of the demonstration. Of course I made some changes for the demo. The sample project is on Github and you can Clone it by running it around.

In this case the main entry is server.js, run the following command in the project root directory to initialize it.

$ pandora init server.js 
? Which type do you like to generate ? (Use arrow keys)
  fork 
❯ cluster Copy the code

I chose Cluster, but you can choose either option, and the two options behave just like PM2. Fork simply pulls server.js, while Cluster starts server.js (the Master/Worker model) with the Cluster module of Node.js.

After initialization, a procfile.js file will be generated. This file is used to define the project structure, just like PM2’s Process file. Procfile is short for Process File.

Then we run Pandora Start to launch the app:

$ pandora start
Starting rest-crud at /xx/xxx/rest-crud
rest-crud started successfully! Run command [ pandora log rest-crud ] to get more informationCopy the code

First put ask next at http://127.0.0.1:300/api/user under simple CRUD example, do a little operation.

Then let’s ignore the Run Command [Pandora log rest-crud] prompt and go straight to http://127.0.0.1:9081/, and you’ll see:

Click the Standard Output button to see the console Output:

Click Trace to see all links:

Click Metrics to see all Metrics:

This is just the beginning

Node.js apps are still weak in terms of operations, and pandora. js does little to help developers understand their apps better and not get confused or fluffed when problems arise.

Four years, we have seen the rise of the Node, the improvement of the tool chain, has seen shrinking application scenario, the product of all sorts of iteration and accident, sigh, still have to do things, let the Node in the department, in the group, and can have some growth and breakthrough in the industry, at the same time, let oneself view and choose a way, a firm go on.

Finally, once again, you are welcome to try your hand at building your Node.js infrastructure based on Pandora. Js, so that there are no difficult applications to manage.