InfluxDB\Database::writePoints PHP Method

writePoints() public method

Write points into InfluxDB using the current driver. This is the recommended method for inserting data into InfluxDB.
public writePoints ( array $points, string $precision = self::PRECISION_NANOSECONDS, string | null $retentionPolicy = null ) : boolean
$points array Array of Point objects
$precision string The timestamp precision (defaults to nanoseconds).
$retentionPolicy string | null 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 boolean
    public function writePoints(array $points, $precision = self::PRECISION_NANOSECONDS, $retentionPolicy = null)
    {
        $payload = array_map(function (Point $point) {
            return (string) $point;
        }, $points);
        return $this->writePayload($payload, $precision, $retentionPolicy);
    }

Usage Example

 public function testWritePointsInASingleCall()
 {
     $point1 = new Point('cpu_load_short', 0.64, array('host' => 'server01', 'region' => 'us-west'), array('cpucount' => 10), 1435222310);
     $point2 = new Point('cpu_load_short', 0.84);
     $payloadExpected = "{$point1}\n{$point2}";
     $this->mockClient->expects($this->once())->method('write')->with($this->equalTo($this->db->getName()), $this->equalTo($payloadExpected))->will($this->returnValue(true));
     $this->db->writePoints(array($point1, $point2));
 }
All Usage Examples Of InfluxDB\Database::writePoints