blob: 1af94b074edb8b786867b9435abeec4b1aa53944 (
plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
<?php
namespace Elastica\Node;
use Elastica\Node as BaseNode;
use Elastica\Request;
/**
* Elastica cluster node object.
*
* @author Nicolas Ruflin <spam@ruflin.com>
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-status.html
*/
class Stats
{
/**
* Response.
*
* @var \Elastica\Response Response object
*/
protected $_response = null;
/**
* Stats data.
*
* @var array stats data
*/
protected $_data = array();
/**
* Node.
*
* @var \Elastica\Node Node object
*/
protected $_node = null;
/**
* Create new stats for node.
*
* @param \Elastica\Node $node Elastica node object
*/
public function __construct(BaseNode $node)
{
$this->_node = $node;
$this->refresh();
}
/**
* Returns all node stats as array based on the arguments.
*
* Several arguments can be use
* get('index', 'test', 'example')
*
* @return array Node stats for the given field or null if not found
*/
public function get()
{
$data = $this->getData();
foreach (func_get_args() as $arg) {
if (isset($data[$arg])) {
$data = $data[$arg];
} else {
return;
}
}
return $data;
}
/**
* Returns all stats data.
*
* @return array Data array
*/
public function getData()
{
return $this->_data;
}
/**
* Returns node object.
*
* @return \Elastica\Node Node object
*/
public function getNode()
{
return $this->_node;
}
/**
* Returns response object.
*
* @return \Elastica\Response Response object
*/
public function getResponse()
{
return $this->_response;
}
/**
* Reloads all nodes information. Has to be called if informations changed.
*
* @return \Elastica\Response Response object
*/
public function refresh()
{
$path = '_nodes/'.$this->getNode()->getName().'/stats';
$this->_response = $this->getNode()->getClient()->request($path, Request::GET);
$data = $this->getResponse()->getData();
$this->_data = reset($data['nodes']);
}
}
|