iankibet/influxdb

Laravel package for interacting with influxDB

1.0.0 2024-07-30 13:38 UTC

This package is auto-updated.

Last update: 2025-03-01 00:33:31 UTC


README

Installation

  1. Install the package via Composer:
composer require iankibet/influxdb
  1. Publish the configuration file:
php artisan vendor:publish --provider="Iankibet\InfluxDB\InfluxDBServiceProvide"
  1. Configure the package by setting the following environment variables in your .env file:
INFLUXDB_HOST=127.0.0.1
INFLUXDB_PORT=8086
INFLUXDB_TOKEN=
INFLUXDB_BUCKET=
INFLUXDB_ORG=

Usage

Writing Data

use Iankibet\InfluxDb\InfluxDbPoint;
use Iankibet\InfluxDb\Facades\InfluxDb;

// in your controller/method
$point = new InfluxDbPoint();
$point->setMeasurement('measurement_name');
$point->setTags(['tag_key' => 'tag_value']);
$point->setFields(['field_key' => 'field_value']);
$point->setTime(time());

InfluxDb::write($point);

Querying Data

use Iankibet\InfluxDb\Facades\InfluxDb;
$measurement = 'measurement_name';
$fields = [
    'key1'=>'value1',
    'key2'=>'value2'
];
$from = '2021-01-01T00:00:00Z';
$to = '2021-01-02T00:00:00Z';
$res = InfluxDb::query('measurement_name', $fields, $from, $to);

For more details, visit the InfluxDB Integration for Laravel: A Comprehensive Guide.