Gateway development inevitably monitors nodeJS server running, nodeJS process running and traffic and we might use Grafana to show that, Here is the running status of one of our gateway projects (including CPU, memory, stack usage, Event loop latency, and GC) :

Understand this children’s shoes may know Kibana, many people mostly take Kibana to do log aggregation collection query, in fact, Kibana has a lot of awesome functions, this time we will use Kibana chart function to show the business data of the project, hand in hand to teach you to make good-looking data statistics chart.

Let’s look at the effect first:

Another project:

All of the above tools are open source, can be deployed on the Intranet, completely free, can save companies a lot of money

1. Preparatory work

This preparation is the most important and determines whether or not you can present the chart.

1.1. Generate buried files

First, you need to bury the data you want to focus on in a fixed format to a specified file, we usually write in the bigData directory, for example, the first renderer focused on some of the data requested by the server, so we use code to bury the data in a format like this:

Use a fixed format (the one you agreed on with your big data team) and fixed fields. The fields in the image above contain these: Path, riderId, cityId, type, incoming, TIMESTAMP, PID, hostname, status, cost, etc.

Buried point code is simpler, put a piece of code where each request comes in and out (fYI) :

This._statlogger. info({// where _statLogger is a Winston instance path: req.path, riderId: req.session.riderId, cityId: req.session.cityId,type: 'incoming'})... this._statLogger.info({ path: req.path, riderId: req.session.riderId, cityId: req.session.cityId,type: 'outcoming',
  status: 'success',
  cost: Date.now() - start
})
Copy the code

The resulting data looks like the image above.

1.2. Configure to collect buried files and index each field

I don’t know exactly how to operate this part because it was assigned to the big data team. If you don’t have a big data team, there’s an elastic solution that you can find on Google, and if you don’t have a big data team, drop me a comment and I’ll find out for you

So here’s what we want in the end:

So everything has, only owe configuration ~

2. Kibana chart configuration

The Kibana sidebar has two menus for creating and displaying ICONS, as shown below:

After clicking Visualize, we can see that there is a + button, and after clicking the plus sign, kibana has provided a number of diagrams to Visualize:

Limited to space, we only talk about a few commonly used chart configuration methods, other charts we can draw inferences. There is a map function, the effect is not bad, as shown below:

2.1. Pie chart making

In the previous renderings, we used the pie chart to visually describe the success and failure ratio of sending requests. In the latter renderings, we used it to represent the distribution ratio of long-connection message sending types. Therefore, the pie chart is undoubtedly the best solution for proportional display.

After you’ve selected the pie chart or created a certain type of chart, Kibana will let you choose which item to use to display the chart, as shown below, and helpfully asks you if you want to fork out of an existing chart

After we have selected the project, we arrive at a screen like this:

So we started to configure, remember to click on the configuration in the red box above (above is the new Version of Kibana: 6.5.4, click on the configuration called Split Series, and the old Version of Kibana interface (Version: 5.6.3) Clicked configurations are called Split Slices), which are configured as follows:

Then click on the triangle indicated by the example arrow above to see the effect:

If we want to specify a time range or other filter criteria, the top module of the interface you can use:

The following charts will not be so detailed, listing the corresponding configuration.

2.2 line chart

To show the number per unit time of each request in the above renderings, using the Classification function of Kibana, we used the following configuration:

The following effect is achieved:

2.3. Bar chart

The bar chart is suitable for comparison or trend display. Here we use the bar chart to show the number of requests in several major cities or to show the number of long connections in real-time in each city. The configuration is as follows:

The effect is as follows:

3. Aggregate display of charts

At this point, we use the Dashboard in the left menu bar. We click the plus sign to also go to the new interface:

Click Add to bring up the panel you want to display:

You can then bring together all the panels from the same project to create the first two renderings

And you’re done

4, the last

Well, at present, I only use these three kinds of charts. All the other charts show the same truth. I believe you can make more cool ICONS for the team to use. If you have any questions, please leave a comment

If you are also interested in the configuration of Grafana, you can write an article on the use of Grafana next time