Performance monitoring of a Node.js app: Step by step instructions
In this post, we are going to walk through how to build your own real-time performance monitoring of a NodeJS app and how this can be used to detect issues on live servers.
We will be using technologies like Elasticsearch, Kibana, Docker Compose, and several NodeJS modules developed here at NearForm.
We show how you can use Docker Compose to run locally or on AWS and we have also created a Vagrantfile that will spin up all the necessary resources if you wish to run it locally on a hypervisor like VirtualBox.
Like our other posts that cover several repos, we have created a quick and easy setup for the resources needed to walk through this tutorial locally.
We have defined the services needed in a Dockerfile. Follow the steps below to spin up resources needed:
If you have Docker Compose installed locally or a cloud provider like AWS then use docker-compose:
Copy to Clipboard
Installation will take about 5 minutes to finish but once done you should be able to bring up Kibana in your browser at https://localhost:5601/
If you have a mismatched version, you will see an error like below:
Node Modules Needed:
We open sourced a few modules for the real time dashboard, and Ill go over each one.
A link to all resources is at the end of this post.
We needed a tool to generate statistics about our running processes, so to do this, we developed the Stats module.
This simple module is used to create a simple event emitter object that emits an event called stats. It contains useful information about the current host machine, the node.js process itself, Garbage Collection within the process and information about how long it is taking your event loop to empty itself and move onto its next iteration.
You can also configure this to add tags to your stats, and it generates a unique id per emitter so you can track down stats for a particular emitter.
Now that you have your stats sent to your elasticsearch server you can install the dashboard for Kibana to visualize it.
To do this, we created the module create-stats-dashboard that makes it very easy to install the dashboard. When you have this module installed through npm, you can run the command create-stats-dashboard to create the dashboard.
It has support configuration env variables to hook it up to any elasticsearch server for creating your dashboard.