/** * 缺省动作 */ public function actionIndex() { $module = $this->request->query('module'); $interface = $this->request->query('interface'); $startTime = $this->request->query('start_time'); $endTime = $this->request->query('end_time'); $count = $this->request->query('count'); $moduleStr = ''; foreach (Cache::$moduleData as $mod => $interfaces) { if ($mod == 'WorkerMan') { continue; } $moduleStr .= '<li><a href="' . Route::url('stat-web', ['controller' => 'Statistic']) . '?module=' . $mod . '">' . $mod . '</a></li>'; if ($module == $mod) { foreach ($interfaces as $if) { $moduleStr .= '<li> <a href="' . Route::url('stat-web', ['controller' => 'Statistic']) . '?module=' . $mod . '&interface=' . $if . '">' . $if . '</a></li>'; } } } $logDataArray = $this->getStasticLog($module, $interface, $startTime, $endTime, $count); unset($_GET['ip'], $_GET['offset']); $logStr = ''; foreach ($logDataArray as $address => $log_data) { $temp = explode(':', $address); $ip = array_shift($temp); $logStr .= $log_data['data']; $_GET['ip'][] = $ip; $_GET['offset'][] = $log_data['offset']; } $logStr = nl2br(str_replace("\n", "\n\n", $logStr)); $nextPageUrl = http_build_query($_GET); $logStr .= '</br><center><a href="' . Route::url('stat-web', ['controller' => 'Logger']) . '?' . $nextPageUrl . '">下一页</a></center>'; $this->template->set('content', View::factory('logger/index', ['logStr' => $logStr])); }
echo Route::url('stat-web', ['controller' => 'Logger']); ?> ">日志</a> </li> <li class="dropdown pull-right"> <a href="#" data-toggle="dropdown" class="dropdown-toggle">其它<strong class="caret"></strong></a> <ul class="dropdown-menu"> <li> <a href="<?php echo Route::url('stat-web', ['controller' => 'Admin', 'action' => 'detect-server']); ?> ">探测数据源</a> </li> <li> <a href="<?php echo Route::url('stat-web', ['controller' => 'Admin']); ?> ">数据源管理</a> </li> </ul> </li> </ul> </div> </div> <div class="row clearfix"> <div class="col-md-12 column"> <?php if ($errorMsg) { ?> <div class="alert alert-dismissable alert-danger"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
/** * {@inheritdoc} */ public function url($name, array $params = null, $protocol = null) { return BaseRoute::url($name, $params, $protocol); }
/** * 测试[Route::url()] */ public function testUrl() { $this->assertEquals('/route-test/1', Route::url('test', ['id' => 1])); $this->assertEquals('/route-test/HELLO', Route::url('test', ['id' => 'HELLO'])); }
/** * 默认动作 */ public function actionIndex() { $module = $this->request->query('module'); $interface = $this->request->query('interface'); $date = $this->request->query('date'); if (!$date) { $date = date('Y-m-d'); } $errorMsg = ''; $today = date('Y-m-d'); $timeNow = time(); StatServer::multiRequestStAndModules($module, $interface, $date); $allStr = ''; if (is_array(Cache::$statisticData['statistic'])) { foreach (Cache::$statisticData['statistic'] as $ip => $st_str) { $allStr .= $st_str; } } $codeMap = []; $data = StatServer::formatStatLog($allStr, $date, $codeMap); $interfaceName = "{$module}::{$interface}"; $successSeriesData = $failSeriesData = $successTimeSeriesData = $failTimeSeriesData = []; $totalCount = $failCount = 0; foreach ($data as $timePoint => $item) { if ($item['total_count']) { $successSeriesData[] = "[" . $timePoint * 1000 . ",{$item['total_count']}]"; $totalCount += $item['total_count']; } $failSeriesData[] = "[" . $timePoint * 1000 . ",{$item['fail_count']}]"; $failCount += $item['fail_count']; if ($item['total_avg_time']) { $successTimeSeriesData[] = "[" . $timePoint * 1000 . ",{$item['total_avg_time']}]"; } $failTimeSeriesData[] = "[" . $timePoint * 1000 . ",{$item['fail_avg_time']}]"; } $successSeriesData = implode(',', $successSeriesData); $failSeriesData = implode(',', $failSeriesData); $successTimeSeriesData = implode(',', $successTimeSeriesData); $failTimeSeriesData = implode(',', $failTimeSeriesData); unset($_GET['start_time'], $_GET['end_time'], $_GET['date'], $_GET['fn']); $query = http_build_query($_GET); // 删除末尾0的记录 if ($today == $date) { while (!empty($data) && ($item = end($data)) && $item['total_count'] == 0 && ($key = key($data)) && $timeNow < $key) { unset($data[$key]); } } $tableData = $htmlClass = ''; if ($data) { $firstLine = true; foreach ($data as $item) { if ($firstLine) { $firstLine = false; if ($item['total_count'] == 0) { continue; } } $htmlClass = 'class="danger"'; if ($item['total_count'] == 0) { $htmlClass = ''; } elseif ($item['percent'] >= 99.98999999999999) { $htmlClass = 'class="success"'; } elseif ($item['percent'] >= 99) { $htmlClass = ''; } elseif ($item['percent'] >= 98) { $htmlClass = 'class="warning"'; } $tableData .= "\n<tr {$htmlClass}>\n <td>{$item['time']}</td>\n <td>{$item['total_count']}</td>\n <td> {$item['total_avg_time']}</td>\n <td>{$item['success_count']}</td>\n <td>{$item['suc_avg_time']}</td>\n <td>" . ($item['fail_count'] > 0 ? "<a href='" . Route::url('stat-web', ['controller' => 'Logger']) . "?{$query}&start_time=" . (strtotime($item['time']) - 300) . "&end_time=" . strtotime($item['time']) . "'>{$item['fail_count']}</a>" : $item['fail_count']) . "</td>\n <td>{$item['fail_avg_time']}</td>\n <td>{$item['percent']}%</td>\n </tr>\n "; } } // date btn $dateBtnStr = ''; for ($i = 13; $i >= 1; $i--) { $theTime = strtotime("-{$i} day"); $theDate = date('Y-m-d', $theTime); $htmlTheDate = $date == $theDate ? "<b>{$theDate}</b>" : $theDate; $dateBtnStr .= '<a href="' . Route::url('stat-web', ['controller' => 'Statistic']) . '?date=' . "{$theDate}&{$query}" . '" class="btn ' . $htmlClass . '" type="button">' . $htmlTheDate . '</a>'; if ($i == 7) { $dateBtnStr .= '</br>'; } } $theDate = date('Y-m-d'); $htmlTheDate = $date == $theDate ? "<b>{$theDate}</b>" : $theDate; $dateBtnStr .= '<a href="' . Route::url('stat-web', ['controller' => 'Statistic']) . '?date=' . "{$theDate}&{$query}" . '" class="btn" type="button">' . $htmlTheDate . '</a>'; $moduleStr = ''; foreach (Cache::$moduleData as $mod => $interfaces) { if ($mod == 'WorkerMan') { continue; } $moduleStr .= '<li><a href="' . Route::url('stat-web', ['controller' => 'Statistic']) . '?module=' . $mod . '">' . $mod . '</a></li>'; if ($module == $mod) { foreach ($interfaces as $if) { $moduleStr .= '<li> <a href="' . Route::url('stat-web', ['controller' => 'Statistic']) . '?module=' . $mod . '&interface=' . $if . '">' . $if . '</a></li>'; } } } if (Cache::$lastFailedIpArray) { $errorMsg = '<strong>无法从以下数据源获取数据:</strong>'; foreach (Cache::$lastFailedIpArray as $ip) { $errorMsg .= $ip . '::' . Config::load('statServer')->get('providerPort') . ' '; } } $this->template->set('content', View::factory('statistic/index', ['errorMsg' => $errorMsg, 'date' => $date, 'module' => $module, 'interface' => $interface, 'interfaceName' => $interfaceName, 'moduleStr' => $moduleStr, 'successSeriesData' => $successSeriesData, 'failSeriesData' => $failSeriesData, 'successTimeSeriesData' => $successTimeSeriesData, 'failTimeSeriesData' => $failTimeSeriesData, 'tableData' => $tableData, 'dateBtnStr' => $dateBtnStr])); }