vendor/shopware/elasticsearch/Profiler/DataCollector.php line 18

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Elasticsearch\Profiler;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpKernel\DataCollector\DataCollector as BaseDataCollector;
  6. class DataCollector extends BaseDataCollector
  7. {
  8.     private ClientProfiler $client;
  9.     public function __construct(ClientProfiler $client)
  10.     {
  11.         $this->client $client;
  12.     }
  13.     public function collect(Request $requestResponse $response, ?\Throwable $exception null): void
  14.     {
  15.         $this->data = [
  16.             'requests' => $this->client->getCalledRequests(),
  17.             'time' => 0,
  18.         ];
  19.         foreach ($this->client->getCalledRequests() as $calledRequest) {
  20.             $this->data['time'] += $calledRequest['time'];
  21.         }
  22.         $this->data['clusterInfo'] = $this->client->cluster()->health();
  23.         $this->data['indices'] = $this->client->cat()->indices();
  24.     }
  25.     public function getName(): string
  26.     {
  27.         return 'elasticsearch';
  28.     }
  29.     public function reset(): void
  30.     {
  31.         $this->data = [];
  32.         $this->client->resetRequests();
  33.     }
  34.     public function getTime(): float
  35.     {
  36.         $time 0;
  37.         foreach ($this->data['requests'] as $calledRequest) {
  38.             $time += $calledRequest['time'];
  39.         }
  40.         return (int) ($time 1000);
  41.     }
  42.     public function getRequestAmount(): int
  43.     {
  44.         return \count($this->data['requests']);
  45.     }
  46.     public function getRequests(): array
  47.     {
  48.         return $this->data['requests'];
  49.     }
  50.     public function getClusterInfo(): array
  51.     {
  52.         return $this->data['clusterInfo'];
  53.     }
  54.     public function getIndices(): array
  55.     {
  56.         return $this->data['indices'];
  57.     }
  58. }