apaszke / tcp-ping

TCP ping utility for node.js
MIT License
123 stars 27 forks source link

Avg returns NaN when 1 or more ping attempts fail - added a fix #12

Open reganface opened 10 months ago

reganface commented 10 months ago

When 1 or more ping attempts fail, avg in the return object will be NaN, though min and max are returned correctly. As a backwards compatible way of addressing this, I've added two more properties in the return object:

{
    ...
    dropped: 1,
    success_avg: 23.6245
}

dropped will show how many of the attempts errored out. success_avg will return the average of all successful pings, ignoring the errors. If all pings are successful, success_avg and avg will be equal.

Since this is an old project that gets quite a bit of use, I decided to add new properties instead of changing the existing one to avoid breaking changes. It could easily be changed to fix the existing functionality, though.

The version number was updated to 0.1.2 and README.md was updated to show the two new properties in the sample return object.