PHP code example of tray-labs / laravel-influxdb
1. Go to this page and download the library: Download tray-labs/laravel-influxdb library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tray-labs / laravel-influxdb example snippets
'providers' => [
TrayLabs\InfluxDB\Providers\ServiceProvider::class,
]
'aliases' => [
'InfluxDB' => TrayLabs\InfluxDB\Facades\InfluxDB::class,
]
$app->configure('InfluxDB');
$app->register(TrayLabs\InfluxDB\Providers\LumenServiceProvider::class);
$app->alias('InfluxDB', TrayLabs\InfluxDB\Facades\InfluxDB::class);
use InfluxDB2\Point;
$writeApi = InfluxDB::createWriteApi();
$point = Point::measurement('test_metric')
->addTag('host', 'server01')
->addTag('region', 'us-west')
->addField('cpucount', 10)
->time(microtime(true));
$writeApi->write($point);
$writeApi->close();
$queryApi = InfluxDB::createQueryApi();
$result = $queryApi->query(
'from(bucket:"my-bucket") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "test_metric")'
);
foreach ($result as $table) {
foreach ($table->records as $record) {
echo $record->getField() . ': ' . $record->getValue() . PHP_EOL;
}
}
sh
php artisan vendor:publish