From f264fba8cddc51bf16f7797fcf447350fa6e55d0 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 23 May 2016 00:51:00 +0200 Subject: Ping and expose ipv6 as a true equal/superior Fixes #80 I should go to bed. Also: Fixes a tiny little issue where we didn't take into account the nature if the OPing timeout? Or has it changed? Either way, no longer do we store thousands of ping replies - per second. --- collectors/ping.pl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'collectors') diff --git a/collectors/ping.pl b/collectors/ping.pl index 590379c..c50ea87 100755 --- a/collectors/ping.pl +++ b/collectors/ping.pl @@ -15,13 +15,14 @@ my $dbh = nms::db_connect(); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; -my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null ORDER BY random()"); +my $q = $dbh->prepare("SELECT switch,host(mgmt_v4_addr) as ip,host(mgmt_v6_addr) as secondary_ip FROM switches WHERE mgmt_v4_addr is not null or mgmt_v6_addr is not null ORDER BY random()"); my $lq = $dbh->prepare("SELECT linknet,addr1,addr2 FROM linknets WHERE addr1 is not null and addr2 is not null"); while (1) { + sleep(0.5); # ping loopbacks my $ping = Net::Oping->new; - $ping->timeout(0.3); + $ping->timeout(0.2); $q->execute; my %ip_to_switch = (); @@ -32,8 +33,10 @@ while (1) { my $switch = $ref->{'switch'}; my $ip = $ref->{'ip'}; - $ping->host_add($ip); - $ip_to_switch{$ip} = $switch; + if (defined($ip) ) { + $ping->host_add($ip); + $ip_to_switch{$ip} = $switch; + } my $secondary_ip = $ref->{'secondary_ip'}; if (defined($secondary_ip)) { @@ -81,7 +84,7 @@ while (1) { $dbh->commit; # ping linknets $ping = Net::Oping->new; - $ping->timeout(0.3); + $ping->timeout(0.2); $lq->execute; my @linknets = (); -- cgit v1.2.3