PHP code example of power-data-hub / laraflux

1. Go to this page and download the library: Download power-data-hub/laraflux library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

power-data-hub / laraflux example snippets


PowerDataHub\Laraflux\ServiceProvider::class



// executing a query will yield a resultset object
$result = Laraflux::query('select * from test_metric LIMIT 5');

// get the points from the resultset yields an array
$points = $result->getPoints();



// create an array of points
$points = [
    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 = Laraflux::writePoints($points, \InfluxDB\Database::PRECISION_SECONDS);
ini
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
ini
php artisan vendor:publish