diff options
author | Stephen Beaver <sbeaver@netgate.com> | 2016-08-18 11:41:19 -0400 |
---|---|---|
committer | Stephen Beaver <sbeaver@netgate.com> | 2016-08-18 11:41:19 -0400 |
commit | 512f2c10af716243046bdd08140856bb8e45222b (patch) | |
tree | c49e4ad3d75fa8a5d5a88455a1439883e3cf67dc /src/usr | |
parent | f30e6bd49c773de28b5ec143add30fc900e7874d (diff) | |
download | pfsense-512f2c10af716243046bdd08140856bb8e45222b.zip pfsense-512f2c10af716243046bdd08140856bb8e45222b.tar.gz |
Added control to set dashboard widget refresh period
Start each widget refresh system after a short random delay to prevent all widgets hitting the server at the exactsame time
Fix issues wherein two widgets were resetting the refresh timer from the AJAX call, not the call-back function, thereby risking stepping on themselves
Diffstat (limited to 'src/usr')
9 files changed, 66 insertions, 22 deletions
diff --git a/src/usr/local/www/system.php b/src/usr/local/www/system.php index 2710186..01368a8 100644 --- a/src/usr/local/www/system.php +++ b/src/usr/local/www/system.php @@ -66,6 +66,7 @@ $pconfig['systemlogsmanagelogpanel'] = isset($config['system']['webgui']['system $pconfig['statusmonitoringsettingspanel'] = isset($config['system']['webgui']['statusmonitoringsettingspanel']); $pconfig['webguihostnamemenu'] = $config['system']['webgui']['webguihostnamemenu']; $pconfig['dnslocalhost'] = isset($config['system']['dnslocalhost']); +$pconfig['dashboardperiod'] = isset($config['widgets']['period']) ? $config['widgets']['period']:"10"; if (!$pconfig['timezone']) { if (isset($g['default_timezone']) && !empty($g['default_timezone'])) { @@ -113,6 +114,10 @@ if ($_POST) { do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); + if ($_POST['dashboardperiod']) { + $config['widgets']['period'] = $_POST['dashboardperiod']; + } + if ($_POST['webguicss']) { $config['system']['webgui']['webguicss'] = $_POST['webguicss']; } else { @@ -356,6 +361,7 @@ $section->addInput(new Form_Input( $pconfig['hostname'], ['placeholder' => 'pfSense'] ))->setHelp('Name of the firewall host, without domain part'); + $section->addInput(new Form_Input( 'domain', 'Domain', @@ -365,6 +371,7 @@ $section->addInput(new Form_Input( ))->setHelp('Do not use \'local\' as a domain name. It will cause local '. 'hosts running mDNS (avahi, bonjour, etc.) to be unable to resolve '. 'local hosts not running mDNS.'); + $form->add($section); $section = new Form_Section('DNS Server Settings'); @@ -441,12 +448,14 @@ $section->addInput(new Form_Checkbox( $form->add($section); $section = new Form_Section('Localization'); + $section->addInput(new Form_Select( 'timezone', 'Timezone', $pconfig['timezone'], array_combine($timezonelist, $timezonelist) ))->setHelp('Select the timezone or location within the timezone to be used by this system.'); + $section->addInput(new Form_Input( 'timeservers', 'Timeservers', @@ -454,6 +463,7 @@ $section->addInput(new Form_Input( $pconfig['timeservers'] ))->setHelp('Use a space to separate multiple hosts (only one required). '. 'Remember to set up at least one DNS server if a host name is entered here!'); + $section->addInput(new Form_Select( 'language', 'Language', @@ -477,6 +487,16 @@ gen_associatedpanels_fields( $pconfig['statusmonitoringsettingspanel']); gen_webguileftcolumnhyper_field($section, $pconfig['webguileftcolumnhyper']); +$section->addInput(new Form_Input( + 'dashboardperiod', + 'Dashboard update period', + 'number', + $pconfig['dashboardperiod'], + ['min' => '10', 'max' => '600'] +))->setHelp('Time in seconds between dashboard widget updates. Small values cause ' . + 'more frequent updates but increase the load on the web server. ' . + 'Minimum is 5 seconds, maximum 600 seconds'); + $form->add($section); print $form; diff --git a/src/usr/local/www/widgets/widgets/dyn_dns_status.widget.php b/src/usr/local/www/widgets/widgets/dyn_dns_status.widget.php index 2dee532..2c1a7b7 100644 --- a/src/usr/local/www/widgets/widgets/dyn_dns_status.widget.php +++ b/src/usr/local/www/widgets/widgets/dyn_dns_status.widget.php @@ -166,8 +166,7 @@ if ($_REQUEST['getdyndnsstatus']) { data: pars, complete: dyndnscallback }); - // Refresh the status every 5 minutes - setTimeout('dyndns_getstatus()', 5*60*1000); + } function dyndnscallback(transport) { // The server returns a string of statuses separated by vertical bars @@ -176,6 +175,9 @@ if ($_REQUEST['getdyndnsstatus']) { var divlabel = '#dyndnsstatus' + count; $(divlabel).prop('innerHTML',responseStrings[count]); } + + // Refresh the status every 5 minutes + setTimeout('dyndns_getstatus()', 5*60*1000); } // Do the first status check 2 seconds after the dashboard opens setTimeout('dyndns_getstatus()', 2000); diff --git a/src/usr/local/www/widgets/widgets/gateways.widget.php b/src/usr/local/www/widgets/widgets/gateways.widget.php index 765f95e..4bb5b67 100644 --- a/src/usr/local/www/widgets/widgets/gateways.widget.php +++ b/src/usr/local/www/widgets/widgets/gateways.widget.php @@ -48,6 +48,8 @@ if ($_POST) { header("Location: /"); exit(0); } + +$widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 : 10000; ?> <div class="table-responsive"> @@ -133,12 +135,14 @@ if ($_POST) { ajaxRequest.done(function (response, textStatus, jqXHR) { $('#gwtblbody').html(response); // and do it again - setTimeout(get_gw_stats, 5000); + setTimeout(get_gw_stats, "<?=$widgetperiod?>"); }); } events.push(function(){ - get_gw_stats(); + // Start polling for updates some small random number of seconds from now (so that all the widgets don't + // hit the server at exactly the same time) + setTimeout(get_gw_stats, Math.floor((Math.random() * 10000) + 1000)); }); //]]> </script> diff --git a/src/usr/local/www/widgets/widgets/installed_packages.widget.php b/src/usr/local/www/widgets/widgets/installed_packages.widget.php index 38c45ce..90dd1be 100644 --- a/src/usr/local/www/widgets/widgets/installed_packages.widget.php +++ b/src/usr/local/www/widgets/widgets/installed_packages.widget.php @@ -163,7 +163,8 @@ if ($_REQUEST && $_REQUEST['ajax']) { $('#pkgtbl').html(response); // and do it again - setTimeout(get_pkg_stats, 5000); + // NOT! There is no need to refresh this widget + // setTimeout(get_pkg_stats, 5000); }); } diff --git a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php index 08c83ea..bfaa82e 100644 --- a/src/usr/local/www/widgets/widgets/interface_statistics.widget.php +++ b/src/usr/local/www/widgets/widgets/interface_statistics.widget.php @@ -84,6 +84,8 @@ if ($_REQUEST && $_REQUEST['ajax']) { exit; } +$widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 : 10000; + ?> <table id="iftbl" class="table table-striped table-hover"> <tr><td><?=gettext("Retrieving interface data")?></td></tr> @@ -106,12 +108,14 @@ if ($_REQUEST && $_REQUEST['ajax']) { $('#iftbl').html(response); // and do it again - setTimeout(get_if_stats, 5000); + setTimeout(get_if_stats, "<?=$widgetperiod?>"); }); } events.push(function(){ - get_if_stats(); + // Start polling for updates some small random number of seconds from now (so that all the widgets don't + // hit the server at exactly the same time) + setTimeout(get_if_stats, Math.floor((Math.random() * 10000) + 1000)); }); //]]> </script> diff --git a/src/usr/local/www/widgets/widgets/ipsec.widget.php b/src/usr/local/www/widgets/widgets/ipsec.widget.php index 0096ce9..ce76f9e 100644 --- a/src/usr/local/www/widgets/widgets/ipsec.widget.php +++ b/src/usr/local/www/widgets/widgets/ipsec.widget.php @@ -180,6 +180,7 @@ if (isset($config['ipsec']['phase1'])) { } $mobile = ipsec_dump_mobile(); +$widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 : 10000; if (isset($config['ipsec']['phase2'])): ?> <div id="ipsec-Overview" style="display:block;" class="table-responsive"> @@ -305,12 +306,14 @@ function get_ipsec_stats() { $('tbody', '#ipsec-' + curtab).html(response); // and do it again - setTimeout(get_ipsec_stats, 6000); + setTimeout(get_ipsec_stats, "<?=$widgetperiod?>"); }); } events.push(function(){ - get_ipsec_stats(); + // Start polling for updates some small random number of seconds from now (so that all the widgets don't + // hit the server at exactly the same time) + setTimeout(get_ipsec_stats, Math.floor((Math.random() * 10000) + 1000)); }); //]]> </script> diff --git a/src/usr/local/www/widgets/widgets/ntp_status.widget.php b/src/usr/local/www/widgets/widgets/ntp_status.widget.php index c0d8384..52993d3 100644 --- a/src/usr/local/www/widgets/widgets/ntp_status.widget.php +++ b/src/usr/local/www/widgets/widgets/ntp_status.widget.php @@ -39,6 +39,10 @@ function clockTimeString($inDate, $showSeconds) { return date($showSeconds ? 'G:i:s' : 'g:i', $inDate) . ' '; } +// For this widget the update period is 6 x larger than most others. It typically defaults +// to once per 60 seconds, not once per 10 seconds +$widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 : 10000; + if ($_REQUEST['updateme']) { //this block displays only on ajax refresh if (isset($config['system']['ipv6allow'])) { @@ -474,16 +478,20 @@ clockUpdate(); data: pars, complete: ntpstatuscallback }); - // Refresh the status every 1 minute - setTimeout('ntp_getstatus()', 1*60*1000); } function ntpstatuscallback(transport) { // The server returns formatted html code var responseStringNtp = transport.responseText $('#ntpstatus').prop('innerHTML',responseStringNtp); + + // Refresh the status at the configured interval + setTimeout('ntp_getstatus()', "<?=$widgetperiod?>"); } - // Do the first status check 1 second after the dashboard opens - setTimeout('ntp_getstatus()', 1000); + + // Start polling for updates some small random number of seconds from now (so that all the widgets don't + // hit the server at exactly the same time) + setTimeout(ntp_getstatus, Math.floor((Math.random() * 10000) + 1000)); + //]]> </script> diff --git a/src/usr/local/www/widgets/widgets/openvpn.widget.php b/src/usr/local/www/widgets/widgets/openvpn.widget.php index 4b74bac..021de5b 100644 --- a/src/usr/local/www/widgets/widgets/openvpn.widget.php +++ b/src/usr/local/www/widgets/widgets/openvpn.widget.php @@ -233,6 +233,8 @@ function printPanel() { } } +$widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 : 10000; + ?> <script type="text/javascript"> @@ -273,14 +275,14 @@ function printPanel() { $('#mainpanel').html(response); // and do it again - setTimeout(get_update, 5000); + setTimeout(get_update, "<?=$widgetperiod?>"); }); } events.push(function(){ // Start polling for updates some small random number of seconds from now (so that all the widgets don't // hit the server at exactly the same time) - setTimeout(get_update, Math.floor((Math.random() * 10000) + 1000)); + setTimeout(get_update, Math.floor((Math.random() * 10000) + 1000)); }); //]]> </script> diff --git a/src/usr/local/www/widgets/widgets/system_information.widget.php b/src/usr/local/www/widgets/widgets/system_information.widget.php index 1512e85..da23d39 100644 --- a/src/usr/local/www/widgets/widgets/system_information.widget.php +++ b/src/usr/local/www/widgets/widgets/system_information.widget.php @@ -77,6 +77,12 @@ if ($_REQUEST['getupdatestatus']) { exit; } +/* Adding one second to the system widet update period + * will ensure that we update the GUI right after the stats are updated. + */ +$widgetperiod = isset($config['widgets']['period']) ? $config['widgets']['period'] * 1000 : 10000; +$widgetperiod += 1000; + $filesystems = get_mounted_filesystems(); ?> @@ -320,13 +326,7 @@ events.push(function(){ }); <?php endif; ?> -/* Most widgets update their backend data every 10 seconds. 11 seconds - * will ensure that we update the GUI right after the stats are updated. - * Seconds * 1000 = value - */ - -var Seconds = 11; -var update_interval = (Math.abs(Math.ceil(Seconds))-1)*1000 + 990; +var update_interval = "<?=$widgetperiod?>"; function setProgress(barName, percent) { $('#' + barName).css('width', percent + '%').attr('aria-valuenow', percent); |