doclassif/laravel-influxdb2

一个旨在提供、设置和使用来自 influxdata/influxdb-client-php 库的服务的Laravel。

1.0.0 2024-09-09 14:16 UTC

This package is auto-updated.

Last update: 2024-09-09 14:19:49 UTC


README

```php
'providers' => [
//  ...
    Kali\InfluxDB\Providers\ServiceProvider::class,
]
```
```php
'aliases' => [
//  ...
    'InfluxDB' => Kali\InfluxDB\Facades\InfluxDB::class,
]
```
  • 定义环境变量以连接到InfluxDB
INFLUXDB_HOST=
INFLUXDB_PORT=
INFLUXDB_TOKEN=
INFLUXDB_BUCKET=
INFLUXDB_ORG=
  • 将此命令写入您的项目终端内
    php artisan vendor:publish
    
    

读取数据

<?php
use Kali\InfluxDB\Facades\InfluxDB;

// Get query client
$queryApi = InfluxDB::createQueryApi();

// Synchronously executes query and return result as unprocessed String
$result = $queryApi->queryRaw(
    "from(bucket: \"my-bucket\")
                |> range(start: 0)
                |> filter(fn: (r) => r[\"_measurement\"] == \"weather\"
                                 and r[\"_field\"] == \"temperature\"
                                 and r[\"location\"] == \"Sydney\")"
);

InfluxDB::close();

写入数据

<?php

$writeApi = InfluxDB::createWriteApi();

// create an array of points
$result = $writeApi->write([
    Point::measurement("blog_posts")
      ->addTag("post_id", $post->id)
      ->addField("likes", 6)
      ->addField("comments", 3)
      ->time(time())
]);

InfluxDB::close();