mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
Merge branch 'release/0.1.2'
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
|
||||
|
||||
@@ -53,6 +53,31 @@ $client = new Client();
|
||||
$client->setAdapter($adapter);
|
||||
```
|
||||
|
||||
### Create your client with the factory method
|
||||
|
||||
Effectively the client creation is not so simple, for that
|
||||
reason you can you the factory method provided with the library.
|
||||
|
||||
```
|
||||
$options = [
|
||||
"adapter" => [
|
||||
"name" => "InfluxDB\\Adapter\\GuzzleAdapter",
|
||||
"options" => [
|
||||
// guzzle options
|
||||
],
|
||||
],
|
||||
"options" => [
|
||||
"host" => "my.influx.domain.tld",
|
||||
],
|
||||
];
|
||||
$client = \InfluxDB\ClientFactory::create($options);
|
||||
|
||||
$client->mark("error.404", ["page" => "/a-missing-page"]);
|
||||
```
|
||||
|
||||
Of course you can always use the DiC or your service manager in
|
||||
order to create a valid client instance.
|
||||
|
||||
### Time Precision write/read queries
|
||||
|
||||
You can set the `time_precision` for query query
|
||||
@@ -110,6 +135,18 @@ array(1) {
|
||||
}
|
||||
```
|
||||
|
||||
## Database operations
|
||||
|
||||
You can create, list or destroy databases using dedicated methods
|
||||
|
||||
```php
|
||||
$client->getDatabases(); // list all databases
|
||||
$client->createDatabase("my.name"); // create a new database with name "my.name"
|
||||
$client->deleteDatabase("my.name"); // delete an existing database with name "my.name"
|
||||
```
|
||||
|
||||
Actually only queryable adapters can handle databases (implements the `QueryableInterface`)
|
||||
|
||||
## Install it
|
||||
|
||||
Just use composer
|
||||
|
||||
+4
-1
@@ -3,7 +3,10 @@
|
||||
"license": "MIT",
|
||||
"description": "Send your app metrics to InfluxDB",
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "~4"
|
||||
"guzzlehttp/guzzle": "~4",
|
||||
"zendframework/zend-stdlib": "~2",
|
||||
"zendframework/zend-filter": "~2",
|
||||
"zendframework/zend-servicemanager": "~2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "2.*",
|
||||
|
||||
Generated
+150
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "17fa2295e2cd007935278098484ab7cc",
|
||||
"hash": "5647460e792745752274202f2289a0cc",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
@@ -123,6 +123,155 @@
|
||||
"stream"
|
||||
],
|
||||
"time": "2014-08-17 21:15:53"
|
||||
},
|
||||
{
|
||||
"name": "zendframework/zend-filter",
|
||||
"version": "2.3.1",
|
||||
"target-dir": "Zend/Filter",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zendframework/Component_ZendFilter.git",
|
||||
"reference": "1889b7aa499beccadac770780a73e1a40e0f8a53"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zendframework/Component_ZendFilter/zipball/1889b7aa499beccadac770780a73e1a40e0f8a53",
|
||||
"reference": "1889b7aa499beccadac770780a73e1a40e0f8a53",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.23",
|
||||
"zendframework/zend-stdlib": "self.version"
|
||||
},
|
||||
"require-dev": {
|
||||
"zendframework/zend-crypt": "self.version",
|
||||
"zendframework/zend-servicemanager": "self.version",
|
||||
"zendframework/zend-uri": "self.version"
|
||||
},
|
||||
"suggest": {
|
||||
"zendframework/zend-crypt": "Zend\\Crypt component",
|
||||
"zendframework/zend-i18n": "Zend\\I18n component",
|
||||
"zendframework/zend-servicemanager": "Zend\\ServiceManager component",
|
||||
"zendframework/zend-uri": "Zend\\Uri component for UriNormalize filter"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.3-dev",
|
||||
"dev-develop": "2.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Zend\\Filter\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"description": "provides a set of commonly needed data filters",
|
||||
"keywords": [
|
||||
"filter",
|
||||
"zf2"
|
||||
],
|
||||
"time": "2014-04-15 15:28:47"
|
||||
},
|
||||
{
|
||||
"name": "zendframework/zend-servicemanager",
|
||||
"version": "2.3.1",
|
||||
"target-dir": "Zend/ServiceManager",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zendframework/Component_ZendServiceManager.git",
|
||||
"reference": "652ab6e142b7afd1eede8f0f33b47d2599786c84"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zendframework/Component_ZendServiceManager/zipball/652ab6e142b7afd1eede8f0f33b47d2599786c84",
|
||||
"reference": "652ab6e142b7afd1eede8f0f33b47d2599786c84",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.23"
|
||||
},
|
||||
"require-dev": {
|
||||
"zendframework/zend-di": "self.version"
|
||||
},
|
||||
"suggest": {
|
||||
"zendframework/zend-di": "Zend\\Di component"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.3-dev",
|
||||
"dev-develop": "2.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Zend\\ServiceManager\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"keywords": [
|
||||
"servicemanager",
|
||||
"zf2"
|
||||
],
|
||||
"time": "2014-04-15 15:28:43"
|
||||
},
|
||||
{
|
||||
"name": "zendframework/zend-stdlib",
|
||||
"version": "2.3.1",
|
||||
"target-dir": "Zend/Stdlib",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zendframework/Component_ZendStdlib.git",
|
||||
"reference": "c1f4830018b5d4f034d32fa01a9e17ea176f56f6"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zendframework/Component_ZendStdlib/zipball/c1f4830018b5d4f034d32fa01a9e17ea176f56f6",
|
||||
"reference": "c1f4830018b5d4f034d32fa01a9e17ea176f56f6",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.23"
|
||||
},
|
||||
"require-dev": {
|
||||
"zendframework/zend-eventmanager": "self.version",
|
||||
"zendframework/zend-serializer": "self.version",
|
||||
"zendframework/zend-servicemanager": "self.version"
|
||||
},
|
||||
"suggest": {
|
||||
"zendframework/zend-eventmanager": "To support aggregate hydrator usage",
|
||||
"zendframework/zend-serializer": "Zend\\Serializer component",
|
||||
"zendframework/zend-servicemanager": "To support hydrator plugin manager usage"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.3-dev",
|
||||
"dev-develop": "2.4-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Zend\\Stdlib\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"keywords": [
|
||||
"stdlib",
|
||||
"zf2"
|
||||
],
|
||||
"time": "2014-04-15 15:28:48"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
|
||||
@@ -17,6 +17,11 @@ class GuzzleAdapter implements AdapterInterface, QueryableInterface
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
public function send($message, $timePrecision = false)
|
||||
{
|
||||
$httpMessage = [
|
||||
|
||||
@@ -12,6 +12,11 @@ class UdpAdapter implements AdapterInterface
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Handle timePrecision parameter
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace InfluxDB;
|
||||
|
||||
use Zend\Stdlib\Hydrator\ClassMethods;
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
|
||||
abstract class ClientFactory
|
||||
{
|
||||
private static $options = [
|
||||
"adapter" => [
|
||||
"name" => false,
|
||||
"options" => [],
|
||||
],
|
||||
"options" => [],
|
||||
];
|
||||
|
||||
public static function create(array $options)
|
||||
{
|
||||
$options = array_replace_recursive(self::$options, $options);
|
||||
|
||||
$adapterName = $options["adapter"]["name"];
|
||||
if (!class_exists($adapterName)) {
|
||||
throw new \InvalidArgumentException("Missing class: {$adapterName}");
|
||||
}
|
||||
$adapterOptions = new Options();
|
||||
|
||||
$hydrator = new ClassMethods();
|
||||
$hydrator->hydrate($options["options"], $adapterOptions);
|
||||
|
||||
$adapter = null;
|
||||
switch ($adapterName) {
|
||||
case 'InfluxDB\\Adapter\\UdpAdapter':
|
||||
$adapter = new $adapterName($adapterOptions);
|
||||
break;
|
||||
case 'InfluxDB\\Adapter\\GuzzleAdapter':
|
||||
$adapter = new $adapterName(new GuzzleClient($options["adapter"]["options"]), $adapterOptions);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException("Missing adapter {$adapter}");
|
||||
}
|
||||
|
||||
$client = new Client();
|
||||
$client->setAdapter($adapter);
|
||||
|
||||
return $client;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace InfluxDB;
|
||||
|
||||
class ClientFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @group factory
|
||||
* @group udp
|
||||
*/
|
||||
public function testCreateUdpClient()
|
||||
{
|
||||
$options = [
|
||||
"adapter" => [
|
||||
"name" => "InfluxDB\\Adapter\\UdpAdapter",
|
||||
],
|
||||
"options" => [
|
||||
"host" => "127.0.0.1",
|
||||
"username" => "user",
|
||||
"password" => "pass",
|
||||
],
|
||||
];
|
||||
|
||||
$client = ClientFactory::create($options);
|
||||
$this->assertInstanceOf("InfluxDB\\Client", $client);
|
||||
|
||||
$this->assertInstanceOf("InfluxDB\\Adapter\\UdpAdapter", $client->getAdapter());
|
||||
$this->assertEquals("127.0.0.1", $client->getAdapter()->getOptions()->getHost());
|
||||
$this->assertEquals("user", $client->getAdapter()->getOptions()->getUsername());
|
||||
$this->assertEquals("pass", $client->getAdapter()->getOptions()->getPassword());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group factory
|
||||
* @group tcp
|
||||
*/
|
||||
public function testCreateTcpClient()
|
||||
{
|
||||
$options = [
|
||||
"adapter" => [
|
||||
"name" => "InfluxDB\\Adapter\\GuzzleAdapter",
|
||||
],
|
||||
"options" => [
|
||||
"host" => "127.0.0.1",
|
||||
"username" => "user",
|
||||
"password" => "pass",
|
||||
],
|
||||
];
|
||||
|
||||
$client = ClientFactory::create($options);
|
||||
$this->assertInstanceOf("InfluxDB\\Client", $client);
|
||||
|
||||
$this->assertInstanceOf("InfluxDB\\Adapter\\GuzzleAdapter", $client->getAdapter());
|
||||
$this->assertEquals("127.0.0.1", $client->getAdapter()->getOptions()->getHost());
|
||||
$this->assertEquals("user", $client->getAdapter()->getOptions()->getUsername());
|
||||
$this->assertEquals("pass", $client->getAdapter()->getOptions()->getPassword());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user