dist/monitor-all.js
function(options, callback) {
      if (typeof options === 'function') {
        callback = options;
        options = null;
      }
      options = options || {};
      callback = callback || function(){};
      var t = this, server = t.get('server'), error,
          startTime = Date.now(),
          port = options.port || Config.Monitor.serviceBasePort,
          attempt = options.attempt || 1,
          allowExternalConnections = Config.Monitor.allowExternalConnections;

      // Recursion detection.  Only scan for so many ports
      if (attempt > Config.Monitor.portsToScan) {
        error = {err:'connect:failure', msg: 'no ports available'};
        log.error('start', error);
        return callback(error);
      }

      // Bind to an existing server, or create a new server
      if (server) {
        t.bindEvents(callback);
      } else {
        server = Http.createServer();

        // Try next port if a server is listening on this port
        server.on('error', function(err) {
          if (err.code === 'EADDRINUSE') {
            // Error if the requested port is in use
            if (t.get('port')) {
              log.error('portInUse',{host:host, port:port});
              return callback({err:'portInUse'});
            }
            // Try the next port
            log.info('portInUse',{host:host, port:port});
            return t.start({port:port + 1, attempt:attempt + 1}, callback);
          }
          // Unknown error
          callback(err);
        });

        // Allow connections from INADDR_ANY or LOCALHOST only
        var host = allowExternalConnections ? '0.0.0.0' : '127.0.0.1';

        // Start listening, callback on success
        server.listen(port, host, function(){

          // Set a default NODE_APP_INSTANCE based on the available server port
          if (!process.env.NODE_APP_INSTANCE)  {
            process.env.NODE_APP_INSTANCE = '' + (port - Config.Monitor.serviceBasePort + 1);
          }

          // Record the server & port, and bind incoming events
          t.set({server: server, port: port});
          t.bindEvents(callback);
          log.info('listening', {
            appName: Config.Monitor.appName,
            NODE_APP_INSTANCE: process.env.NODE_APP_INSTANCE,
            listeningOn: host,
            port: port
          });
        });
      }
    }
function(options, callback) {
      if (typeof options === 'function') {
        callback = options;
        options = null;
      }
      options = options || {};
      callback = callback || function(){};
      var t = this, server = t.get('server'), error,
          startTime = Date.now(),
          port = options.port || Config.Monitor.serviceBasePort,
          attempt = options.attempt || 1,
          allowExternalConnections = Config.Monitor.allowExternalConnections;

      // Recursion detection.  Only scan for so many ports
      if (attempt > Config.Monitor.portsToScan) {
        error = {err:'connect:failure', msg: 'no ports available'};
        log.error('start', error);
        return callback(error);
      }

      // Bind to an existing server, or create a new server
      if (server) {
        t.bindEvents(callback);
      } else {
        server = Http.createServer();

        // Try next port if a server is listening on this port
        server.on('error', function(err) {
          if (err.code === 'EADDRINUSE') {
            // Error if the requested port is in use
            if (t.get('port')) {
              log.error('portInUse',{host:host, port:port});
              return callback({err:'portInUse'});
            }
            // Try the next port
            log.info('portInUse',{host:host, port:port});
            return t.start({port:port + 1, attempt:attempt + 1}, callback);
          }
          // Unknown error
          callback(err);
        });

        // Allow connections from INADDR_ANY or LOCALHOST only
        var host = allowExternalConnections ? '0.0.0.0' : '127.0.0.1';

        // Start listening, callback on success
        server.listen(port, host, function(){

          // Set a default NODE_APP_INSTANCE based on the available server port
          if (!process.env.NODE_APP_INSTANCE)  {
            process.env.NODE_APP_INSTANCE = '' + (port - Config.Monitor.serviceBasePort + 1);
          }

          // Record the server & port, and bind incoming events
          t.set({server: server, port: port});
          t.bindEvents(callback);
          log.info('listening', {
            appName: Config.Monitor.appName,
            NODE_APP_INSTANCE: process.env.NODE_APP_INSTANCE,
            listeningOn: host,
            port: port
          });
        });
      }
    }
function ( options , callback ) { if ( typeof options === 'function' ) { callback = options ; options = null ; } options = options || { } ; callback = callback || function ( ) { } ; var t = this , server = t . get ( 'server' ) , error , startTime = Date . now ( ) , port = options . port || Config . Monitor . serviceBasePort , attempt = options . attempt || 1 , allowExternalConnections = Config . Monitor . allowExternalConnections ; // Recursion detection.  Only scan for so many ports if ( attempt > Config . Monitor . portsToScan ) { error = { err : 'connect:failure' , msg : 'no ports available' } ; log . error ( 'start' , error ) ; return callback ( error ) ; } // Bind to an existing server, or create a new server if ( server ) { t . bindEvents ( callback ) ; } else { server = Http . createServer ( ) ; // Try next port if a server is listening on this port server . on ( 'error' , function ( err ) { if ( err . code === 'EADDRINUSE' ) { // Error if the requested port is in use if ( t . get ( 'port' ) ) { log . error ( 'portInUse' , { host : host , port : port } ) ; return callback ( { err : 'portInUse' } ) ; } // Try the next port log . info ( 'portInUse' , { host : host , port : port } ) ; return t . start ( { port : port + 1 , attempt : attempt + 1 } , callback ) ; } // Unknown error callback ( err ) ; } ) ; // Allow connections from INADDR_ANY or LOCALHOST only var host = allowExternalConnections ? '0.0.0.0' : '127.0.0.1' ; // Start listening, callback on success server . listen ( port , host , function ( ) { // Set a default NODE_APP_INSTANCE based on the available server port if ( ! process . env . NODE_APP_INSTANCE ) { process . env . NODE_APP_INSTANCE = '' + ( port - Config . Monitor . serviceBasePort + 1 ) ; } // Record the server & port, and bind incoming events t . set ( { server : server , port : port } ) ; t . bindEvents ( callback ) ; log . info ( 'listening' , { appName : Config . Monitor . appName , NODE_APP_INSTANCE : process . env . NODE_APP_INSTANCE , listeningOn : host , port : port } ) ; } ) ; } }
Start accepting monitor connections

This method starts listening for incoming monitor connections on the
server.

If the server was specified during object creation, this binds the
socket.io service to the server.

If the server was not specified during object creation, this will create
a server on the first available monitor port.

@method start
@param options {Object} - Start options. OPTIONAL
@param options.port {Integer} - Port to attempt listening on if server isn't specified.  Default: 42000
@param options.attempt {Integer} - Attempt number for internal recursion detection.  Default: 1
@param callback {Function(error)} - Called when the server is accepting connections.
 
The server has started

This event is fired when the server has determined the port to accept
connections on, and has successfully configured the server to start
accepting new monitor connections.

@event start
 
A client error has been detected

This event is fired if an error has been detected in the underlying
transport.  It may indicate message loss, and may result in a
subsequent stop event if the connection cannot be restored.

@event error
Start accepting monitor connections