mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* Removed unsed `use` statemment * Moved helper http url composer to `GuzzleAdapter` (responsibility) * Removed unused `clearTimePrecision` method * Updated composer
73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace InfluxDB;
|
|
|
|
use InfluxDb\Adapter\QueryableInterface;
|
|
|
|
/**
|
|
* Client to manage request at InfluxDB
|
|
*/
|
|
class Client
|
|
{
|
|
private $adapter;
|
|
|
|
public function __construct(Adapter\AdapterInterface $adapter)
|
|
{
|
|
$this->adapter = $adapter;
|
|
return $this;
|
|
}
|
|
|
|
public function getAdapter()
|
|
{
|
|
return $this->adapter;
|
|
}
|
|
|
|
public function mark($name, array $values = [])
|
|
{
|
|
$data = $name;
|
|
if (!is_array($name)) {
|
|
$data =[];
|
|
|
|
$data['points'][0]['measurement'] = $name;
|
|
$data['points'][0]['fields'] = $values;
|
|
}
|
|
|
|
return $this->getAdapter()->send($data);
|
|
}
|
|
|
|
public function query($query)
|
|
{
|
|
if (!($this->getAdapter() instanceOf QueryableInterface)) {
|
|
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
|
|
}
|
|
|
|
$return = $this->getAdapter()->query($query);
|
|
|
|
return $return;
|
|
}
|
|
|
|
public function getDatabases()
|
|
{
|
|
if (!($this->getAdapter() instanceOf QueryableInterface)) {
|
|
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
|
|
}
|
|
return $this->getAdapter()->query("show databases");
|
|
}
|
|
|
|
public function createDatabase($name)
|
|
{
|
|
if (!($this->getAdapter() instanceOf QueryableInterface)) {
|
|
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
|
|
}
|
|
return $this->getAdapter()->query("create database \"{$name}\"");
|
|
}
|
|
|
|
public function deleteDatabase($name)
|
|
{
|
|
if (!($this->getAdapter() instanceOf QueryableInterface)) {
|
|
throw new \BadMethodCallException("You can query the database only if the adapter supports it!");
|
|
}
|
|
return $this->getAdapter()->query("drop database \"{$name}\"");
|
|
}
|
|
}
|