Introduction
The Palzin Monitor (APM) Node.js package simplifies the process of monitoring the performance of your Node.js applications. By automatically instrumenting your application, it records performance metrics related to HTTP requests, database queries, custom code segments, and more. This guide will help you get started with using Palzin Monitor with your Node.js application.
Prerequisites
Before you begin, ensure you have the following prerequisites installed:
Step 1: Install Palzin Monitor Node.js Package
You can easily install the Palzin Monitor Node.js package using npm. Open your terminal or command prompt and run the following command:
Linux/MacOS:
npm install @palzin-apm/palzin-nodejs --save
Windows:
npm install @palzin-apm/palzin-nodejs --save
Step 2: Configure the Ingestion Key and URL
To use Palzin Monitor, you need to configure it with your ingestion key and URL. You can obtain these by creating a project in your Palzin Monitor (APM) dashboard.
If you use dotenv
for managing environment variables, add the following lines to your environment file (e.g., .env
):
PALZIN_APM_INGESTION_KEY=[ingestion key]
PALZIN_APM_URL=[your Palzin Monitor domain]
Step 3: Initialize Palzin Monitor
You should initialize Palzin Monitor as early as possible in your Node.js application. Import the Palzin Monitor module and initialize it with your configuration:
const palzin = require('@palzin-apm/palzin-nodejs')({
ingestionKey: 'YOUR_INGESTION_KEY',
url: 'YOUR_PALZIN_MONITOR_URL',
});
// Continue with the rest of your script...
Step 4: HTTP Request Monitoring
If your Node.js application handles HTTP requests, you can start monitoring them automatically. Ensure that you start a transaction as soon as possible in your web server code. Here's an example using a custom web server:
const http = require('http');
const palzin = require('@palzin-apm/palzin-nodejs')({
ingestionKey: 'YOUR_INGESTION_KEY',
url: 'YOUR_PALZIN_MONITOR_URL',
});
// Setup routes and route handlers
const server = http.createServer((req, res) => {
// Start the transaction
palzin.startTransaction(req.url);
// Your route handling logic here...
// End the transaction
palzin.endTransaction();
});
server.listen(3000, () => {
console.log('Server is running on port 3000');
});
Step 5: Custom Segments
Palzin Monitor allows you to monitor custom code segments within your application. You can use this feature to gain insights into specific parts of your code. Here's how to add custom segments:
const palzin = require('@palzin-apm/palzin-nodejs')({
ingestionKey: 'YOUR_INGESTION_KEY',
url: 'YOUR_PALZIN_MONITOR_URL',
});
palzin.addSegment(() => {
// Your custom code here...
}, 'custom-segment', 'Custom Segment Label');
In the example above, we added a custom segment labeled "Custom Segment Label." You can include any code block you want to monitor using this method.
Step 6: Exception Monitoring
Palzin Monitor automatically reports unhandled exceptions, ensuring you receive real-time alerts for unexpected errors. However, you can also manually report exceptions if needed. Here's how:
try {
// Your code statements here...
} catch (e) {
// Report the exception
palzin.reportException(e);
}
By reporting exceptions intentionally, you can collect diagnostic data and receive real-time alerts for specific exceptions without blocking the execution of your code.
Conclusion
You've successfully integrated Palzin Monitor with your Node.js application. It will now record performance metrics and provide valuable insights into your application's behavior. Monitor the Palzin Monitor dashboard for real-time alerts and performance analysis to ensure your application runs smoothly and efficiently.
Ensure that you replace 'PALZIN_APM_INGESTION_KEY'
and 'PALZIN_APM_URL'
with your actual Palzin Monitor (APM) ingestion key and URL respectively.
This guide provides you with the necessary steps to integrate Palzin Monitor with your Slim Framework application. By following these steps, you can easily monitor and analyze the performance of your Slim application using Palzin Monitor.
It takes less than a minutes to setup your first monitoring.