Skip to content

Commit 97b8a59

Browse files
committed
Hic Sunt Dracones
0 parents  commit 97b8a59

File tree

9 files changed

+302
-0
lines changed

9 files changed

+302
-0
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
indent_style = space
12+
13+
[**.php]
14+
indent_size = 4
15+
16+
[**.json]
17+
indent_size = 4
18+
19+
[**.yml]
20+
indent_size = 2

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/
2+
.bundle
3+
composer.lock
4+
/build/

.php_cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/**
3+
* Config for PHP-CS-Fixer ver2
4+
*/
5+
$rules = [
6+
'@PSR2' => true,
7+
// addtional rules
8+
'array_syntax' => ['syntax' => 'short'],
9+
'no_multiline_whitespace_before_semicolons' => true,
10+
'no_short_echo_tag' => true,
11+
'no_unused_imports' => true,
12+
'not_operator_with_successor_space' => true,
13+
];
14+
$excludes = [
15+
// add exclude project directory
16+
'vendor',
17+
'node_modules',
18+
'storage',
19+
'public',
20+
'docker',
21+
'bootstrap',
22+
'resources'
23+
];
24+
return PhpCsFixer\Config::create()
25+
->setRules($rules)
26+
->setFinder(
27+
PhpCsFixer\Finder::create()
28+
->exclude($excludes)
29+
->notName('README.md')
30+
->notName('_ide_helper.php')
31+
->notName('_ide_helper_models.php')
32+
->notName('.phpstorm.meta.php')
33+
->notName('server.php')
34+
->notName('*.xml')
35+
->notName('*.yml')
36+
);

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 TrayLabs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Laravel Influxdb
2+
3+
A service made to provide, set up and use [influxdb-php](https://github.com/influxdata/influxdb-php/) in Laravel 5.6
4+
5+
## Installation
6+
7+
Follow this steps to use this package on your Laravel installation
8+
9+
### 1. Require it on composer
10+
11+
```bash
12+
composer require power-data-hub/laraflux
13+
```
14+
15+
The package will automatically register it's service provider.
16+
17+
For Laravel <= 5.4 add the provider manually
18+
19+
### 2. Load service provider (optional Laravel <= 5.4 only)
20+
21+
You need to update your `config/app.php` configuration file to register our service provider, adding this line on `providers` array:
22+
23+
```php
24+
PowerDataHub\Laraflux\ServiceProvider::class
25+
```
26+
27+
```
28+
'aliases' => [
29+
// ...
30+
'InfluxDB' => PowerDataHub\Laraflux\Facades\InfluxDB::class,
31+
]
32+
```
33+
34+
* Define `.env` variables to connect to InfluxDB
35+
36+
```ini
37+
INFLUXDB_HOST=localhost
38+
INFLUXDB_PORT=8086
39+
INFLUXDB_USER=some_user
40+
INFLUXDB_PASSWORD=some_password
41+
INFLUXDB_SSL=false
42+
INFLUXDB_VERIFYSSL=false
43+
INFLUXDB_TIMEOUT=0
44+
INFLUXDB_DBNAME=some_database
45+
```
46+
47+
* Write this into your terminal inside your project
48+
49+
```ini
50+
php artisan vendor:publish
51+
```
52+
53+
## Reading Data
54+
55+
```php
56+
<?php
57+
58+
// executing a query will yield a resultset object
59+
$result = InfluxDB::query('select * from test_metric LIMIT 5');
60+
61+
// get the points from the resultset yields an array
62+
$points = $result->getPoints();
63+
```
64+
65+
## Writing Data
66+
67+
```php
68+
<?php
69+
70+
// create an array of points
71+
$points = array(
72+
new InfluxDB\Point(
73+
'test_metric', // name of the measurement
74+
null, // the measurement value
75+
['host' => 'server01', 'region' => 'us-west'], // optional tags
76+
['cpucount' => 10], // optional additional fields
77+
time() // Time precision has to be set to seconds!
78+
),
79+
new InfluxDB\Point(
80+
'test_metric', // name of the measurement
81+
null, // the measurement value
82+
['host' => 'server01', 'region' => 'us-west'], // optional tags
83+
['cpucount' => 10], // optional additional fields
84+
time() // Time precision has to be set to seconds!
85+
)
86+
);
87+
88+
$result = InfluxDB::writePoints($points, \InfluxDB\Database::PRECISION_SECONDS);
89+
```
90+
91+
License
92+
----
93+
94+
This project is licensed under the MIT License

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "power-data-hub/laraflux",
3+
"description": "A service made to provide, set up and use influxphp in Laravel.",
4+
"type": "library",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Power Data Hub",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"PowerDataHub\\Laraflux\\": "src/"
15+
}
16+
},
17+
"require": {
18+
"php": "^7.1.3",
19+
"influxdb/influxdb-php": "^1.14"
20+
},
21+
"require-dev": {
22+
"orchestra/testbench": "^3.6",
23+
"phpunit/phpunit": "^7.0",
24+
"friendsofphp/php-cs-fixer": "^2.11"
25+
},
26+
"minimum-stability": "dev",
27+
"extra": {
28+
"laravel": {
29+
"providers": [
30+
"PowerDataHub\\Laraflux\\ServiceProvider"
31+
]
32+
}
33+
}
34+
}

