Relic Solution: Network debugging tools available in Synthetics

Did you know that there are several third-party modules useful for network troubleshooting available in Synthetics, including nodejs-traceroute, net-ping, and dns? These can be very useful when trying to troubleshoot any possible network issues between a public or private location, and the endpoint you are monitoring.

Following are some basic examples to help get you started using these modules. I recommend using an API Test monitor for these, however you can use a Scripted Browser as well. If you do use a Scripted Browser monitor though, make sure to add a $browser.get('SOME_URL') to the script so that it doesn’t fail with NetworkError: Monitor produced no traffic.

nodejs-traceroute

const Traceroute = require('nodejs-traceroute');
const endpoint = "YOUR_ENDPOINT";

try {
    const tracer = new Traceroute();
    tracer
        .on('pid', (pid) => {
            console.log(`pid: ${pid}`);
        })
        .on('destination', (destination) => {
            console.log(`destination: ${destination}`);
        })
        .on('hop', (hop) => {
            console.log(`hop: ${JSON.stringify(hop)}`);
        })
        .on('close', (code) => {
            console.log(`close: code ${code}`);
        });
 
    tracer.trace(endpoint);
} catch (ex) {
    console.log(ex);
}

Traceroute with net-ping

var ping = require ("net-ping");
var session = ping.createSession ();
var endpoint = "YOUR_ENDPOINT";

function doneCb (error, target) {
    if (error)
        console.log (target + ": " + error.toString ());
    else
        console.log (target + ": Done");
}
function feedCb (error, target, ttl, sent, rcvd) {
    var ms = rcvd - sent;
    if (error) {
        if (error instanceof ping.TimeExceededError) {
            console.log (target + ": " + error.source + " (ttl="
                    + ttl + " ms=" + ms +")");
        } else {
            console.log (target + ": " + error.toString ()
                    + " (ttl=" + ttl + " ms=" + ms +")");
        }
    } else {
        console.log (target + ": " + target + " (ttl=" + ttl
                + " ms=" + ms +")");
    }
}

//Second parameter is max number of hops
session.traceRoute (endpoint, 30, feedCb, doneCb);

Traceroute with dns and net-ping

var dns = require('dns');
var ping = require ("net-ping");
var endpoint = "YOUR_ENDPOINT";

var options = {
  ttl: 128,
    retries: 1,
    timeout: 5000,
  maxHopTimeouts: 10
};
var session = ping.createSession (options),
 url = endpoint;
 
function doneCb (error, target) {
    if (error)
        console.log (target + ": " + error.toString ());
    else
        console.log (target + ": Done");
}
function feedCb (error, target, ttl, sent, rcvd) {
    var ms = rcvd - sent;
    if (error) {
        if (error instanceof ping.TimeExceededError) {
            console.log (target + ": " + error.source + " (ttl=" + ttl + " ms=" + ms +")");
        } else {
            console.log (target + ": " + error.toString () + " (ttl=" + ttl + " ms=" + ms +")");
        }
    } else {
        console.log (target + ": " + target + " (ttl=" + ttl + " ms=" + ms +")");
    }
}
 
function resolveDNS (url) {
  dns.resolve4(url, function (err, addresses) {
  if (err) throw err;
    // only traceroute on the first address returned
      session.traceRoute (addresses[0], options, feedCb, doneCb);
});
}
 
resolveDNS(endpoint);

ICMP ping with dns and net-ping

var dns = require('dns');
var ping = require("net-ping");
var endpoint = "YOUR_ENDPOINT";

var options = {
  ttl: 128,
  retries: 1,
  timeout: 5000,
};
var session = ping.createSession(options);

function callback(error, target) {
    if (error)
        console.log (target + ": " + error.toString());
    else
        console.log (target + ": Alive");
}

function resolveDNS(url) {
  dns.resolve4(url, function (err, addresses) {
  if (err) throw err;
    // only ping the first address returned
      session.pingHost(addresses[0], callback);
  });
}

resolveDNS(endpoint);
1 Like