Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Ping externally hosted server from Heroku?

Tags:

heroku

I am connecting to a externally hosted MongoDB server from Heroku app. I need to test latency between my Heroku app and MongoDB server. I ran Heroku bash but 'ping' command is not available there. My only purpose is to test latency between Heroku and MongoDB server.

like image 239
willing_to_learn Avatar asked Sep 30 '22 02:09

willing_to_learn


1 Answers

Try this (needs node.js): https://www.npmjs.com/package/tcp-ping

$ heroku run bash
Running `bash` attached to terminal... up, run.9040
~ $ npm install tcp-ping
[email protected] node_modules/tcp-ping
~ $ node
> var tcpp = require('tcp-ping');
undefined
> tcpp.ping({ address: 'www.heroku.com', port: 80 }, function(err, data) {
...     console.log(data);
... });
undefined
> { address: 'www.heroku.com',
  port: 80,
  attempts: 10,
  avg: 10.4436728,
  max: 31.421943,
  min: 4.133464,
  results:
   [ { seq: 0, time: 31.421943 },
     { seq: 1, time: 7.204108 },
     { seq: 2, time: 10.878877 },
     { seq: 3, time: 13.744017 },
     { seq: 4, time: 4.133464 },
     { seq: 5, time: 7.970543 },
     { seq: 6, time: 9.550277 },
     { seq: 7, time: 7.120228 },
     { seq: 8, time: 6.797261 },
     { seq: 9, time: 5.61601 } ] }

undefined

So, first install tcp-ping:

~ $ npm install tcp-ping

Then, copy paste these into the Node REPL client:

var tcpp = require('tcp-ping');
tcpp.ping({ address: 'www.heroku.com', port: 80 }, function(err, data) {
    console.log(data);
});
like image 139
ile Avatar answered Dec 31 '22 22:12

ile