Last active
August 29, 2015 14:01
-
-
Save DarrenCattle/509c65732e218c986583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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