ping-metrics
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,3 +5,3 @@ // Example usage. Run with `node example.js` | ||
pingMetrics({ip: "104.160.131.1", interval: 1000}, function(metrics) { | ||
var ping1 = pingMetrics({ip: "104.160.131.1", interval: 1000}, function(metrics) { | ||
console.log([ | ||
@@ -14,4 +14,5 @@ "NA Ping: " + Math.round(metrics.ping), | ||
}); | ||
ping1.run(); | ||
pingMetrics({ip: "185.40.65.1", interval: 3000}, function(metrics) { | ||
var ping2 = pingMetrics({ip: "185.40.65.1", interval: 3000}, function(metrics) { | ||
console.log([ | ||
@@ -24,1 +25,12 @@ "EUW Ping: " + Math.round(metrics.ping), | ||
}); | ||
ping2.run(); | ||
setTimeout(function() { | ||
console.log("Stopping ping1"); | ||
ping1.stop(); | ||
}, 5500); | ||
setTimeout(function() { | ||
console.log("Resuming ping1"); | ||
ping1.run(); | ||
}, 10500); |
14
index.js
@@ -51,4 +51,8 @@ var ping = require('net-ping'); | ||
var pingValues = []; | ||
var stop = false; | ||
var run = function() { | ||
if (stop) { | ||
return; | ||
} | ||
var timeStart = new Date().getTime(); | ||
@@ -82,5 +86,13 @@ session.pingHost(options.ip, function(err, target, sent, rcvd) { | ||
}; | ||
run(); | ||
return { | ||
run: function() { | ||
stop = false; | ||
run(); | ||
}, | ||
stop: function() { | ||
stop = true; | ||
} | ||
}; | ||
}; | ||
module.exports = pingMetrics; |
{ | ||
"name": "ping-metrics", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Ping (ICMP) rolling metrics", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,3 +18,3 @@ # ping-metrics | ||
}; | ||
pingMetrics(options, function(metrics) { | ||
var ping = pingMetrics(options, function(metrics) { | ||
console.log([ | ||
@@ -27,2 +27,7 @@ "Current Ping: " + metrics.ping, | ||
}); | ||
ping.run(); | ||
// You can also stop and resume: | ||
ping.stop(); | ||
ping.run(); | ||
``` |
4873
116
32