| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace Elastica\Node;
- use Elastica\Node as BaseNode;
- /**
- * Elastica cluster node object.
- *
- * @author Nicolas Ruflin <spam@ruflin.com>
- *
- * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-status.html
- */
- class Stats
- {
- /**
- * Response.
- *
- * @var \Elastica\Response Response object
- */
- protected $_response;
- /**
- * Stats data.
- *
- * @var array stats data
- */
- protected $_data = [];
- /**
- * Node.
- *
- * @var \Elastica\Node Node object
- */
- protected $_node;
- /**
- * 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()
- {
- $endpoint = new \Elasticsearch\Endpoints\Cluster\Nodes\Stats();
- $endpoint->setNodeID($this->getNode()->getName());
- $this->_response = $this->getNode()->getClient()->requestEndpoint($endpoint);
- $data = $this->getResponse()->getData();
- $this->_data = reset($data['nodes']);
- }
- }
|