From 47912c237ad44e2dcfd71112e1220ff0d4294d82 Mon Sep 17 00:00:00 2001 From: Mario Galli Date: Wed, 15 Dec 2021 14:49:07 +0100 Subject: [PATCH] division by zero on httping timeouts --- lib/Pingmachine/Order.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Pingmachine/Order.pm b/lib/Pingmachine/Order.pm index 63b3614..9ff35e9 100644 --- a/lib/Pingmachine/Order.pm +++ b/lib/Pingmachine/Order.pm @@ -345,9 +345,15 @@ sub _update_telegraf { my @rtts = @{$results->{pings}}; my @sorted_rtts = @{$results->{rtts}}; + my $loss; my $all_pings = scalar @rtts; my $successful_pings = scalar @sorted_rtts; - my $loss = 100.0*($all_pings - $successful_pings)/$all_pings; + if ($all_pings) { + $loss = 100.0*($all_pings - $successful_pings)/$all_pings; + } + else { + $loss = 100.0; + } my $median = $rtts[int($successful_pings/2)]; # will be undef if empty my $min = $sorted_rtts[0]; # will be undef if empty my $max = pop @sorted_rtts; # will be undef if empty