function get_interface_rates($iface, &$inKbps, &$outKbps)
{
    $realif = get_real_interface($iface);
    $ifinfo1 = pfSense_get_interface_stats($realif);
    $tmrStart = microtime(true);
    usleep(100000);
    $ifinfo2 = pfSense_get_interface_stats($realif);
    $totTime = microtime(true) - $tmrStart;
    $inKbps = abs($ifinfo2['inbytes'] - $ifinfo1['inbytes']) * (1 / $totTime) / 1000 * 8;
    $outKbps = abs($ifinfo2['outbytes'] - $ifinfo1['outbytes']) * (1 / $totTime) / 1000 * 8;
}
Exemple #2
0
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
	POSSIBILITY OF SUCH DAMAGE.
*/
/*
	pfSense_BUILDER_BINARIES: /usr/bin/netstat
	pfSense_MODULE:	interfaces
*/
##|+PRIV
##|*IDENT=page-xmlrpcinterfacestats
##|*NAME=XMLRPC Interface Stats page
##|*DESCR=Allow access to the 'XMLRPC Interface Stats' page.
##|*MATCH=ifstats.php*
##|-PRIV
require_once 'guiconfig.inc';
require_once "interfaces.inc";
$if = $_GET['if'];
$realif = get_real_interface($if);
if (!$realif) {
    $realif = $if;
    // Need for IPsec case interface.
}
$ifinfo = pfSense_get_interface_stats($realif);
$temp = gettimeofday();
$timing = (double) $temp["sec"] + (double) $temp["usec"] / 1000000.0;
header("Last-Modified: " . gmdate("D, j M Y H:i:s") . " GMT");
header("Expires: " . gmdate("D, j M Y H:i:s", time()) . " GMT");
header("Cache-Control: no-cache, no-store, must-revalidate");
// HTTP/1.1
header("Pragma: no-cache");
// HTTP/1.0
echo "{$timing}|" . $ifinfo['inbytes'] . "|" . $ifinfo['outbytes'] . "\n";
function get_traffic_stats(&$in_data, &$out_data)
{
    global $config;
    global $traffic_last_ugmt, $traffic_last_ifin, $traffic_last_ifout;
    $lcdproc_screen_config = $config['installedpackages']['lcdprocscreens']['config'][0];
    /* read the configured interface */
    $ifnum = $lcdproc_screen_config['scr_traffic_interface'];
    /* get the real interface name (code from ifstats.php)*/
    $realif = get_real_interface($ifnum);
    if (!$realif) {
        $realif = $ifnum;
    }
    // Need for IPSec case interface.
    /* get the interface stats (code from ifstats.php)*/
    $ifinfo = pfSense_get_interface_stats($realif);
    /* get the current time (code from ifstats.php)*/
    $temp = gettimeofday();
    $timing = (double) $temp["sec"] + (double) $temp["usec"] / 1000000.0;
    /* calculate the traffic stats */
    $deltatime = $timing - $traffic_last_ugmt;
    $in_data = "IN:  " . formatSpeedBits(((double) $ifinfo['inbytes'] - $traffic_last_ifin) / $deltatime);
    $out_data = "OUT: " . formatSpeedBits(((double) $ifinfo['outbytes'] - $traffic_last_ifout) / $deltatime);
    $traffic_last_ugmt = $timing;
    $traffic_last_ifin = (double) $ifinfo['inbytes'];
    $traffic_last_ifout = (double) $ifinfo['outbytes'];
}