2015-06-03 04:30:57 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Graphite;
|
|
|
|
|
|
|
|
|
|
use Icinga\Module\Graphite\GraphTemplate;
|
|
|
|
|
use Icinga\Module\Graphite\GraphiteQuery;
|
|
|
|
|
|
2015-06-25 09:30:42 -04:00
|
|
|
/**
|
|
|
|
|
* Graphite web app
|
|
|
|
|
*
|
|
|
|
|
* Simple class, start point for all your queries
|
|
|
|
|
*/
|
2015-06-03 04:30:57 -04:00
|
|
|
class GraphiteWeb
|
|
|
|
|
{
|
2015-06-25 09:30:42 -04:00
|
|
|
/**
|
2017-08-31 08:34:32 -04:00
|
|
|
* HTTP interface to Graphite Web
|
2015-06-25 09:30:42 -04:00
|
|
|
*
|
2017-08-31 08:34:32 -04:00
|
|
|
* @var GraphiteWebClientInterface
|
2015-06-25 09:30:42 -04:00
|
|
|
*/
|
2017-08-31 08:34:32 -04:00
|
|
|
private $client;
|
2015-06-03 04:30:57 -04:00
|
|
|
|
2015-06-25 09:30:42 -04:00
|
|
|
/**
|
|
|
|
|
* Construct a new graphite webapp instance
|
|
|
|
|
*
|
2017-08-31 08:34:32 -04:00
|
|
|
* @param GraphiteWebClientInterface $client HTTP interface to Graphite Web
|
2015-06-25 09:30:42 -04:00
|
|
|
*/
|
2017-08-31 08:34:32 -04:00
|
|
|
public function __construct(GraphiteWebClientInterface $client)
|
2015-06-03 04:30:57 -04:00
|
|
|
{
|
2017-08-31 08:34:32 -04:00
|
|
|
$this->client = $client;
|
2015-06-03 04:30:57 -04:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 09:30:42 -04:00
|
|
|
/**
|
|
|
|
|
* Initiate a new query object
|
|
|
|
|
*
|
|
|
|
|
* @return GraphiteQuery
|
|
|
|
|
*/
|
2015-06-03 04:30:57 -04:00
|
|
|
public function select()
|
|
|
|
|
{
|
|
|
|
|
return new GraphiteQuery($this);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-25 09:30:42 -04:00
|
|
|
/**
|
2017-08-31 08:34:32 -04:00
|
|
|
* Get {@link client}
|
2015-06-25 09:30:42 -04:00
|
|
|
*
|
2017-08-31 08:34:32 -04:00
|
|
|
* @return GraphiteWebClientInterface
|
2015-06-25 09:30:42 -04:00
|
|
|
*/
|
2017-08-31 08:34:32 -04:00
|
|
|
public function getClient()
|
2015-06-03 04:30:57 -04:00
|
|
|
{
|
2017-08-31 08:34:32 -04:00
|
|
|
return $this->client;
|
2015-06-03 04:30:57 -04:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 09:30:42 -04:00
|
|
|
/**
|
|
|
|
|
* Retrieve a list of metrics fitting the given filter
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2015-06-03 04:30:57 -04:00
|
|
|
public function listMetrics($filter)
|
|
|
|
|
{
|
2017-08-31 08:34:32 -04:00
|
|
|
$res = json_decode($this->client->request('metrics/expand', ['query' => $filter]));
|
2015-06-03 04:30:57 -04:00
|
|
|
natsort($res->results);
|
|
|
|
|
return array_values($res->results);
|
|
|
|
|
}
|
|
|
|
|
}
|