Skip to content

Instantly share code, notes, and snippets.

@DarrenCattle
Last active August 29, 2015 14:01
Show Gist options
  • Save DarrenCattle/509c65732e218c986583 to your computer and use it in GitHub Desktop.
Save DarrenCattle/509c65732e218c986583 to your computer and use it in GitHub Desktop.
var ping = require('jjg-ping');
function pingGoogle () {
var connected, disconnected, c, d = 0;
var spikelength, spikedistance = [];
this.run = function() {
ping.system.ping('google.com', function(latency, status) {
if (status) {
if(d!=0) {spikelength.push(d); d=0;}
connected++; c++;
console.log('Google is reachable (' + latency + ' ms ping).');
}
else {
spikedistance.push(c); c=0;
disconnected++; d++;
console.log('Google is unreachable.');
}
});
};
this.stats = function () {
console.log('Connected: ' + connected);
console.log('Disconnected: ' + disconnected);
console.log('Spike Length: ' + spikelength);
console.log('Spike Distance: ' + spikedistance);
}
}
var dope = new pingGoogle();
for (var i = 0; i < 10; i++) {dope.run();}
dope.stats();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment