Skip to content

A minimal service provider to set up and use InfluxDB SDK in Laravel 5

Notifications You must be signed in to change notification settings

bbrink68/laravel-influx-provider

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Laravel InfluxDB provider

A minimal service provider to set up and use InfluxDB SDK in Laravel 5

Installation

  • Add a line to require section of composer.json and execute $ composer install
"require": {
//  ...
    "pdffiller/laravel-influx-provider": "^1.2"
}
  • Add a line to config/app.php
'providers' => [
//  ...
    Pdffiller\LaravelInfluxProvider\InfluxDBServiceProvider::class,
]
  • Define env variables to connect to InfluxDB
LARAVEL_INFLUX_PROVIDER_PROTOCOL=http
LARAVEL_INFLUX_PROVIDER_USER=some_user
LARAVEL_INFLUX_PROVIDER_PASSWORD=some_password
LARAVEL_INFLUX_PROVIDER_HOST=host
LARAVEL_INFLUX_PROVIDER_PORT=8086
LARAVEL_INFLUX_PROVIDER_DATABASE=database_name

How to use

$point = [
    new \InfluxDB\Point(
        'name' => 'some_name',
        'value' => 1, // some value for some_name
        'tags' => [
            // array of string values
        ],
        'fields' => [
            // array of numeric values
        ],
        'timestamp' => exec('date +%s%N')  // timestamp in nanoseconds on Linux ONLY
    )
];
try {
    Influx::writePoints($point);
} catch (\InfluxDB\Exception $e) {
    // something is wrong, track this
}

Also you can send data to another database like this:

Influx::selectDB($dbName)->writePoints($point);

About

A minimal service provider to set up and use InfluxDB SDK in Laravel 5

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%