influxdb-php icon indicating copy to clipboard operation
influxdb-php copied to clipboard

Select Retention Policy for Writes

Open bbczeuz opened this issue 9 years ago • 2 comments

I didn't yet find a way to select a retention policy when writing points (at least in 0.1 branch, as I'm using PHP 5.3 on RHEL6). Possible solution: Add rp parameter to HTTP request. I'll probably create a PR that adds this functionality via an additional (default=null) parameter to Client::write

bbczeuz avatar Aug 16 '16 15:08 bbczeuz

Since 1.3.1 , retention policy is included in InfluxDB\Database::writePoints. Unfortunately the Readme has not been updated to include examples.

    /**
     * Write points into InfluxDB using the current driver. This is the recommended method for inserting
     * data into InfluxDB.
     *
     * @param  Point[]     $points           Array of Point objects
     * @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 bool
     * @throws \InfluxDB\Exception
     */
    public function writePoints(array $points, $precision = self::PRECISION_NANOSECONDS, $retentionPolicy = null)

virgofx avatar Aug 16 '16 15:08 virgofx

can't get this to work with influxdb 1.4.2 and influxdb-php 1.14.5

> show retention policies
name     duration shardGroupDuration replicaN default
----     -------- ------------------ -------- -------
autogen  0s       168h0m0s           1        false
mypolicy 12h0m0s  1h0m0s             1        true
inf      0s       168h0m0s           1        false

so i do this:

$retentionPolicy = "inf";
$this->database->writePoints($this->points, InfluxDB\Database::PRECISION_NANOSECONDS, $retentionPolicy);

it will work, but the data point will end up in the default retention policy (mypolicy), not in inf

any ideas?

EugenNY avatar Mar 11 '18 16:03 EugenNY