Enable Node.js monitoring

Contents

Overview

Node.js is an open source, JavaScript runtime environment for server and networking applications. Citrix Smart Tools lets you to monitor Node.js applications installed on your Linux server.

Software prerequisites

  • Linux Operating System
  • Git
  • Node.js version must be version 0.6 or later.

Install and configure Node.js monitor plugin

Before you enable Node.js monitoring, install and configure monitoring plugin for Node.js.

  1. Use the following command to install the monitoring plugin for a Node.js application: 

    npm install git://github.com/scalextremeinc/Node.js-monitoring.git#v1.0.1

    If the installation is not successful, ensure that git is present on your system. 
  2. Include the following lines and restart the Node.js application.

    var monitor = require('scalex-monitor');
    ...
    var server = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
    }).listen(1337, '127.0.0.1');

    monitor.bind(10010); //change this 10010 to an unused port on your server.
    monitor.addMonitoring(server, {'collect_all': 'yes', 'server_port': 1337}); //change 1337 to the port that your node.js application listens on.
  3. The following is a sample code to create custom metrics with monitor.addCustomValue:

    var server = http.createServer(function (req, res) {
    var start = new Date().getTime(); monitor.addCustomValue("hello.random", Math.random());
    monitor.addCustomValue("hello2.duration", new Date().getTime() - start); res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, '127.0.0.1');

Enable Node.js monitor

To enable Node.js monitoring in Citrix Smart Tools:

  1. Log into Citrix Smart Tools.
  2. From the Deployments page, move the pointer over the deployment you monitor and click Details.
  3. Click Monitoring.
  4. Click the name of the server for which you want to enable metrics.
  5. Move the pointer under the Monitoring tab and click Configure. If Monitoring is not enabled, the Enable Monitoring prompt appears. Click Enable.
  6. Click View Existing Information. The Metric Manager page appears listing all the available metric groups. By default, the System metric group appears with the list of available applications. 
  7. Click the Node.js metric group and select Node.js.  The Enable App dialog appears. Click Close to continue.
  8. (Optional) To enable Node.js for other machines in the deployment, click Enable for other machines?. Select the target machines and click Save. 

Once the Node.js application is enabled, the application data will be available on the graphs within 2-5 minutes. The application metric may be identified by the port it listens on.

Examples

Multiple Node.js applications within a single application

The following example illustrates how to enable monitoring of two Node.js applications within a single application.

var monitor = require('scalex-monitor');
var http = require('http');

var server = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

var server2 = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World2\n');
}).listen(1338, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1338/');

monitor.bind(10010);
monitor.addMonitoring(server, {'collect_all': 'yes', 'server_port': 1337});
monitor.addMonitoring(server2, {'collect_all': 'yes', 'server_port': 1338});

console.log('done');

Multiple Node.js applications on same server but separate applications

The following example illustrates how to enable monitoring of two separate Node.js applications on the same server.

 Example configuration for Node.js application 1

var monitor = require('scalex-monitor');
var http = require('http');

var server = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1337/');

monitor.bind(10010);
monitor.addMonitoring(server, {'collect_all': 'yes', 'server_port': 1337});

console.log('done');

 

Example configuration for Node.js application 2 with custom metrics

var monitor = require('scalex-monitor');
var http = require('http');

var server2 = http.createServer(function (req, res) {
var start = new Date().getTime(); monitor.addCustomValue("hello.random", Math.random());
monitor.addCustomValue("hello2.duration", new Date().getTime() - start); res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1338, '127.0.0.1');

console.log('Server running at http://127.0.0.1:1338/');

monitor.bind(10011);

monitor.addMonitoring(server2, {'collect_all': 'yes', 'server_port': 1338});

console.log('done');

0 Comments