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