yamez / laravel-influxdb
一个用于提供、设置和使用来自 influxdata influxphp 库的服务,以在 Laravel 中使用。
1.0.7
2020-06-01 02:40 UTC
Requires
- illuminate/support: ^5.0|^6.0|^7.0
- influxdb/influxdb-php: ^1.15
This package is auto-updated.
Last update: 2024-09-29 06:02:19 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 许可证授权