From 082d0089be7252b9b44e1073fe2edcaebc5380b0 Mon Sep 17 00:00:00 2001 From: Jeff Date: Mon, 31 Jul 2017 17:57:02 -0400 Subject: [PATCH] Traffic Graph improvements (#1472) * Traffic Graph improvements * cleanup * Document variables * Option to change the number of hosts listed 5-30 I set the max as 30, though I don't know what the upper end should be, maybe 50? I worry about resources on the client as you start to increase the number of graphs and data being stored in Javascript. * Memory Leak fix, Increased Top to 50 * Removing memory leak "fixes" that didn't work * Static DHCP reservation hostnames * Simplified dhcp Active leases still need to be done --- src/www/status_graph.php | 230 ++++++++++++++++-- .../widgets/widgets/traffic_graphs.widget.php | 4 +- 2 files changed, 216 insertions(+), 18 deletions(-) diff --git a/src/www/status_graph.php b/src/www/status_graph.php index bcf08e656..485c9f902 100644 --- a/src/www/status_graph.php +++ b/src/www/status_graph.php @@ -1,7 +1,8 @@ . All rights reserved. @@ -34,6 +35,8 @@ require_once("/usr/local/www/widgets/api/plugins/traffic.inc"); // Get configured interface list $ifdescrs = get_configured_interface_with_descr(); +$interfaces = legacy_config_get_interfaces(array('virtual' => false)); +$hostlist = array(); if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable'])) { $ifdescrs['enc0'] = "IPsec"; } @@ -47,6 +50,19 @@ foreach (array('server', 'client') as $mode) { } } +//Create array of hostnames from DHCP +foreach ($interfaces as $ifname => $ifarr) { + foreach (array('dhcpd', 'dhcpdv6') as $dhcp) { + if (isset($config[$dhcp][$ifname]['staticmap'])) { + foreach($config[$dhcp][$ifname]['staticmap'] as $entry) { + if (!empty($entry['hostname'])) { + $hostlist[$entry['ipaddr']] = htmlentities($entry['hostname']); + } + } + } + } +} + if ($_SERVER['REQUEST_METHOD'] === 'GET') { // load initial form data $pconfig = array(); @@ -74,7 +90,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $intsubnet = gen_subnet(find_interface_ip($real_interface), $netmask) . "/$netmask"; $cmd_args = $pconfig['filter'] == "local" ? " -c " . $intsubnet . " " : " -lc 0.0.0.0/0 "; $cmd_args .= $pconfig['sort'] == "out" ? " -T " : " -R "; - $cmd_action = "/usr/local/bin/rate -i {$real_interface} -nlq 1 -Aba 20 {$cmd_args} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $4, $6, $8 }'"; + $cmd_action = "/usr/local/bin/rate -v -i {$real_interface} -nlq 1 -Aba 20 {$cmd_args} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $4, $6, $8 }'"; exec($cmd_action, $listedIPs); for ($idx = 2 ; $idx < count($listedIPs) ; ++$idx) { $fields = explode(':', $listedIPs[$idx]); @@ -82,6 +98,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $addrdata = gethostbyaddr($fields[0]); if ($pconfig['hostipformat'] == 'hostname' && $addrdata != $fields[0]){ $addrdata = explode(".", $addrdata)[0]; + } else if ($pconfig['hostipformat'] == 'hostname' && array_key_exists($fields[0], $hostlist)) { + $addrdata = $hostlist[$fields[0]]; } } else { $addrdata = $fields[0]; @@ -104,9 +122,49 @@ include("head.inc"); ?> - +
@@ -162,6 +308,7 @@ include("head.inc"); + @@ -179,12 +326,24 @@ include("head.inc"); @@ -208,6 +367,28 @@ include("head.inc"); + + + @@ -222,8 +403,10 @@ include("head.inc"); - - + + + + @@ -236,5 +419,18 @@ include("head.inc");
- + diff --git a/src/www/widgets/widgets/traffic_graphs.widget.php b/src/www/widgets/widgets/traffic_graphs.widget.php index b818c18c2..2c6a6371b 100644 --- a/src/www/widgets/widgets/traffic_graphs.widget.php +++ b/src/www/widgets/widgets/traffic_graphs.widget.php @@ -94,7 +94,9 @@ // load data traffic_graph_widget_chart_data_in.datum(chart_data_in).transition().duration(500).call(traffic_graph_widget_chart_in); - traffic_graph_widget_chart_data_out.datum(chart_data_out).transition().duration(500).call(traffic_graph_widget_chart_out); + if (traffic_graph_widget_chart_data_out !== null) { + traffic_graph_widget_chart_data_out.datum(chart_data_out).transition().duration(500).call(traffic_graph_widget_chart_out); + } // set selection d3.selectAll("#traffic_graph_widget_chart_in").selectAll(".nv-series").each(function(d, i) {