diff options
author | Kristian Lyngstol <kly@kly@.no> | 2016-03-26 03:48:12 +0100 |
---|---|---|
committer | Kristian Lyngstol <kly@kly@.no> | 2016-03-26 03:48:12 +0100 |
commit | 004f4efcfd0779f4307b90fed139dc87d01ad0b9 (patch) | |
tree | f63bef356ae23f63e81e79d54c2cc911c4937004 | |
parent | 25409cdc01450279ce56b78ce962956a9990a175 (diff) |
NMS: Various performance tweaks
-rwxr-xr-x | include/nms/web.pm | 4 | ||||
-rwxr-xr-x | web/nms-public.gathering.org/api/public/dhcp-summary | 7 | ||||
-rwxr-xr-x | web/nms-public.gathering.org/api/public/ping | 6 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/public/dhcp | 2 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/public/dhcp-summary | 7 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/public/ping | 6 | ||||
-rwxr-xr-x | web/nms.gathering.org/api/public/switch-state | 6 | ||||
-rw-r--r-- | web/nms.gathering.org/js/nms-info-box.js | 10 |
8 files changed, 25 insertions, 23 deletions
diff --git a/include/nms/web.pm b/include/nms/web.pm index c9f7236..889e774 100755 --- a/include/nms/web.pm +++ b/include/nms/web.pm @@ -57,7 +57,7 @@ sub db_safe_quote { # endpoints it is better to return no data than old data (e.g.: ping). sub setwhen { $now = "now()"; - my $window = '15m'; + my $window = '8m'; my $offset = '0s'; if (@_ > 0) { $window = $_[0]; @@ -86,6 +86,8 @@ sub finalize_output { printcc; print "Etag: $hash\n"; + print "Access-Control-Allow-Origin: *\n"; + print "Access-Control-Allow-Methods: HEAD, GET\n"; print "Content-Type: text/json; charset=utf-8\n\n"; print JSON::XS::encode_json(\%json); print "\n"; diff --git a/web/nms-public.gathering.org/api/public/dhcp-summary b/web/nms-public.gathering.org/api/public/dhcp-summary index dd643b2..a0e5609 100755 --- a/web/nms-public.gathering.org/api/public/dhcp-summary +++ b/web/nms-public.gathering.org/api/public/dhcp-summary @@ -5,16 +5,11 @@ use warnings; use nms::web; nms::web::setwhen('2h'); -my $q = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp;"); -$q->execute(); -while (my $ref = $q->fetchrow_hashref()) { - $nms::web::json{'dhcp'}{'total'} = $ref; -} my $q2 = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp where $nms::web::when;"); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { - $nms::web::json{'dhcp'}{'recent'} = $ref; + $nms::web::json{'dhcp'} = $ref; } $nms::web::cc{'max-age'} = "10"; $nms::web::cc{'stale-while-revalidate'} = "15"; diff --git a/web/nms-public.gathering.org/api/public/ping b/web/nms-public.gathering.org/api/public/ping index ba572af..db46b00 100755 --- a/web/nms-public.gathering.org/api/public/ping +++ b/web/nms-public.gathering.org/api/public/ping @@ -4,7 +4,7 @@ use strict; use warnings; use nms::web; -#nms::web::setwhen('1s'); +nms::web::setwhen('10s'); my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (now() - time) as age,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where " . $nms::web::when . " group by switch)"); @@ -32,6 +32,6 @@ while ( my $ref = $lq->fetchrow_hashref() ) { $nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ]; } -$nms::web::cc{'max-age'} = "1"; -$nms::web::cc{'stale-while-revalidate'} = "5"; +$nms::web::cc{'max-age'} = "2"; +$nms::web::cc{'stale-while-revalidate'} = "15"; finalize_output(); diff --git a/web/nms.gathering.org/api/public/dhcp b/web/nms.gathering.org/api/public/dhcp index 91d52af..7b048d1 100755 --- a/web/nms.gathering.org/api/public/dhcp +++ b/web/nms.gathering.org/api/public/dhcp @@ -15,6 +15,6 @@ while ( my $ref = $q->fetchrow_hashref() ) { $json{'dhcp'}{$ref->{'sysname'}} = $ref->{'time'}; } -$nms::web::cc{'max-age'} = "5"; +$nms::web::cc{'max-age'} = "10"; $nms::web::cc{'stale-while-revalidate'} = "30"; finalize_output(); diff --git a/web/nms.gathering.org/api/public/dhcp-summary b/web/nms.gathering.org/api/public/dhcp-summary index dd643b2..a0e5609 100755 --- a/web/nms.gathering.org/api/public/dhcp-summary +++ b/web/nms.gathering.org/api/public/dhcp-summary @@ -5,16 +5,11 @@ use warnings; use nms::web; nms::web::setwhen('2h'); -my $q = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp;"); -$q->execute(); -while (my $ref = $q->fetchrow_hashref()) { - $nms::web::json{'dhcp'}{'total'} = $ref; -} my $q2 = $nms::web::dbh->prepare("select count(distinct mac) as clients,count(distinct ip) as addresses,count(mac) as acks from dhcp where $nms::web::when;"); $q2->execute(); while (my $ref = $q2->fetchrow_hashref()) { - $nms::web::json{'dhcp'}{'recent'} = $ref; + $nms::web::json{'dhcp'} = $ref; } $nms::web::cc{'max-age'} = "10"; $nms::web::cc{'stale-while-revalidate'} = "15"; diff --git a/web/nms.gathering.org/api/public/ping b/web/nms.gathering.org/api/public/ping index ba572af..db46b00 100755 --- a/web/nms.gathering.org/api/public/ping +++ b/web/nms.gathering.org/api/public/ping @@ -4,7 +4,7 @@ use strict; use warnings; use nms::web; -#nms::web::setwhen('1s'); +nms::web::setwhen('10s'); my $q = $nms::web::dbh->prepare("SELECT DISTINCT ON (sysname) (now() - time) as age,sysname, latency_ms FROM ping NATURAL JOIN switches WHERE time in (select max(time) from ping where " . $nms::web::when . " group by switch)"); @@ -32,6 +32,6 @@ while ( my $ref = $lq->fetchrow_hashref() ) { $nms::web::json{'linknets'}{$ref->{'linknet'}} = [ $ref->{'latency1_ms'}, $ref->{'latency2_ms'} ]; } -$nms::web::cc{'max-age'} = "1"; -$nms::web::cc{'stale-while-revalidate'} = "5"; +$nms::web::cc{'max-age'} = "2"; +$nms::web::cc{'stale-while-revalidate'} = "15"; finalize_output(); diff --git a/web/nms.gathering.org/api/public/switch-state b/web/nms.gathering.org/api/public/switch-state index 0e28cfd..a6caea9 100755 --- a/web/nms.gathering.org/api/public/switch-state +++ b/web/nms.gathering.org/api/public/switch-state @@ -19,6 +19,9 @@ while ( my $ref = $q->fetchrow_hashref() ) { for my $porti (keys %{$data{'ports'}}) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; + if ($porti =~ m/\.0$/) { + next; + } if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) { $smallport =~ s/[0-9-].*$//; } else { @@ -59,6 +62,9 @@ while ( my $ref = $q2->fetchrow_hashref() ) { for my $porti (keys %{$data{'ports'}}) { my %port = %{$data{'ports'}{$porti}}; my $smallport = $porti; + if ($porti =~ m/\.0$/) { + next; + } if (not $smallport =~ m/^ae/ and not $smallport =~ m/^et/) { $smallport =~ s/[0-9-].*$//; } else { diff --git a/web/nms.gathering.org/js/nms-info-box.js b/web/nms.gathering.org/js/nms-info-box.js index a718f78..77f5cf5 100644 --- a/web/nms.gathering.org/js/nms-info-box.js +++ b/web/nms.gathering.org/js/nms-info-box.js @@ -579,6 +579,7 @@ nmsInfoBox._searchSmart = function(id, sw) { return true; } } catch (e) {} + try { if (id.match("active")) { var limit = id; limit = limit.replace("active>",""); @@ -586,21 +587,24 @@ nmsInfoBox._searchSmart = function(id, sw) { limit = limit.replace("active=",""); var operator = id.replace("active","")[0]; if (limit == parseInt(limit)) { + var ports = parseInt(nmsData.switchstate.switches[sw].ifs.ge.live); + limit = parseInt(limit); if (operator == ">" ) { - if (nmsData.switchstate.switches[sw]['totals'].live > limit) { + if (ports > limit) { return true; } } else if (operator == "<") { - if (nmsData.switchstate.switches[sw]['totals'].live < limit) { + if (ports < limit) { return true; } } else if (operator == "=") { - if (nmsData.switchstate.switches[sw]['totals'].live == limit) { + if (ports == limit) { return true; } } } } + } catch (e) {} try { if (nmsData.smanagement.switches[sw].mgmt_v4_addr.match(id)) { return true; |