Stats.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace Elasticsearch\Endpoints\Cluster\Nodes;
  3. /**
  4. * Class Stats
  5. *
  6. * @category Elasticsearch
  7. * @package Elasticsearch\Endpoints\Cluster\Nodes
  8. * @author Zachary Tong <zach@elastic.co>
  9. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
  10. * @link http://elastic.co
  11. */
  12. class Stats extends AbstractNodesEndpoint
  13. {
  14. // Limit the information returned to the specified metrics
  15. private $metric;
  16. // Limit the information returned for `indices` metric to the specific index metrics. Isn&#039;t used if `indices` (or `all`) metric isn&#039;t specified.
  17. private $indexMetric;
  18. /**
  19. * @param $metric
  20. *
  21. * @return $this
  22. */
  23. public function setMetric($metric)
  24. {
  25. if (isset($metric) !== true) {
  26. return $this;
  27. }
  28. if (is_array($metric) === true) {
  29. $metric = implode(",", $metric);
  30. }
  31. $this->metric = $metric;
  32. return $this;
  33. }
  34. /**
  35. * @param $indexMetric
  36. *
  37. * @return $this
  38. */
  39. public function setIndexMetric($indexMetric)
  40. {
  41. if (isset($indexMetric) !== true) {
  42. return $this;
  43. }
  44. if (is_array($indexMetric) === true) {
  45. $indexMetric = implode(",", $indexMetric);
  46. }
  47. $this->indexMetric = $indexMetric;
  48. return $this;
  49. }
  50. /**
  51. * @return string
  52. */
  53. public function getURI()
  54. {
  55. $metric = $this->metric;
  56. $index_metric = $this->indexMetric;
  57. $node_id = $this->nodeID;
  58. $uri = "/_nodes/stats";
  59. if (isset($node_id) === true && isset($metric) === true && isset($index_metric) === true) {
  60. $uri = "/_nodes/$node_id/stats/$metric/$index_metric";
  61. } elseif (isset($metric) === true && isset($index_metric) === true) {
  62. $uri = "/_nodes/stats/$metric/$index_metric";
  63. } elseif (isset($node_id) === true && isset($metric) === true) {
  64. $uri = "/_nodes/$node_id/stats/$metric";
  65. } elseif (isset($metric) === true) {
  66. $uri = "/_nodes/stats/$metric";
  67. } elseif (isset($node_id) === true) {
  68. $uri = "/_nodes/$node_id/stats";
  69. }
  70. return $uri;
  71. }
  72. /**
  73. * @return string[]
  74. */
  75. public function getParamWhitelist()
  76. {
  77. return array(
  78. 'completion_fields',
  79. 'fielddata_fields',
  80. 'fields',
  81. 'groups',
  82. 'human',
  83. 'level',
  84. 'types',
  85. 'include_segment_file_sizes',
  86. );
  87. }
  88. /**
  89. * @return string
  90. */
  91. public function getMethod()
  92. {
  93. return 'GET';
  94. }
  95. }