Exemple #1
0
 public function run($logId, $tag)
 {
     $this->controller->loadData($tag);
     $timings = $this->panel->calculateTimings();
     ArrayHelper::multisort($timings, 3, SORT_DESC);
     if (!isset($timings[$logId])) {
         throw new HttpException(404, 'Log message not found.');
     }
     $message = $timings[$logId][1];
     if (($pos = mb_strpos($message, "#")) !== false) {
         $url = mb_substr($message, 0, $pos);
         $body = mb_substr($message, $pos + 1);
     } else {
         $url = $message;
         $body = null;
     }
     list($dbname, $action) = explode('.', $url);
     /* @var $db Database */
     $db = Yii::$app->get($this->com)->getDatabase($dbname);
     $time = microtime(true);
     switch ($action) {
         case 'findAll':
             $docs = $db->getSearch()->setLimit(3)->setQuery($body)->search();
             $result = '<strong>Estimated Matched: </strong>' . $db->getLastCount();
             foreach ($docs as $doc) {
                 $result .= '<br/>' . $doc->rank() . '. (' . $doc->percent() . '%)';
                 $result .= "<br/>" . Json::encode($doc->getFields(), 448) . "\n";
             }
             if ($db->getLastCount() > 3) {
                 $result .= '<br/> ... other ' . ($db->getLastCount() - 3) . ' results ...';
             }
             break;
         case 'findOne':
             $docs = $db->getSearch()->setLimit(1)->setQuery($body)->search();
             if (count($docs) === 0) {
                 $result = '<span class="label label-danger">no found</span>';
             } else {
                 $result = "<br/>\n" . Json::encode($docs[0]->getFields(), 448);
             }
             break;
         case 'count':
             $count = $db->getSearch()->setQuery($body)->count();
             $result = '<strong>Estimated Matched: </strong>' . $count;
             break;
         default:
             throw new NotSupportedException("Action '{$action}' is not supported by xunsearch.");
     }
     $result = '<strong>DB Total: </strong>' . $db->getDbTotal() . '<br/>' . '<strong>Parsed Query: </strong>' . $db->getQuery() . '<br/>' . $result;
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ['time' => sprintf('%.1f ms', (microtime(true) - $time) * 1000), 'result' => $result];
 }
Exemple #2
0
 public function run($logId, $tag)
 {
     $this->controller->loadData($tag);
     $timings = $this->panel->calculateTimings();
     ArrayHelper::multisort($timings, 3, SORT_DESC);
     if (!isset($timings[$logId])) {
         throw new HttpException(404, 'Log message not found.');
     }
     $message = $timings[$logId][1];
     if (($pos = mb_strpos($message, "#")) !== false) {
         $url = mb_substr($message, 0, $pos);
         $body = mb_substr($message, $pos + 1);
     } else {
         $url = $message;
         $body = null;
     }
     $method = mb_substr($url, 0, $pos = mb_strpos($url, ' '));
     $url = mb_substr($url, $pos + 1);
     $options = ['pretty' => true];
     /* @var $db Connection */
     $db = \Yii::$app->get($this->db);
     $time = microtime(true);
     switch ($method) {
         case 'GET':
             $result = $db->get($url, $options, $body, true);
             break;
         case 'POST':
             $result = $db->post($url, $options, $body, true);
             break;
         case 'PUT':
             $result = $db->put($url, $options, $body, true);
             break;
         case 'DELETE':
             $result = $db->delete($url, $options, $body, true);
             break;
         case 'HEAD':
             $result = $db->head($url, $options, $body);
             break;
         default:
             throw new NotSupportedException("Request method '{$method}' is not supported by elasticsearch.");
     }
     $time = microtime(true) - $time;
     if ($result === true) {
         $result = '<span class="label label-success">success</span>';
     } elseif ($result === false) {
         $result = '<span class="label label-danger">no success</span>';
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ['time' => sprintf('%.1f ms', $time * 1000), 'result' => $result];
 }
 /**
  * @param $logId
  * @param $tag
  * @return array
  * @throws HttpException
  * @throws NotSupportedException
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\web\NotFoundHttpException
  */
 public function run($logId, $tag)
 {
     $this->controller->loadData($tag);
     $timings = $this->panel->calculateTimings();
     ArrayHelper::multisort($timings, 3, SORT_DESC);
     if (!isset($timings[$logId])) {
         throw new HttpException(404, 'Log message not found.');
     }
     $message = $timings[$logId][1];
     if (($pos = mb_strpos($message, '#')) !== false) {
         $url = mb_substr($message, 0, $pos);
         $body = mb_substr($message, $pos + 1);
     } else {
         $url = $message;
         $body = null;
     }
     $method = mb_substr($url, 0, $pos = mb_strpos($url, ' '));
     $url = mb_substr($url, $pos + 1);
     parse_str($body, $options);
     /* @var $db Connection */
     $db = \Yii::$app->get($this->db);
     $time = microtime(true);
     switch ($method) {
         case 'GET':
             $result = $db->get($url, $options, $body, true);
             break;
         case 'POST':
             $result = $db->post($url, $options, $body, true);
             break;
         case 'PUT':
             $result = $db->put($url, $options, $body, true);
             break;
         case 'DELETE':
             $result = $db->delete($url, $options, $body, true);
             break;
         case 'HEAD':
             $result = $db->head($url, $options, $body);
             break;
         default:
             throw new NotSupportedException("Request method '{$method}' is not supported by HiArt.");
     }
     $time = microtime(true) - $time;
     $now = microtime(true);
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ['time' => date('H:i:s.', $now) . sprintf('%03d', (int) (($now - (int) $now) * 1000)), 'duration' => sprintf('%.1f ms', $time * 1000), 'result' => $result];
 }