Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ping] Packet loss monitoring #4234

Open
1 task done
smitty-nieto opened this issue Dec 13, 2023 · 5 comments
Open
1 task done

[ping] Packet loss monitoring #4234

smitty-nieto opened this issue Dec 13, 2023 · 5 comments
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added type:enhance-existing feature wants to enhance existing monitor

Comments

@smitty-nieto
Copy link

⚠️ Please verify that this feature request has NOT been suggested before.

  • I checked and didn't find similar feature request

🏷️ Feature Request Type

New Notification, Other

🔖 Feature description

Implement packet loss and latency/round trip times

✔️ Solution

I would think the easiest way to implement this would be in the existing ping monitor.
Adding a packet loss threshold (30%, 50%, etc)
Would prob need to ensure the ping monitor does multiple pings, so maybe a ping count ? (ie : send 5 ping packets)

Since we are already capturing the response time (47 ms) would be good to be able to alert on this.

❓ Alternatives

No response

📝 Additional Context

We have a client right now that we monitor with ping monitor. Since SOME of the pings make it through, it constantly shows up as green. Further investigation shows 33-80% packet loss

5 packets transmitted, 1 received, 80% packet loss, time 4095ms
rtt min/avg/max/mdev = 5.757/5.757/5.757/0.000 ms

Not only packet loss, but being able to set a threshold on the latency would be great. Meaning, if it's normally 47ms for the ping, and it suddenly jumps to 150-200ms, I would want to alert on this.

@smitty-nieto smitty-nieto added the feature-request Request for new features to be added label Dec 13, 2023
@CommanderStorm CommanderStorm added area:monitor Everything related to monitors type:enhance-existing feature wants to enhance existing monitor labels Dec 13, 2023
@smitty-nieto
Copy link
Author

smitty-nieto commented Dec 13, 2023

The Proof of concept here shows it is already a part of the ping module.
Would just need to account for the new packets sent count (default to 5) and packet loss.
Don't think we would need to graph packet loss, just alert or mark down if packet loss is above a certain percentage.

ping-module.js

const ping = require('ping');

exports.pingAsync = function (hostname, ipv6 = false, size = 56, count = 5) {
    return new Promise((resolve, reject) => {
        let received = 0;
        let sent = 0;

        const pingOptions = {
            v6: ipv6,
            packetSize: size,
        };

        const pingResults = [];

        for (let i = 0; i < count; i++) {
            ping.promise.probe(hostname, pingOptions).then((res) => {
                sent++;
                if (res.alive) {
                    received++;
                    pingResults.push(res);
                } else {
                    pingResults.push(null); // Indicate a failed ping
                }

                if (sent === count) {
                    const packetLoss = ((sent - received) / sent) * 100;
                    const averagePingTime = pingResults.reduce((sum, result) => {
                        if (result && result.time) {
                            return sum + parseFloat(result.time);
                        }
                        return sum;
                    }, 0) / received;

                    resolve({
                        packetLoss,
                        averagePingTime,
                        sent,
                        received,
                    });
                }
            }).catch((err) => {
                sent++;
                pingResults.push(err);

                if (sent === count) {
                    const packetLoss = ((sent - received) / sent) * 100;
                    const averagePingTime = pingResults.reduce((sum, result) => {
                        if (result && result.time) {
                            return sum + parseFloat(result.time);
                        }
                        return sum;
                    }, 0) / received;

                    resolve({
                        packetLoss,
                        averagePingTime,
                        sent,
                        received,
                    });
                }
            });
        }
    });
};

ping-test.js

const { pingAsync } = require('./ping-module.js');

async function main() {
    try {
        const hostname = 'www.google.com'; // Replace with the host you want to ping
        const result = await pingAsync(hostname, false, 56, 5);

        console.log(`Packet loss: ${result.packetLoss.toFixed(2)}%`);
        console.log(`Ping count: Sent = ${result.sent}, Received = ${result.received}`);
        if (!isNaN(result.averagePingTime)) {
            console.log(`Average ping time (for successful pings): ${result.averagePingTime.toFixed(2)} ms`);
        } else {
            console.log('Average ping time (for successful pings): N/A');
        }
    } catch (error) {
        console.error('Error:', error.message);
    }
}

main();

node ping-test.js

Packet loss: 0.00%
Ping count: Sent = 5, Received = 5
Average ping time (for successful pings): 9.05 ms

@CommanderStorm CommanderStorm changed the title Packet loss monitoring [ping] Packet loss monitoring Dec 13, 2023
@smitty-nieto
Copy link
Author

Output of packet loss

Packet loss: 80.00%
Ping count: Sent = 5, Received = 1
Average ping time (for successful pings): 9.41 ms

@L-69

This comment was marked as off-topic.

@CommanderStorm

This comment was marked as resolved.

@hadwinfu
Copy link

The Proof of concept here shows it is already a part of the ping module. Would just need to account for the new packets sent count (default to 5) and packet loss. Don't think we would need to graph packet loss, just alert or mark down if packet loss is above a certain percentage.

ping-module.js
ping-test.js
node ping-test.js

Packet loss: 0.00%
Ping count: Sent = 5, Received = 5
Average ping time (for successful pings): 9.05 ms

but in some cases, we need to monitor if a network service is stable, not only if it's down or up. Please support graph packet loss. Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added type:enhance-existing feature wants to enhance existing monitor
Projects
None yet
Development

No branches or pull requests

4 participants