APM with Elastic Stack for NodeJS Application
Posted By : Jatin Gupta | 30-Oct-2018
Download and unpack APM server
curl -L -O https://artifacts.elastic.co/downloads/apm-server/apm-server-6.2.0-amd64.deb
sudo dpkg -i apm-server-6.2.0-amd64.deb
Import Dashboards
./apm-server setup
Edit the configuration
If you are using
output.elasticsearch:
hosts: ["<es_url>"]
username: <username>
password: <password>
Start APM Server
./apm-server -e
Install the APM Agent
Install the APM agent as a dependency for your node js application
npm install elastic-apm-node --save
Configure the Agent
These agents will run with your application. APM services are created programmatically based on service name we will mention in the code. This agent supports Express, Koa,
// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({
// Set required service name (allowed characters: a-z, A-Z, 0-9, -, _, and space)
serviceName: '',
// Use if APM Server requires a token
secretToken: '',
// Set custom APM Server URL (default: http://localhost:8200)
serverUrl: ''
})
Add this code in your main javascript file you use to run the code which is at most times app.js or server
This code should be placed at the top as it is important that this code should run before you require any module in your app.
What does it do?
Performance Monitoring
Elastic APM agent consequently measures the execution of your NodeJS Express application. It records time ranges for database queries, outer HTTP requests and other moderate activities that occur during requests to your Express application.
The agent will instrument the most widely recognized modules. To instrument different occasions, you can utilize custom ranges.
Time Ranges are grouped in transactions - as a matter, of course, one for every approaching HTTP request. Be that as it may, it's conceivable to make custom exchanges not related to an HTTP request.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Jatin Gupta
Jatin is a DevOps trainee. He ha deep interest in python and cloud technologies. He likes to read about science/history and fiction, listening to music and explore new places.