power-data-hub/laraflux

一个用于提供、设置和使用influxphp在Laravel中的服务。

v0.0.1 2018-05-20 22:46 UTC

README

Maintained by Powerdatahub.com

Laravel Influxdb

一个用于提供、设置和使用influxdb-php在Laravel 5.6中的服务。

安装

按照以下步骤在你的Laravel安装上使用此包

1. 在composer中要求它

composer require power-data-hub/laraflux

该包将自动注册其服务提供者。

对于Laravel <= 5.4,请手动添加提供者

2. 加载服务提供者(仅限于Laravel <= 5.4可选)

您需要更新您的config/app.php配置文件以注册我们的服务提供者,在providers数组中添加此行

PowerDataHub\Laraflux\ServiceProvider::class
'aliases' => [
//  ...
    'Laraflux' => PowerDataHub\Laraflux\Facades\Laraflux::class,
]
  • 定义.env变量以连接到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
  • 在您的项目终端中写入以下内容
php artisan vendor:publish

读取数据

<?php

// executing a query will yield a resultset object
$result = Laraflux::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 = [
    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 = Laraflux::writePoints($points, \InfluxDB\Database::PRECISION_SECONDS);

许可证

此项目使用MIT许可证授权