/** * Get public peering graphs * */ private function _publicPeeringGraphs() { // only do this once every five minutes if ($admin_home_stats = $this->getD2Cache()->fetch('admin_home_stats')) { $this->view->graphs = $admin_home_stats['graphs']; $this->view->stats = $admin_home_stats['stats']; } else { $admin_home_stats = []; $graphs = []; $stats = []; if ($this->multiIXP()) { $ixps = $this->getD2R('\\Entities\\IXP')->findAll(); foreach ($ixps as $ixp) { if ($ixp->getAggregateGraphName()) { $graphs[$ixp->getId()]['name'] = $ixp->getAggregateGraphName(); $graphs[$ixp->getId()]['title'] = $ixp->getName(); $mrtg = new IXP_Mrtg($ixp->getMrtgPath() . DIRECTORY_SEPARATOR . 'ixp_peering-' . $ixp->getAggregateGraphName() . '-' . IXP_Mrtg::CATEGORY_BITS . '.log'); $stats[$ixp->getId()] = $mrtg->getValues(IXP_Mrtg::PERIOD_MONTH, IXP_Mrtg::CATEGORY_BITS); } } } else { $ixp = $this->getD2R('\\Entities\\IXP')->getDefault(); if ($ixp->getAggregateGraphName()) { $graphs[$ixp->getId()]['name'] = $ixp->getAggregateGraphName(); $graphs[$ixp->getId()]['title'] = 'IXP Aggregate Graph'; $mrtg = new IXP_Mrtg($ixp->getMrtgPath() . DIRECTORY_SEPARATOR . 'ixp_peering-' . $ixp->getAggregateGraphName() . '-' . IXP_Mrtg::CATEGORY_BITS . '.log'); $stats[$ixp->getId()] = $mrtg->getValues(IXP_Mrtg::PERIOD_MONTH, IXP_Mrtg::CATEGORY_BITS); } foreach ($ixp->getInfrastructures() as $inf) { if ($inf->getAggregateGraphName()) { $graphs[$ixp->getId() . '-' . $inf->getId()]['name'] = $inf->getAggregateGraphName(); $graphs[$ixp->getId() . '-' . $inf->getId()]['title'] = $inf->getName(); $mrtg = new IXP_Mrtg($ixp->getMrtgPath() . DIRECTORY_SEPARATOR . 'ixp_peering-' . $inf->getAggregateGraphName() . '-' . IXP_Mrtg::CATEGORY_BITS . '.log'); $stats[$ixp->getId() . '-' . $inf->getId()] = $mrtg->getValues(IXP_Mrtg::PERIOD_MONTH, IXP_Mrtg::CATEGORY_BITS); } } } $admin_home_stats['graphs'] = $this->view->graphs = $graphs; $admin_home_stats['stats'] = $this->view->stats = $stats; $this->getD2Cache()->save('admin_home_stats', $admin_home_stats, 300); } }
public function uploadTrafficStatsToDbAction() { // do this for all IXPs $ixps = $this->getD2R('\\Entities\\IXP')->findAll(); foreach ($ixps as $ixp) { $this->verbose("\nProcessing IXP " . $ixp->getName(), false); // This should only be done once a day and if values already exist for 'today', // just delete them. $day = date('Y-m-d'); $this->getD2EM()->getRepository('\\Entities\\TrafficDaily')->deleteForDay($day, $ixp); $custs = $this->getD2R('\\Entities\\Customer')->getConnected(false, true, $ixp); foreach ($custs as $cust) { $this->verbose("\n\t- processing customer " . $cust->getName() . "\t ", false); $stats = array(); foreach (IXP_Mrtg::$CATEGORIES as $category) { $this->verbose("({$category}) ", false); $mrtg = new IXP_Mrtg(IXP_Mrtg::getMrtgFilePath($ixp->getMrtgPath() . '/members', 'LOG', 'aggregate', $category, $cust->getShortname())); $td = new \Entities\TrafficDaily(); $td->setDay(new DateTime($day)); $td->setCategory($category); $td->setCustomer($cust); $td->setIXP($ixp); foreach (IXP_Mrtg::$PERIODS as $name => $period) { $stats = $mrtg->getValues($period, $category, false); $fn = "set{$name}AvgIn"; $td->{$fn}($stats['averagein']); $fn = "set{$name}AvgOut"; $td->{$fn}($stats['averageout']); $fn = "set{$name}MaxIn"; $td->{$fn}($stats['maxin']); $fn = "set{$name}MaxOut"; $td->{$fn}($stats['maxout']); $fn = "set{$name}TotIn"; $td->{$fn}($stats['totalin']); $fn = "set{$name}TotOut"; $td->{$fn}($stats['totalout']); } $this->getD2EM()->persist($td); } $this->getD2EM()->flush(); } } if (isset($this->_options['cli']['traffic_daily']['delete_old']) && $this->_options['cli']['traffic_daily']['delete_old']) { if (isset($this->_options['cli']['traffic_differentials']['stddev_calc_length']) && $this->_options['cli']['traffic_differentials']['stddev_calc_length']) { $this->verbose("\nDeleting old daily traffic records that are no longer required"); $this->getD2EM()->getRepository('\\Entities\\TrafficDaily')->deleteBefore(new DateTime("-{$this->_options['cli']['traffic_differentials']['stddev_calc_length']} days"), $ixp); } } $this->verbose(""); }
public function switchesAction() { $eSwitches = $this->getD2EM()->getRepository('\\Entities\\Switcher')->getAndCache(true, \Entities\Switcher::TYPE_SWITCH); $switches = []; foreach ($eSwitches as $s) { // if we're not doing infrastructure aggregates, we're probably not doing swicth aggregates: if ($s->getInfrastructure()->getAggregateGraphName()) { $switches[$s->getId()]['name'] = $s->getName(); $switches[$s->getId()]['mrtg'] = $s->getInfrastructure()->getIXP()->getMrtgPath(); } } $this->view->switches = $switches; $switch = $this->getParam('switch', array_keys($switches)[0]); if (!in_array($switch, array_keys($switches))) { $switch = array_keys($switches)[0]; } $this->view->switch = $switch; $category = $this->setCategory(); // override allowed categories as some aren't available here $this->view->categories = IXP_Mrtg::$CATEGORIES_AGGREGATE; $this->setPeriod(); $stats = array(); foreach (IXP_Mrtg::$PERIODS as $period) { $mrtg = new IXP_Mrtg($switches[$switch]['mrtg'] . '/switches/' . 'switch-aggregate-' . $switches[$switch]['name'] . '-' . $category . '.log'); $stats[$period] = $mrtg->getValues($period, $category); } $this->view->stats = $stats; }