mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
Merge branch 'release/0.1.1'
This commit is contained in:
@@ -53,6 +53,18 @@ $client = new Client();
|
||||
$client->setAdapter($adapter);
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
@@ -28,7 +28,7 @@ class ClientSpec extends ObjectBehavior
|
||||
"points" => [
|
||||
["Guccini", "Autogrill"]
|
||||
]
|
||||
]])->shouldBeCalledTimes(1);
|
||||
]], false)->shouldBeCalledTimes(1);
|
||||
|
||||
$this->mark("video.search", [
|
||||
"author" => "Guccini",
|
||||
@@ -36,6 +36,23 @@ class ClientSpec extends ObjectBehavior
|
||||
]);
|
||||
}
|
||||
|
||||
function it_should_send_data_with_time_precision(AdapterInterface $adapter)
|
||||
{
|
||||
$adapter->send([[
|
||||
"name" => "video.search",
|
||||
"columns" => ["time", "author", "title"],
|
||||
"points" => [
|
||||
["1410591552", "Guccini", "Autogrill"]
|
||||
]
|
||||
]], "s")->shouldBeCalledTimes(1);
|
||||
|
||||
$this->mark("video.search", [
|
||||
"time" => "1410591552",
|
||||
"author" => "Guccini",
|
||||
"title" => "Autogrill"
|
||||
], "s");
|
||||
}
|
||||
|
||||
function it_should_query_on_querable_adapter(GuzzleAdapter $adapter)
|
||||
{
|
||||
$this->setAdapter($adapter);
|
||||
|
||||
@@ -3,5 +3,5 @@ namespace InfluxDB\Adapter;
|
||||
|
||||
interface AdapterInterface
|
||||
{
|
||||
public function send($message);
|
||||
public function send($message, $timePrecision = false);
|
||||
}
|
||||
|
||||
@@ -17,13 +17,17 @@ class GuzzleAdapter implements AdapterInterface, QueryableInterface
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function send($message)
|
||||
public function send($message, $timePrecision = false)
|
||||
{
|
||||
$httpMessage = [
|
||||
"auth" => [$this->options->getUsername(), $this->options->getPassword()],
|
||||
"body" => json_encode($message)
|
||||
];
|
||||
|
||||
if ($timePrecision) {
|
||||
$httpMessage["query"]["time_precision"] = $timePrecision;
|
||||
}
|
||||
|
||||
$endpoint = $this->options->getHttpSeriesEndpoint();
|
||||
return $this->httpClient->post($endpoint, $httpMessage);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,10 @@ class UdpAdapter implements AdapterInterface
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function send($message)
|
||||
/**
|
||||
* @todo Handle timePrecision parameter
|
||||
*/
|
||||
public function send($message, $timePrecision = false)
|
||||
{
|
||||
$message = json_encode($message);
|
||||
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
|
||||
|
||||
@@ -20,14 +20,17 @@ class Client
|
||||
return $this->adapter;
|
||||
}
|
||||
|
||||
public function mark($name, array $values)
|
||||
public function mark($name, array $values, $timePrecision = false)
|
||||
{
|
||||
$data =[];
|
||||
|
||||
$timePrecision = $this->clearTimePrecision($timePrecision);
|
||||
|
||||
$data['name'] = $name;
|
||||
$data['columns'] = array_keys($values);
|
||||
$data['points'][] = array_values($values);
|
||||
|
||||
return $this->getAdapter()->send([$data]);
|
||||
return $this->getAdapter()->send([$data], $timePrecision);
|
||||
}
|
||||
|
||||
public function query($query, $timePrecision = false)
|
||||
|
||||
@@ -100,6 +100,21 @@ class ClientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals("tcp.test", $body[0]["name"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group tcp
|
||||
*/
|
||||
public function testGuzzleHttpWriteApiWithTimePrecision()
|
||||
{
|
||||
$this->object->mark("tcp.test", ["time" => 1410591552, "mark" => "element"], "s");
|
||||
|
||||
$body = $this->object->query("select mark from tcp.test", "ms");
|
||||
|
||||
$this->assertCount(1, $body[0]["points"]);
|
||||
$this->assertEquals("tcp.test", $body[0]["name"]);
|
||||
|
||||
$this->assertEquals("1410591552000", $body[0]["points"][0][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group udp
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user