tray-labs/laravel-influxdb

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

1.0.11 2024-03-30 16:33 UTC

This package is auto-updated.

Last update: 2024-09-13 14:38:57 UTC


README

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

安装

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

注册服务提供者(选择以下两种之一)。

  • Laravel:在 config/app.php 文件中,Laravel 5.5+ 自动支持包发现,您应该跳过此步骤
    'providers' => [
    //  ...
    TrayLabs\InfluxDB\Providers\ServiceProvider::class,
    ]
    'aliases' => [
    //  ...
        'InfluxDB' => TrayLabs\InfluxDB\Facades\InfluxDB::class,
    ]
  • Lumen:在 bootstrap/app.php 文件中
    // config
    $app->configure('InfluxDB');
    
    $app->register(TrayLabs\InfluxDB\Providers\LumenServiceProvider::class);
    $app->alias('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
  • 在您的项目目录中的终端内写入以下内容
    • Laravel
      php artisan vendor:publish
    • Lumen
      cp vendor/TrayLabs/lumen-influxdb/config/InfluxDB.php config/InfluxDB.php

读取数据

<?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 许可证授权