renatosilva / laravel-influxdb

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

1.0.7 2021-02-12 16:42 UTC

This package is not auto-updated.

Last update: 2024-09-22 08:23:52 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许可证