Ejemplo n.º 1
0
 /**
  * Write a payload into InfluxDB using the current driver. This method is similar to <tt>writePoints()</tt>,
  * except it takes a string payload instead of an array of Points. This is useful in the following situations:
  *
  *   1) Performing unique queries that may not conform to the current Point standard.
  *   2) Inserting very large set of points into a measurement where looping via array_map() actually
  *      hurts performance as the payload may be calculated in advance by caller.
  *
  * @param  string|array  $payload          InfluxDB payload (Or array of payloads) that conform to the Line syntax.
  * @param  string        $precision        The timestamp precision (defaults to nanoseconds).
  * @param  string|null   $retentionPolicy  Specifies an explicit retention policy to use when writing all points. If
  *                                         not set, the default retention period will be used. This is only
  *                                         applicable for the Guzzle driver. The UDP driver utilizes the endpoint
  *                                         configuration defined in the server's influxdb configuration file.
  * @return Observable
  * @throws \Rxnet\InfluxDB\Exception
  */
 public function writePayload($payload, $precision = self::PRECISION_NANOSECONDS, $retentionPolicy = null)
 {
     try {
         $parameters = ['url' => sprintf('write?db=%s&precision=%s', $this->name, $precision), 'database' => $this->name, 'method' => 'post'];
         if ($retentionPolicy !== null) {
             $parameters['url'] .= sprintf('&rp=%s', $retentionPolicy);
         }
         return $this->client->write($parameters, $payload);
     } catch (Exception $e) {
         throw new InfluxDBException($e->getMessage(), $e->getCode());
     }
 }
Ejemplo n.º 2
0
<?php

use EventLoop\EventLoop;
use Rxnet\InfluxDB\Client;
use Rxnet\InfluxDB\Database;
use Rxnet\InfluxDB\Point;
require __DIR__ . "/../../vendor/autoload.php";
$loop = EventLoop::getLoop();
$dsn = "udp+influxdb://127.0.0.1:4444/my_db";
// (database is ignored in UDP as its hardcoded in the server config)
$influx = Client::fromDSN($dsn);
$points = [new Point('temperature', 24, ['city' => 'Clermont-Ferrand', 'country' => 'FR'], [], time())];
$req = $influx->writePayload($points, Database::PRECISION_SECONDS);
$req->subscribeCallback(null, function () {
    printf("onError : Unable to send message\n");
}, function () {
    printf("onCompleted : Done\n");
}, new \Rx\Scheduler\EventLoopScheduler($loop));
$loop->run();