Пример #1
0
 /**
  * 缺省动作
  */
 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>&nbsp;&nbsp;<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]));
 }
Пример #2
0
 /**
  * 每个请求层,最终被调用的方法
  *
  * @return mixed
  */
 public function handle()
 {
     Base::getLog()->debug(__METHOD__ . ' handle main flow - start');
     if (!Route::exists('default')) {
         Base::getLog()->debug(__METHOD__ . ' set default route');
         Route::set('default', '(<controller>(/<action>(/<id>)))')->defaults(['controller' => 'Site', 'action' => 'index']);
     }
     $this->flow->contexts['uri'] = Url::detectUri();
     Base::getLog()->debug(__METHOD__ . ' handle main flow - end');
 }
Пример #3
0
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>
Пример #4
0
 /**
  * 测试[Route::exists()]
  */
 public function testExists()
 {
     $this->assertTrue(Route::exists('test'));
 }
Пример #5
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     $this->routeRegex = Route::compile($this->uri, $this->regex);
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function compile($uri, array $regex = null)
 {
     return BaseRoute::compile($uri, $regex);
 }
Пример #7
0
 /**
  * 根据指定的路由返回URL,等同于下面的代码:
  *
  *     echo URL::site(Route::get($name)->uri($params), $protocol);
  *
  * @param  string $name     路由名
  * @param  array  $params   URI参数
  * @param  mixed  $protocol 协议字符串、布尔值、等等
  * @return string
  */
 public static function url($name, array $params = null, $protocol = null)
 {
     $route = Route::get($name);
     return $route->isExternal() ? $route->uri($params) : Url::site($route->uri($params), $protocol);
 }
Пример #8
0
<?php

use tourze\Base\Config;
use tourze\Route\Route;
use tourze\StatServer\Cache;
use tourze\View\View;
if (is_file(__DIR__ . '/vendor/autoload.php')) {
    require_once __DIR__ . '/vendor/autoload.php';
}
ini_set('display_errors', 'on');
if (!defined('ROOT_PATH')) {
    define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
}
if (!defined('WEB_PATH')) {
    define('WEB_PATH', ROOT_PATH . 'web' . DIRECTORY_SEPARATOR);
}
Config::addPath(ROOT_PATH . 'config' . DIRECTORY_SEPARATOR);
View::addPath(ROOT_PATH . 'view' . DIRECTORY_SEPARATOR);
Cache::$serverIpList = Config::load('statServer')->get('serverIpList');
// 指定控制器命名空间
Route::$defaultNamespace = '\\tourze\\StatServer\\Controller\\';
Route::set('stat-web', '(<controller>(/<action>(/<id>)))')->defaults(['controller' => 'Main', 'action' => 'index']);
// 创建类别名
@class_alias('\\tourze\\StatServer\\Protocol\\Statistic', '\\Workerman\\Protocols\\Statistic');
Пример #9
0
 /**
  * 解析请求,查找路由
  *
  * @param  Request $request Request
  * @param  Route[] $routes  Route
  * @return array
  */
 public static function process(Request $request, $routes = null)
 {
     Base::getLog()->debug(__METHOD__ . ' process request and find the route');
     $routes = empty($routes) ? Route::all() : $routes;
     Base::getLog()->debug(__METHOD__ . ' get route list for process route', ['routes' => array_keys($routes)]);
     $params = null;
     foreach ($routes as $name => $route) {
         Base::getLog()->debug(__METHOD__ . ' check route', ['name' => $name, 'method' => $request->method]);
         /* @var $route Entry */
         if ($params = $route->matches($request->uri, $request->method)) {
             Base::getLog()->debug(__METHOD__ . ' matched route found', ['name' => $name, 'params' => $params]);
             return ['params' => $params, 'route' => $route];
         }
     }
     return null;
 }
Пример #10
0
 /**
  * 默认动作
  */
 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>&nbsp;&nbsp;<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') . '&nbsp;';
         }
     }
     $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]));
 }