proxy.js
function healthcheck(node) {
    var ended = false;
    var node_id = node.host + ':' + node.port;
    var client = net.connect(
      {port: node.adminport, host: node.host},
      function onConnect() {
        if (!ended) {
          client.write('health\r\n');
        }
      }
    );

    client.setTimeout(healthCheckInterval, function() {
      client.end();
      markNodeAsUnhealthy(node_id);
      client.removeAllListeners('data');
      ended = true;
    });

    client.on('data', function(data) {
      if (ended) {
        return;
      }

      var health_status = data.toString();
      client.end();
      ended = true;

      if (health_status.indexOf('up') < 0) {
        markNodeAsUnhealthy(node_id);
      } else {
        markNodeAsHealthy(node_id);
      }
    });

    client.on('error', function(e) {
      if (ended) {
        return;
      }

      if (e.code !== 'ECONNREFUSED' && e.code !== 'EHOSTUNREACH' && e.code !== 'ECONNRESET') {
        log('Error during healthcheck on node ' + node_id + ' with ' + e.code, 'ERROR');
      }

      markNodeAsUnhealthy(node_id);
    });
  }
function healthcheck(node) {
    var ended = false;
    var node_id = node.host + ':' + node.port;
    var client = net.connect(
      {port: node.adminport, host: node.host},
      function onConnect() {
        if (!ended) {
          client.write('health\r\n');
        }
      }
    );

    client.setTimeout(healthCheckInterval, function() {
      client.end();
      markNodeAsUnhealthy(node_id);
      client.removeAllListeners('data');
      ended = true;
    });

    client.on('data', function(data) {
      if (ended) {
        return;
      }

      var health_status = data.toString();
      client.end();
      ended = true;

      if (health_status.indexOf('up') < 0) {
        markNodeAsUnhealthy(node_id);
      } else {
        markNodeAsHealthy(node_id);
      }
    });

    client.on('error', function(e) {
      if (ended) {
        return;
      }

      if (e.code !== 'ECONNREFUSED' && e.code !== 'EHOSTUNREACH' && e.code !== 'ECONNRESET') {
        log('Error during healthcheck on node ' + node_id + ' with ' + e.code, 'ERROR');
      }

      markNodeAsUnhealthy(node_id);
    });
  }
function healthcheck ( node ) { var ended = false ; var node_id = node . host + ':' + node . port ; var client = net . connect ( { port : node . adminport , host : node . host } , function onConnect ( ) { if ( ! ended ) { client . write ( 'health\r\n' ) ; } } ) ; client . setTimeout ( healthCheckInterval , function ( ) { client . end ( ) ; markNodeAsUnhealthy ( node_id ) ; client . removeAllListeners ( 'data' ) ; ended = true ; } ) ; client . on ( 'data' , function ( data ) { if ( ended ) { return ; } var health_status = data . toString ( ) ; client . end ( ) ; ended = true ; if ( health_status . indexOf ( 'up' ) < 0 ) { markNodeAsUnhealthy ( node_id ) ; } else { markNodeAsHealthy ( node_id ) ; } } ) ; client . on ( 'error' , function ( e ) { if ( ended ) { return ; } if ( e . code !== 'ECONNREFUSED' && e . code !== 'EHOSTUNREACH' && e . code !== 'ECONNRESET' ) { log ( 'Error during healthcheck on node ' + node_id + ' with ' + e . code , 'ERROR' ) ; } markNodeAsUnhealthy ( node_id ) ; } ) ; }
Perform health check on node
Perform health check on node