diff options
-rwxr-xr-x | collectors/ping.pl | 13 | ||||
-rwxr-xr-x | web/api/public/ping | 20 | ||||
-rw-r--r-- | web/js/nms-map-handlers.js | 31 |
3 files changed, 46 insertions, 18 deletions
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 = (); diff --git a/web/api/public/ping b/web/api/public/ping index 36e3334..1928368 100755 --- a/web/api/public/ping +++ b/web/api/public/ping @@ -11,20 +11,24 @@ my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::no $q->execute(); while (my $ref = $q->fetchrow_hashref()) { - $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency'} = $ref->{'latency_ms'}; + $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency4'} = $ref->{'latency_ms'}; # Get seconds, without decimlas, from timestamp. # '00:01:01.435601' => 61 seconds. my ( $h, $m, $s ) = split( ':|\.', $ref->{'age'} ); - $nms::web::json{'switches'}{$ref->{'sysname'}}{'age'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'}; + $nms::web::json{'switches'}{$ref->{'sysname'}}{'age4'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'}; } -my $qs = $nms::web::dbh->prepare("SELECT DISTINCT ON (switch) switch, latency_ms FROM ping_secondary_ip WHERE " - . $nms::web::when . " ORDER BY switch, time DESC;"); -$qs->execute(); -while ( my $ref = $qs->fetchrow_hashref() ) { - $nms::web::json{'switches'}{$ref->{'switch'}}{'latency_secondary'} = $ref->{'latency_ms'}; -} +my $q2 = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (" . $nms::web::now . " - time) as age,sysname, latency_ms FROM ping_secondary_ip NATURAL JOIN switches WHERE time in (select max(time) from ping where " + . $nms::web::when . " group by switch)"); +$q2->execute(); +while (my $ref = $q2->fetchrow_hashref()) { + $nms::web::json{'switches'}{$ref->{'sysname'}}{'latency6'} = $ref->{'latency_ms'}; + # Get seconds, without decimlas, from timestamp. + # '00:01:01.435601' => 61 seconds. + my ( $h, $m, $s ) = split( ':|\.', $ref->{'age'} ); + $nms::web::json{'switches'}{$ref->{'sysname'}}{'age6'} = ($h*60*60) + ($m*60) + $s; # $$ref->{'age'}; +} my $lq = $nms::web::dbh->prepare("SELECT DISTINCT ON (linknet) linknet, latency1_ms, latency2_ms FROM linknet_ping WHERE " . $nms::web::when . " ORDER BY linknet, time DESC;"); $lq->execute(); diff --git a/web/js/nms-map-handlers.js b/web/js/nms-map-handlers.js index 09d2525..b863ab2 100644 --- a/web/js/nms-map-handlers.js +++ b/web/js/nms-map-handlers.js @@ -86,6 +86,7 @@ var handlerInfo = function(tag,desc) { * Short name, typically matching the url anchor. */ this.tag = tag; + this.description = desc || "Unknown"; this.data = [ { value: undefined, @@ -329,13 +330,33 @@ function pingInfo(sw) var ret = new handlerInfo("ping","Latency(ms)"); ret.why = "Latency"; try { - ret.data[0].value = nmsData.ping.switches[sw].latency; - ret.score = parseInt(ret.data[0].value) * 10; - if (nmsData.ping.switches[sw].age > 5) { + var v4 = nmsData.ping.switches[sw].latency4; + var v6 = nmsData.ping.switches[sw].latency6; + ret.data[0].value = v4; + ret.data[0].description = "IPv4 latency(ms)"; + ret.data[1] = {}; + ret.data[1].value = v6; + ret.data[1].description = "IPv6 latency(ms)"; + if (v4 == v6 == undefined) { + ret.score = 1000; + ret.why = "No IPv4 or IPv6 ping reply"; + } else if(v6 == undefined) { + ret.score = 200; + ret.why = "No IPv6 ping reply"; + } else if (v4 == undefined) { + ret.score = 199; + ret.why = "No IPv4 ping reply"; + } else { + v4 = parseInt(v4); + v6 = parseInt(v6); + ret.score = (v4 > v6 ? v4 : v6) * 10; + } + if (nmsData.ping.switches[sw].age4 > 5 || nmsData.ping.switches[sw].age6 > 5) { ret.why = "Old ping"; ret.score = 900; } } catch(e) { + console.log(e); ret.data[0].value = "N/A - no ping replies"; ret.why = "No ping replies"; ret.score = 999; @@ -566,7 +587,7 @@ function cpuInit() { } function comboInfo(sw) { - var worst = new handlerInfo("combo"); + var worst = new handlerInfo("combo", "Combo"); worst.score = -1; for (var h in handlers) { try { @@ -579,7 +600,7 @@ function comboInfo(sw) { } catch(e) { } } worst.data = [{ - description: "Worst: " + worst.data[0].description, + description: "Worst: " + worst.description, value: worst.why }]; return worst; |