* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * * $Id$ */ function NodeStats($id, $dt) { global $DB; if ($stats = $DB->GetRow('SELECT SUM(download) AS download, SUM(upload) AS upload FROM stats WHERE nodeid=? AND dt>?', array($id, time() - $dt))) { list($result['download']['data'], $result['download']['units']) = setunits($stats['download']); list($result['upload']['data'], $result['upload']['units']) = setunits($stats['upload']); $result['downavg'] = $stats['download'] * 8 / 1000 / $dt; $result['upavg'] = $stats['upload'] * 8 / 1000 / $dt; } return $result; } $nodeid = $_GET['id']; $nodestats['hour'] = NodeStats($nodeid, 60 * 60); $nodestats['day'] = NodeStats($nodeid, 60 * 60 * 24); $nodestats['month'] = NodeStats($nodeid, 60 * 60 * 24 * 30); $SMARTY->assign('nodestats', $nodestats); register_plugin('nodes-infobox-end', '../modules/traffic/templates/nodetraffic.html');
function getNodeStats($nodeid) { global $SMARTY, $DB; $nodeid = intval($nodeid); $result = new xajaxResponse(); $nodestats['hour'] = NodeStats($nodeid, 60 * 60); $nodestats['day'] = NodeStats($nodeid, 60 * 60 * 24); $nodestats['month'] = NodeStats($nodeid, 60 * 60 * 24 * 30); $SMARTY->assign('nodeid', $nodeid); $nodeip = $DB->GetOne('SELECT INET_NTOA(ipaddr) FROM vnodes WHERE id = ?', array($nodeid)); $SMARTY->assign('nodeip', $nodeip); $SMARTY->assign('nodestats', $nodestats); $contents = $SMARTY->fetch('node/nodestats.html'); $result->append('nodeinfo', 'innerHTML', $contents); if (ConfigHelper::getConfig('phpui.live_traffic_helper')) { $script = ' live_traffic_start = function() { xajax.config.waitCursor = false; xajax_getThroughput(\'' . $nodeip . '\'); } live_traffic_finished = function() { xajax.config.waitCursor = true; setTimeout("live_traffic_start()", 3000); } '; $result->script($script); $result->script("live_traffic_start()"); } return $result; }