-
Notifications
You must be signed in to change notification settings - Fork 795
/
ElasticaDataCollector.php
88 lines (74 loc) · 1.86 KB
/
ElasticaDataCollector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/*
* This file is part of the FOSElasticaBundle package.
*
* (c) FriendsOfSymfony <https://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\ElasticaBundle\DataCollector;
use FOS\ElasticaBundle\Logger\ElasticaLogger;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
/**
* Data collector collecting elastica statistics.
*
* @author Gordon Franke <info@nevalon.de>
*/
class ElasticaDataCollector extends DataCollector
{
protected ElasticaLogger $logger;
public function __construct(ElasticaLogger $logger)
{
$this->logger = $logger;
}
/**
* @return void
*/
public function collect(Request $request, Response $response, ?\Throwable $exception = null)
{
$this->data['nb_queries'] = $this->logger->getNbQueries();
$this->data['queries'] = $this->logger->getQueries();
}
public function getQueryCount()
{
return $this->data['nb_queries'];
}
public function getQueries()
{
return $this->data['queries'];
}
/**
* @return int
*/
public function getTime()
{
$time = 0;
foreach ($this->data['queries'] as $query) {
$time += $query['engineMS'];
}
return $time;
}
/**
* @return int
*/
public function getExecutionTime()
{
$time = 0;
foreach ($this->data['queries'] as $query) {
$time += $query['executionMS'];
}
return $time;
}
public function getName(): string
{
return 'elastica';
}
public function reset(): void
{
$this->logger->reset();
$this->data = [];
}
}