icingaweb2-module-graphite/library/Graphite/GraphiteWeb.php

64 lines
1.3 KiB
PHP
Raw Permalink Normal View History

<?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
*/
class GraphiteWeb
{
2015-06-25 09:30:42 -04:00
/**
* HTTP interface to Graphite Web
2015-06-25 09:30:42 -04:00
*
* @var GraphiteWebClientInterface
2015-06-25 09:30:42 -04:00
*/
private $client;
2015-06-25 09:30:42 -04:00
/**
* Construct a new graphite webapp instance
*
* @param GraphiteWebClientInterface $client HTTP interface to Graphite Web
2015-06-25 09:30:42 -04:00
*/
public function __construct(GraphiteWebClientInterface $client)
{
$this->client = $client;
}
2015-06-25 09:30:42 -04:00
/**
* Initiate a new query object
*
* @return GraphiteQuery
*/
public function select()
{
return new GraphiteQuery($this);
}
2015-06-25 09:30:42 -04:00
/**
* Get {@link client}
2015-06-25 09:30:42 -04:00
*
* @return GraphiteWebClientInterface
2015-06-25 09:30:42 -04:00
*/
public function getClient()
{
return $this->client;
}
2015-06-25 09:30:42 -04:00
/**
* Retrieve a list of metrics fitting the given filter
*
* @return array
*/
public function listMetrics($filter)
{
$res = json_decode($this->client->request('metrics/expand', ['query' => $filter]));
natsort($res->results);
return array_values($res->results);
}
}