A service made to provide, set up and use the library from influxdata influxphp in Laravel.
tray-labs/laravel-influxdb is a Laravel package for a service made to provide, set up and use the library from influxdata influxphp in laravel..
It currently has 73 GitHub stars and 186.003 downloads on Packagist (latest version v2.0.0).
Install it with composer require tray-labs/laravel-influxdb.
Discover more Laravel packages by tray-labs
or browse all Laravel packages to compare alternatives.
Last updated
A service made to provide, set up and use influxdb-client-php (InfluxDB 2.x) in Laravel.
composer require tray-labs/laravel-influxdb
Laravel: in config/app.php file. Laravel 5.5+ supports package discovery automatically, you should skip this step
'providers' => [
TrayLabs\InfluxDB\Providers\ServiceProvider::class,
]
'aliases' => [
'InfluxDB' => TrayLabs\InfluxDB\Facades\InfluxDB::class,
]
Lumen: in bootstrap/app.php file
$app->configure('InfluxDB');
$app->register(TrayLabs\InfluxDB\Providers\LumenServiceProvider::class);
$app->alias('InfluxDB', TrayLabs\InfluxDB\Facades\InfluxDB::class);
Define the env variables to connect to InfluxDB:
INFLUXDB_HOST=localhost
INFLUXDB_PORT=8086
INFLUXDB_TOKEN=my-token
INFLUXDB_ORG=my-org
INFLUXDB_BUCKET=my-bucket
INFLUXDB_SSL=false
INFLUXDB_VERIFYSSL=false
INFLUXDB_TIMEOUT=0
Publish the config file:
php artisan vendor:publish
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;
}
}
This project is licensed under the MIT License