animalyoung/laravel-influxdb

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

1.0.6 2019-09-23 14:43 UTC

This package is not auto-updated.

Last update: 2024-09-28 08:44:56 UTC


README

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

安装

  • 使用composer命令安装
composer install 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许可证授权