jrbecart / laravel-influxdb
这是一个服务,旨在提供、设置和使用influxdata的influxphp库在Laravel中的应用。
1.0.8
2021-06-16 14:30 UTC
Requires
- illuminate/support: ^5.0|^6.0|^7.0|^8.0
- jrbecart/influxdb-php: ^1.16
This package is not auto-updated.
Last update: 2024-09-20 05:45:48 UTC
README
这是一个服务,旨在提供、设置和使用来自influxdata influxdb-php库在Laravel中的应用。
安装
- 通过composer命令安装
composer require tray-labs/laravel-influxdb
- 或者在
composer.json的require部分添加以下行,并在终端执行$ composer install
"require": { "tray-labs/laravel-influxdb": "^1.0" }
此包使用自动发现功能,如果使用低于laravel 5.5的版本,您必须使用以下设置
- 将这些行添加到您的config/app.php中(仅适用于Laravel版本低于5.5)
'providers' => [ // ... TrayLabs\InfluxDB\Providers\ServiceProvider::class, ]
'aliases' => [ // ... 'InfluxDB' => TrayLabs\InfluxDB\Facades\InfluxDB::class, ]
- 定义连接到InfluxDB的环境变量
INFLUXDB_HOST=localhost INFLUXDB_PORT=8086 INFLUXDB_USER=some_user INFLUXDB_PASSWORD=some_password INFLUXDB_SSL=false INFLUXDB_VERIFYSSL=false INFLUXDB_TIMEOUT=0 INFLUXDB_DBNAME=some_database INFLUXDB_UDP_ENABLED=false # Activate UDP INFLUXDB_UDP_PORT=4444 # Port for UDP
- 在您的项目目录中终端内运行以下命令
php artisan vendor:publish
读取数据
<?php // executing a query will yield a resultset object $result = InfluxDB::query('select * from test_metric LIMIT 5'); // get the points from the resultset yields an array $points = $result->getPoints();
写入数据
<?php // create an array of points $points = array( new InfluxDB\Point( 'test_metric', // name of the measurement null, // the measurement value ['host' => 'server01', 'region' => 'us-west'], // optional tags ['cpucount' => 10], // optional additional fields time() // Time precision has to be set to seconds! ), new InfluxDB\Point( 'test_metric', // name of the measurement null, // the measurement value ['host' => 'server01', 'region' => 'us-west'], // optional tags ['cpucount' => 10], // optional additional fields time() // Time precision has to be set to seconds! ) ); $result = InfluxDB::writePoints($points, \InfluxDB\Database::PRECISION_SECONDS);
许可证
本项目采用MIT许可证