modis/laravel-influxdb

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

1.2 2021-01-25 14:35 UTC

This package is auto-updated.

Last update: 2024-09-25 16:08:01 UTC


README

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

安装

  • 通过composer命令安装
composer require modis/laravel-influxdb
  • 或者将以下行添加到composer.json的require部分,并在终端执行$ composer install
"require": {
    "modis/laravel-influxdb": "^1.2"
}

此包使用自动发现功能,如果使用Laravel版本低于5.5,则必须使用以下设置

  • 将以下行添加到您的config/app.php中(仅适用于Laravel版本低于5.5)
'providers' => [
//  ...
    Modis\InfluxDB\Providers\ServiceProvider::class,
]
'aliases' => [
//  ...
    'InfluxDB' => Modis\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许可证