From 72b08569e92a8a20413baec2ca6e1cba53c1e300 Mon Sep 17 00:00:00 2001 From: Walter Dal Mut Date: Sun, 7 Jun 2015 13:03:06 +0200 Subject: [PATCH] Added test for direct messsages with HTTP client --- README.md | 38 ++++++++++++++++++++++------------- tests/InfluxDB/ClientTest.php | 30 +++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5d766d332..fc78d5743 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Send metrics to InfluxDB and query for any data. +**For InfluxDB v0.8 checkout branch 0.3** + ## Install it Just use composer @@ -34,6 +36,27 @@ $client->mark("app.search", [ ]); ``` +Or use InfluxDB direct messages + +```php +$client->mark([ + "database" => "mydb", + "tags" => [ + "dc" => "eu-west-1", + ], + "points" => [ + [ + "name" => "vm-serie", + "fields" => [ + "cpu" => 18.12, + "free" => 712423, + ], + ], + ] +]); +``` + + Retrieve existing points: ```php @@ -61,7 +84,7 @@ php -m | grep sockets If you don't have the `sockets` extension, you can proceed in two ways: - Recompile your PHP whith the `--enable-sockets` flag -- Or just compile the `sockets` extension extracting it from the PHP source. +- Or just compile the `sockets` extension extracting it from the PHP source. 1. Download the source relative to the PHP version that you on from [here](https://github.com/php/php-src/releases) 2. Enter in the `ext/sockets` directory 3. Issue a `phpize && ./configure && make -j && sudo make install` @@ -124,25 +147,12 @@ $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 - -```php -$client->mark("app.search", $points, "s"); //points contains "time" that is in seconds -``` - -```php -$client->query("select * from app.search", "s"); // retrieve points using seconds for time column -``` - ### Query InfluxDB You can query the time series database using the query method. ```php $influx->query("select * from mine"); -$influx->query("select * from mine", "s"); // with time_precision ``` You can query the database only if the adapter is queryable (implements diff --git a/tests/InfluxDB/ClientTest.php b/tests/InfluxDB/ClientTest.php index 5a498452a..744a6e1ef 100644 --- a/tests/InfluxDB/ClientTest.php +++ b/tests/InfluxDB/ClientTest.php @@ -97,6 +97,36 @@ class ClientTest extends \PHPUnit_Framework_TestCase $this->assertEquals("element", $body["results"][0]["series"][0]["values"][0][1]); } + /** + * @group tcp + */ + public function testWriteDirectMessages() + { + $this->object->mark([ + "database" => "tcp.test", + "tags" => [ + "dc" => "eu-west-1", + ], + "points" => [ + [ + "name" => "vm-serie", + "fields" => [ + "cpu" => 18.12, + "free" => 712423, + ], + ], + ] + ]); + + sleep(1); + + $body = $this->object->query("select * from \"vm-serie\""); + + $this->assertCount(1, $body["results"][0]["series"][0]["values"]); + $this->assertEquals("cpu", $body["results"][0]["series"][0]["columns"][1]); + $this->assertEquals(18.12, $body["results"][0]["series"][0]["values"][0][1]); + } + /** * @group udp */