Ejemplo n.º 1
0
 public function actionStat($type, $id)
 {
     Yii::import('ext.moment.index', 1);
     $momentManager = new momentManager($id);
     $stat = $momentManager->stat($type);
     //print_r($stat);
     if (empty($stat)) {
         $this->render('stat/index', array('title' => Yii::t('admin', 'Statistics not avaiable'), 'stat' => array(), 'type' => $type, 'id' => $id));
         Yii::app()->end();
     }
     switch ($type) {
         case 'disk':
             $stat = json_decode($stat, 1);
             foreach ($stat as $k => $s) {
                 foreach ($s['disk info'] as $key => $value) {
                     $s['disk info'][$key] = $this->convertSize($value);
                 }
                 $stat[$k] = $s;
             }
             $all = $stat;
             break;
         case 'rtmp':
             $all = str_replace(array('<html><body>', '</html></body>'), '', $stat);
             break;
         case 'load':
             $stat = json_decode($stat, 1);
             $all = array();
             $stat = array_reverse($stat['statistics']);
             $stat = array_slice($stat, 0, 100);
             $stat = array_reverse($stat);
             foreach ($stat as $key => $value) {
                 $all['time'][] = $value['time'];
                 foreach ($value as $k => $v) {
                     if ($k == 'time') {
                         continue;
                     }
                     if ($k == 'rtmp_sessions') {
                         $all['rtmp_sessions']['sessions'][] = (double) $v;
                         continue;
                     }
                     if ($k == 'HDD utilization') {
                         foreach ($v as $t) {
                             $all['hdd'][$t['device']][] = (double) $t['util'];
                         }
                         continue;
                     }
                     $all[$k]['min'][] = (double) $v['min'];
                     $all[$k]['max'][] = (double) $v['max'];
                     $all[$k]['avg'][] = (double) $v['avg'];
                 }
             }
             break;
         case 'source_info':
             print_r($stat);
             return true;
             break;
         default:
             $all = array();
             break;
     }
     $this->render('stat/index', array('title' => Yii::t('admin', 'Statistics(100 recent changes)'), 'stat' => $all, 'type' => $type, 'id' => $id));
 }