config/laraflux.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
return [
4+
'host' => env('INFLUXDB_HOST', 'localhost'),
5+
'port' => env('INFLUXDB_PORT', 8086),
6+
'username' => env('INFLUXDB_USER', ''),
7+
'password' => env('INFLUXDB_PASSWORD', ''),
8+
'ssl' => env('INFLUXDB_SSL', false),
9+
'verifySSL' => env('INFLUXDB_VERIFYSSL', false),
10+
'timeout' => env('INFLUXDB_TIMEOUT', 0),
11+
'dbname' => env('INFLUXDB_DBNAME', ''),
12+
];

src/Facades/InfluxDB.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace PowerDataHub\Laraflux\Facades;
4+
5+
use Illuminate\Support\Facades\Facade as LaravelFacade;
6+
use InfluxDB\Database;
7+
8+
class InfluxDB extends LaravelFacade
9+
{
10+
/**
11+
* Get the registered name of the component.
12+
*
13+
* @return string
14+
*/
15+
protected static function getFacadeAccessor()
16+
{
17+
return Database::class;
18+
}
19+
}

src/Providers/ServiceProvider.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace PowerDataHub\Laraflux\Providers;
4+
5+
use Illuminate\Support\ServiceProvider as LaravelServiceProvider;
6+
use InfluxDB\Client as InfluxClient;
7+
use InfluxDB\Database as InfluxDB;
8+
9+
class ServiceProvider extends LaravelServiceProvider
10+
{
11+
/**
12+
* Indicates if loading of the provider is deferred.
13+
*
14+
* @var bool
15+
*/
16+
protected $defer = true;
17+
18+
/**
19+
* Bootstrap any application services.
20+
*
21+
* @return void
22+
*/
23+
public function boot()
24+
{
25+
$this->publishes([
26+
__DIR__ . '/../../config/laraflux.php' => config_path('laraflux.php')
27+
]);
28+
}
29+
30+
/**
31+
* Register the service provider.
32+
*
33+
* @return void
34+
*/
35+
public function register()
36+
{
37+
$this->app->singleton(InfluxDB::class, function($app) {
38+
$client = new InfluxClient(
39+
config('influxdb.host'),
40+
config('influxdb.port'),
41+
config('influxdb.username'),
42+
config('influxdb.password'),
43+
config('influxdb.ssl'),
44+
config('influxdb.verifySSL'),
45+
config('influxdb.timeout')
46+
);
47+
return $client->selectDB(config('influxdb.dbname'));
48+
});
49+
}
50+
51+
/**
52+
* Get the services provided by the provider.
53+
*
54+
* @return array
55+
*/
56+
public function provides()
57+
{
58+
return [
59+
InfluxDB::class,
60+
];
61+
}
62+
}

0 commit comments

Comments
 (0)