示例#1
0
 public function onGet()
 {
     $filter = Log\QueryFilter::create($this->getParameters());
     $condition = $filter->getCondition('log');
     $expression = $condition->getExpression($this->connection->getDatabasePlatform());
     // build data structure
     $fromDate = $filter->getFrom();
     $toDate = $filter->getTo();
     $diff = $toDate->getTimestamp() - $fromDate->getTimestamp();
     $data = [];
     $labels = [];
     while ($fromDate <= $toDate) {
         $data[$fromDate->format('Y-m-d')] = 0;
         $labels[] = $fromDate->format($diff < 2419200 ? 'D' : 'Y-m-d');
         $fromDate->add(new \DateInterval('P1D'));
     }
     // fill values
     $sql = '  SELECT COUNT(log.id) AS count,
                      DATE(log.date) AS date
                 FROM fusio_log log
                WHERE ' . $expression . '
             GROUP BY DATE(log.date)';
     $result = $this->connection->fetchAll($sql, $condition->getValues());
     foreach ($result as $row) {
         $data[$row['date']] = (int) $row['count'];
     }
     $this->setBody(array('labels' => $labels, 'data' => [array_values($data)], 'series' => ['Requests']));
 }
示例#2
0
 /**
  * Returns the GET response
  *
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doGet(Version $version)
 {
     $startIndex = $this->getParameter('startIndex', Validate::TYPE_INTEGER) ?: null;
     $filter = Log\QueryFilter::create($this->getParameters());
     $condition = $filter->getCondition();
     $table = $this->tableManager->getTable('Fusio\\Impl\\Backend\\Table\\Log');
     $table->setRestrictedFields(['header', 'body']);
     return array('totalItems' => $table->getCount($condition), 'startIndex' => $startIndex, 'entry' => $table->getAll($startIndex, null, 'id', Sql::SORT_DESC, $condition));
 }
示例#3
0
 public function onGet()
 {
     $filter = Log\QueryFilter::create($this->getParameters());
     $condition = $filter->getCondition('log');
     $expression = $condition->getExpression($this->connection->getDatabasePlatform());
     // get the most used routes and build data structure
     $sql = '    SELECT log.routeId
                   FROM fusio_log_error error
             INNER JOIN fusio_log log
                     ON log.id = error.logId
                  WHERE ' . $expression . '
                    AND log.routeId IS NOT NULL
               GROUP BY log.routeId
               ORDER BY COUNT(error.id) DESC
                  LIMIT 6';
     $result = $this->connection->fetchAll($sql, $condition->getValues());
     $routeIds = array();
     $data = [];
     $series = [];
     foreach ($result as $row) {
         $routeIds[] = $row['routeId'];
         $data[$row['routeId']] = [];
         $series[$row['routeId']] = null;
         $fromDate = clone $filter->getFrom();
         $toDate = clone $filter->getTo();
         while ($fromDate <= $toDate) {
             $data[$row['routeId']][$fromDate->format('Y-m-d')] = 0;
             $fromDate->add(new \DateInterval('P1D'));
         }
     }
     if (!empty($routeIds)) {
         $condition->in('log.routeId', $routeIds);
     }
     // fill data with values
     $expression = $condition->getExpression($this->connection->getDatabasePlatform());
     $sql = '    SELECT COUNT(error.id) AS count,
                        log.routeId,
                        routes.path,
                        DATE(log.date) AS date
                   FROM fusio_log_error error
             INNER JOIN fusio_log log
                     ON log.id = error.logId
             INNER JOIN fusio_routes routes
                     ON log.routeId = routes.id
                  WHERE ' . $expression . '
               GROUP BY DATE(log.date), log.routeId';
     $result = $this->connection->fetchAll($sql, $condition->getValues());
     foreach ($result as $row) {
         $series[$row['routeId']] = $row['path'];
         $data[$row['routeId']][$row['date']] = (int) $row['count'];
     }
     // build labels
     $fromDate = clone $filter->getFrom();
     $toDate = clone $filter->getTo();
     $diff = $toDate->getTimestamp() - $fromDate->getTimestamp();
     $labels = [];
     while ($fromDate <= $toDate) {
         $labels[] = $fromDate->format($diff < 2419200 ? 'D' : 'Y-m-d');
         $fromDate->add(new \DateInterval('P1D'));
     }
     // clean data structure
     $values = [];
     foreach ($data as $row) {
         $values[] = array_values($row);
     }
     $this->setBody(array('labels' => $labels, 'data' => array_values($values), 'series' => array_values($series)));
 }