Giter Club home page Giter Club logo

influxdb-php's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

influxdb-php's Issues

Support group by *

Hello,
Currently, Influxdb-php not support the arguments 'group by *'
Here is a sample output with and without group by:
Exemple of request :
$QueryGTD = $database_gtd->query('select * from '.$mesurement_gtd.' order by time desc LIMIT 1'); $QSeriesGtd = $database_gtd->query('select * from '.$mesurement_gtd.' group by * order by time desc LIMIT 1');

var_dump($QueryGTD)
object(InfluxDB \ ResultSet) # 155(1) { ["parsedResults" : protected] = > array(1) { ["results"] = > array(1) { [0] = > array(1) { ["series"] = > array(1) { [0] = > array(3) { ["name"] = > string(3)"gtd" ["columns"] = > array(3) { [0] = > string(4)"time"[1] = > string(8)"platform"[2] = > string(5)"value" } ["values"] = > array(1) { [0] = > array(3) { [0] = > string(20)"2016-07-05T07:48:47Z" [1] = > string(9)"OpenStack" [2] = > int(100) } } } } } } } }

var_dump($QSeriesGtd)
object(InfluxDB \ ResultSet) # 153(1) { ["parsedResults" : protected] = > array(1) { ["results"] = > array(1) { [0] = > array(1) { ["series"] = > array(1) { [0] = > array(4) { ["name"] = > string(3)"gtd" ["tags"] = > array(1) { ["platform"] = > string(9)"OpenStack" } ["columns"] = > array(2) { [0] = > string(4)"time"[1] = > string(5)"value" } ["values"] = > array(1) { [0] = > array(2) { [0] = > string(20)"2016-07-05T07:48:47Z" [1] = > int(100) } } } } } } } }

Active development

Dear influxDB,

My team and at leaseweb i are creating a library for php that is based on the python library and should work the same way. Do you want us to create the library independently or can we have push rights to this repo?

Our repo (work in progress): https://github.com/LeaseWeb/influxdb-php

why is 'symfony/event-dispatcher' required dependency?

Why is 'symfony/event-dispatcher' marked as required dependency (https://github.com/influxdata/influxdb-php/blob/master/composer.json#L31)?

So I did little test - I will remove 'symfony/event-dispatcher' from dependencies and do composer install.

These are packages that are installed:

php5.6 ../composer.phar install --no-dev
Loading composer repositories with package information
Installing dependencies from lock file
Package operations: 4 installs, 0 updates, 0 removals
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing guzzlehttp/psr7 (1.4.2): Loading from cache
  - Installing guzzlehttp/promises (v1.3.1): Loading from cache
  - Installing guzzlehttp/guzzle (6.3.0): Loading from cache

So another test with removing symfony from dev dependencies and replacing their phpunit-bridge with real phpunit my composer.json dependencies will look like

    "require": {
        "php": "^5.5 || ^7.0",
        "guzzlehttp/guzzle": "^6.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^5.7"
    },

and this will get installed:

php5.6 ../composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 29 installs, 0 updates, 0 removals
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing guzzlehttp/psr7 (1.4.2): Loading from cache
  - Installing guzzlehttp/promises (v1.3.1): Loading from cache
  - Installing guzzlehttp/guzzle (6.3.0): Loading from cache
  - Installing webmozart/assert (1.2.0): Loading from cache
  - Installing phpdocumentor/reflection-common (1.0.1): Loading from cache
  - Installing phpdocumentor/type-resolver (0.4.0): Loading from cache
  - Installing phpdocumentor/reflection-docblock (3.3.2): Loading from cache
  - Installing phpunit/php-token-stream (1.4.12): Loading from cache
  - Installing symfony/yaml (v3.4.2): Loading from cache
  - Installing sebastian/version (2.0.1): Loading from cache
  - Installing sebastian/resource-operations (1.0.0): Loading from cache
  - Installing sebastian/recursion-context (2.0.0): Loading from cache
  - Installing sebastian/object-enumerator (2.0.1): Loading from cache
  - Installing sebastian/global-state (1.1.1): Loading from cache
  - Installing sebastian/exporter (2.0.0): Loading from cache
  - Installing sebastian/environment (2.0.0): Loading from cache
  - Installing sebastian/diff (1.4.3): Loading from cache
  - Installing sebastian/comparator (1.2.4): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Loading from cache
  - Installing doctrine/instantiator (1.0.5): Loading from cache
  - Installing phpunit/phpunit-mock-objects (3.4.4): Loading from cache
  - Installing phpunit/php-timer (1.0.9): Loading from cache
  - Installing phpunit/php-file-iterator (1.4.5): Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
  - Installing phpunit/php-code-coverage (4.0.8): Loading from cache
  - Installing phpspec/prophecy (1.7.3): Loading from cache
  - Installing myclabs/deep-copy (1.7.0): Loading from cache
  - Installing phpunit/phpunit (5.7.26): Loading from cache
guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware)
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Generating autoload files

so only 'symfony/yaml (v3.4.2)' is required through dependency in somewhere in phpunit

Maybe we could remove sympony deps and use phpunit. Looking at .travis.yml (https://github.com/influxdata/influxdb-php/blob/master/.travis.yml) it is little bit silly as it is more about testing sympfony than testing influxdb library. I could do PR for it

ps. I am aware that phpunit 5.7 does not support php5.5 officially.

this is why???

include('influxdb-php-sdk1/autoload.php');

/*
$host = '127.0.0.1';
$port = 8086;
$dbname = 'ddd';
$client = new InfluxDB\Client($host, $port);

fetch the database
$database = $client->selectDB('ddd');

// executing a query will yield a resultset object
$result = $database->query('select * from log LIMIT 5');

var_dump($result);
*/

// directly get the database object
$database = InfluxDB\Client::fromDSN(sprintf('influxdb://user:pass@%s:%s/%s', '127.0.0.1', 8086, 'test_db'));

// get the client to retrieve other databases

$client = $database->getClient();

// set the UDP driver in the client
$client->setDriver(new \InfluxDB\Driver\UDP($client->getHost(), 4444));

$points = [
new Point(
'test_metric',
0.84,
['host' => 'server01', 'region' => 'us-west'],
['cpucount' => 10],
exec('date +%s%N') // this will produce a nanosecond timestamp in Linux operating systems
)
];

// now just write your points like you normally would
$result = $database->writePoints($points);

results:

Fatal error: Class 'Point' not found in /mnt/hgfs/windows-webserver/study/influxdb/t4.php on line 47

Safely handle inserting object field values

Problem

Hi, I was trying to insert a uuid into a record, and it caused a 400 error because the finished record looked like this

event,foo=bar id=a605d377-47bd-4d9a-8b6e-c9ed66bed255

The error occurs because the uuid isn't quoted:

event,foo=bar id="a605d377-47bd-4d9a-8b6e-c9ed66bed255"

This is because the uuid was a Uuid object, not a string (which I didn't realize at the time).

Solution

This function should stringify objects before processing them.

if (is_object($field) {
    $field = $field->toString();
}

The object will eventually be stringified when inserted into the line record, so may as well do it early so it can be quoted if needed.

I can't use the retentionPolicy

i created a database and created six retentionPolicy on this database.

image

but,when i worte the data into it.Only the default policy can success. Other request return 204,but nothing in the database.

i tried to edit the config file,but it see normal.
image

The default policy is POLICY_ONE_MONTH
so i send this request

 curl -i -XPOST 'http://localhost:8086/write?db=haiwaiuni-stat&precision=u&rp=POLICY_ONE_WEEK' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.63 1515414280000001'

the result is

HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 4c01452a-f473-11e7-8020-000000000000
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.4.2
X-Request-Id: 4c01452a-f473-11e7-8020-000000000000
Date: Mon, 08 Jan 2018 12:56:09 GMT

nothing
image

and i change it to:

curl -i -XPOST 'http://localhost:8086/write?db=haiwaiuni-stat&precision=u&rp=POLICY_ONE_MONTH' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.63 1515414280000001'

the result is

HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: b53571f3-f473-11e7-8025-000000000000
X-Influxdb-Build: OSS
X-Influxdb-Version: 1.4.2
X-Request-Id: b53571f3-f473-11e7-8025-000000000000
Date: Mon, 08 Jan 2018 12:59:05 GMT

The data is already in there.
image

i dont't know how it works.

Anyone can help me?

Offset in InfluxDB\Query\Builder

Hi,

Is there a way to use offset in Builder? I am planning use it for pagination purposes.

Also what is the simples way to get the total value? SELECT * FROM table returns many stuff rather than single scalar value such as 23. Just to replace $result->getPoints()[0]['count'] which looks ugly.

Thanks

Paced releases

Would it be possible to deploy regular updates in a similar way with influxdb or telegraf. That'd make us become more confident with the library. It's a shame we do not get enough incentives to switch from the wonderful https://github.com/corley/influxdb-php-sdk to this library, which is closer to the core influxdb project.

Manage connect exception

I simulated an InfluxDB server crash to see how my app work.

I got an exception directly from Guzzle library:

image

Guzzle is used by your library but not by the user. The end use should rely to your exception only IMHO.

If think it would be better to have you own generic exception for that.

What do you think?

Writing data with timestamp not working

From your example:

    // create an array of points
    $points = array(
        new Point(
            'test_metric',
            0.64,
            array('host' => 'server01', 'region' => 'us-west'),
            array('cpucount' => 10),
            1435255849
        ),
        new Point(
            'test_metric',
            0.84,
            array('host' => 'server01', 'region' => 'us-west'),
            array('cpucount' => 10),
            1435255850
        )
    );

    $newPoints = $database->writePoints($points);

with InfluxDB 0.9.1 timestamp is added as 1970-01-01T00:00:01.435255849Z

Same wrong database entry if I do:

        new Point(
            'test_metric',
            0.84,
            array('host' => 'server01', 'region' => 'us-west'),
            array('cpucount' => 10),
            time()
        )

Exception on GuzzleHttp fopen on Debian 8.0 AMD64 and InfluxDB 0.12.2

I'm having issue not able to create a database object where a exception is thrown:

os: Debian 8.4 AMD64 jessie
php-cli (from debian repo): PHP 5.6.20-0+deb8u1 (cli) (built: Apr 27 2016 11:26:05)
influxdb (from influxdata repo): 0.12.2

The snippet (the demo as the README.md):

<?php
        require_once "vendor/autoload.php";

        use InfluxDB\Client;
        use InfluxDB\Point;
        use InfluxDB\Database;

        $host = "localhost";
        $port = 8086;
        $user = "endurance";
        $pass = "endurance";
        $dbname = "endurance";

        $client = new InfluxDB\Client($host, $port);
        $db = $client->selectDB($dbname);

        // create an array of points
        $points = array(
                new Point(
                        'test_metric', // name of the measurement
                        0.64, // the measurement value
                        ['host' => 'server01', 'region' => 'us-west'], // optional tags
                        ['cpucount' => 10], // optional additional fields
                        1435255849 // Time precision has to be set to seconds!
                ),
                new Point(
                'test_metric', // name of the measurement
                        0.84, // the measurement value
                        ['host' => 'server01', 'region' => 'us-west'], // optional tags
                        ['cpucount' => 10], // optional additional fields
                        1435255849 // Time precision has to be set to seconds!
                )
        );

        // we are writing unix timestamps, which have a second precision
        $result = $db->writePoints($points, Database::PRECISION_SECONDS);
?>

The error:

PHP Fatal error:  Uncaught exception 'InfluxDB\Exception' with message 'Error creating resource: [message] fopen(http://localhost:8086/write?db=endurance&precision=s): failed to open stream: HTTP request failed!
[file] /vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
[line] 287' in vendor/influxdb/influxdb-php/src/InfluxDB/Database.php:144
Stack trace:
#0 writetest.php(36): InfluxDB\Database->writePoints(Array, 's')
#1 {main}
  thrown in vendor/influxdb/influxdb-php/src/InfluxDB/Database.php on line 144

I actually see something flowing on the wire, while still the exception is thrown....:

$ sudo tcpflow -i lo -c  'port 8086'
tcpflow: listening on lo
::1.45219-::1.08086: POST /write?db=endurance&precision=s HTTP/1.1

::1.45219-::1.08086: Content-Length: 151
User-Agent: GuzzleHttp/6.2.0 PHP/5.6.20-0+deb8u1
Host: localhost:8086
Connection: close
Content-Type:
::1.45219-::1.08086:

::1.45219-::1.08086:

::1.45219-::1.08086: test_metric,host=server01,region=us-west cpucount=10i,value=0.64 1435255849
test_metric,host=server01,region=us-west cpucount=10i,value=0.84 1435255849
::1.08086-::1.45219: HTTP/1.1 204 No Content
Request-Id: be4c3e00-0dfa-11e6-aeba-000000000000
X-Influxdb-Version: 0.12.2
Date: Fri, 29 Apr 2016 11:08:46 GMT
Connection: close

Maybe someone can test this also on a vanilla debian, as we digged deep into the GuzzleHttp lib and had no clue...

writing multiple measurements with differents specified timestamp

I try to write multiple measurements, each with a specified time (not the time from the moment when it's inserted) but I feel the signature doesn't allow this.
prepareMessageSection() in src/Adapter/WriterTrait.php only accepts one "time" key in array, so all inserted measurements will have the same timestamp

any way to insert multiple measurments with their own timestamp ?
it's possible querying directly (with cUrl for example)

Grant Privilege, with get?

object(InfluxDB\ResultSet)#33 (2) {
["parsedResults":protected]=>
array(1) {
["results"]=>
array(1) {
[0]=>
array(2) {
["statement_id"]=>
int(0)
["messages"]=>
array(1) {
[0]=>
array(2) {
["level"]=>
string(7) "warning"
["text"]=>
string(120) "deprecated use of 'GRANT ALL PRIVILEGES ON tbh_vps TO tbh_vps' in a read only context, please use a POST request instead"
}
}
}
}
}
["rawResults":protected]=>
string(196) "{"results":[{"statement_id":0,"messages":[{"level":"warning","text":"deprecated use of 'GRANT ALL PRIVILEGES ON tbh_vps TO tbh_vps' in a read only context, please use a POST request instead"}]}]}
"
}

I think it's self explanatory.

Async request

I can't use UDP, is there any way to write points asynchronously?

Failed to show database when calling exists()

When calling exists() to check a DB, PHP will throw fatal error:

PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Error creating resource: [message] fopen(http://127.0.0.1:8086/query?q=SHOW+DATABASES): failed to open stream: HTTP request failed!
[file] /project/lib/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php
[line] 282' in /project/lib/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php:222
Stack trace:
#0 /project/lib/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(286): GuzzleHttp\Handler\StreamHandler->createResource(Object(Closure))
#1 /project/lib/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php(52): GuzzleHttp\Handler\StreamHandler->createStream(Object(GuzzleHttp\Psr7\Request), Array)
#2 /project/lib/vendor/guzzlehttp/guzzle/src/PrepareBodyMiddleware.php(42): GuzzleHttp\Handler\StreamHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#3 /project/lib/vendor/guzzlehttp/guzzle/src/Middleware.php(30): GuzzleHttp\PrepareBodyMiddleware in /project/lib/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 51


I can manually use CURL or wget to successfully retrieve:
http://127.0.0.1:8086/query?q=SHOW+DATABASES
but not from influxdb-php's exists().

It seems the error related with guzzle 6.
Is there any one has similar issue like this?

An interesting starting point?

Hi! Thanks for your job at InfluxDB, it is a nice tool!

We use it in ours applications written in PHP.
I'm here to underline ours influxdb-php-sdk and to submit it to influxdb community.
This SDK now support UDP and TPC (Guzzle) protocols but exist standard interface to write your implementation. It's fully tested and very simple to use it and extendable.

  1. Use composer to manage dependency
composer require corley/influxdb-sdk
  1. Create your client
$options = new Options();
$adapter = new UdpAdapter($options);

$client = new Client();
$client->setAdapter($adapter);
  1. Mark your points
$client->mark("app.search", [
    "key" => "this is my search"
]);

It's very integrable with dependency injection containers like SymfonyDiC or any other framework.

See README.md

What do you think about it?

[Enhancement] Allow time precision setting when creating database object

I'm writing an API which contains a lot of queries using this library. As I need to set the precision for every call to query, it increases the verbosity of my code.

It would be beneficial to be able to set the precision once, with the option of overriding the setting if precision is set on a specific call to query.

Float value in point is sent localized

This results in an exception like:

HTTP Code 400 {"error":"unable to parse points"} (Class: InfluxDB\Exception)

Fix in InfluxDB\Point:

`/**
* @param array $fields
*/
public function setFields($fields)
{
foreach ($fields as &$field) {
if (is_integer($field)) {
$field = sprintf('%di', $field);
} elseif (is_string($field)) {
$field = $this->escapeFieldValue($field);
} elseif (is_float($field) || is_double($field)) {
$field = sprintf('%F', $field);
} elseif (is_bool($field)) {
$field = ($field ? "true" : "false");
}
}

    $this->fields = $fields;
}`

why very slow to write data use udp ???

use InfluxDB\Point;

// directly get the database object
$database = InfluxDB\Client::fromDSN(sprintf('influxdb://user:pass@%s:%s/%s', '127.0.0.1', 8086, 'test_db'));

// get the client to retrieve other databases
$client = $database->getClient();

// set the UDP driver in the client
$client->setDriver(new \InfluxDB\Driver\UDP($client->getHost(), 4444));

for($i=0;$i<1000000;$i++){
$points = [
new Point(
'test_metric',
0.84,
['host' => 'server01', 'region' => 'us-west'],
['cpucount' => 10],
exec('date +%s%N') // this will produce a nanosecond timestamp in Linux operating systems
)
];

$result = $database->writePoints($points);
}

results:
select count(value) from test_metric where time > now() - 1m group by time(1s);
time count
2015-08-19T01:00:51Z 25
2015-08-19T01:00:52Z 23
2015-08-19T01:00:53Z 22
2015-08-19T01:00:54Z 20
2015-08-19T01:00:55Z 23
2015-08-19T01:00:56Z 22
2015-08-19T01:00:57Z 23
2015-08-19T01:00:58Z 25
2015-08-19T01:00:59Z 24
2015-08-19T01:01:00Z 28
2015-08-19T01:01:01Z 28
2015-08-19T01:01:02Z 29
2015-08-19T01:01:03Z 29
2015-08-19T01:01:04Z 23
2015-08-19T01:01:05Z 30
2015-08-19T01:01:06Z 28
2015-08-19T01:01:07Z 29
2015-08-19T01:01:08Z 28
2015-08-19T01:01:09Z 22
2015-08-19T01:01:10Z 26
2015-08-19T01:01:11Z 25
2015-08-19T01:01:12Z 24
2015-08-19T01:01:13Z 24
2015-08-19T01:01:14Z 22
2015-08-19T01:01:15Z 24
2015-08-19T01:01:16Z 24
2015-08-19T01:01:17Z 24

I'm very silent

Safe query parameters

Hi there,

I've been looking around for a safe way to inject variables into queries using $database->query(...) but haven't come across anything (and looking through the code, it doesn't appear that this has been implemented. This is a little worrisome considering SQL injects can cause all sorts of nasty attacks and are very easily preventable.

Is there any way we could get something like the following in order to prevent injection attacks?

$database->query("SELECT * FROM measurement WHERE something=? AND other=?", [$something, $other]);

Let me know if I'm missing anything/this is already implemented and thanks a bunch for creating Influx!

Select Retention Policy for Writes

I didn't yet find a way to select a retention policy when writing points (at least in 0.1 branch, as I'm using PHP 5.3 on RHEL6).
Possible solution: Add rp parameter to HTTP request.
I'll probably create a PR that adds this functionality via an additional (default=null) parameter to Client::write

Database name on UDP protocol

Is it me or the databse name doesn't need to be selected to send data through UDP protocol, since it's configured on the influxDB conf file.
We shoud be able to send data directely from client, no need of database instance, right ?

example of reliable connection

Hi I'm looking for an example of how to wrap the client in a try catch to detect if the database has gone away, and to attempt to reconnect if so. My php app is a daemon and right now it simply stops executing with no error if influxdb is restarted, e.g. for a simple config file update (I wish it had SIGHUP) which is obviously less than ideal, thanks.

Support for 0.9.5

Recently upgraded to 0.9.5, mostly for its tsm1 engine that saves space. Are there breaking changes that need to be addressed in this library?

Data is NOT getting written to DB - HTTP 400/ bad timestamp?

I have a simple client that should write/read data- yet the result is always empty, be it Admin interface or client. The code is entirely from the readme:

$client = new InfluxDB\Client('127.0.0.1', 8086);

// fetch the database
$database = $client->selectDB('test');

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

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

// create an array of points
$points = array(
    new Point(
        'test_metric', // name of the measurement
        0.64, // the measurement value
        ['host' => 'server01', 'region' => 'us-west'], // optional tags
        ['cpucount' => 10], // optional additional fields
        1435255849 // Time precision has to be set to seconds!
    ),
    new Point(
        'test_metric', // name of the measurement
        0.84, // the measurement value
        ['host' => 'server01', 'region' => 'us-west'], // optional tags
        ['cpucount' => 10], // optional additional fields
        1435255849 // Time precision has to be set to seconds!
    )
);

// we are writing unix timestamps, which have a second precision
$result = $database->writePoints($points, Database::PRECISION_SECONDS);
print_r($result);


// executing a query will yield a resultset object
$result = $database->query('SHOW MEASUREMENTS')->getPoints();
print_r($result);

This happens against Windows server, current download.

authentication failed while calling Database::writePoints()

In src/InfluxDB/Database.php:

if (!empty($this->username) && !empty($this->password)) {
        $parameters += ['auth' => [$this->username, $this->password]];
}

it checks username and password, but the two value is read from the Database class, but it seems that two values are defined in the Client class. so i'm always get a false result.

is this a bug ?

php client creates invalid line protocol?

Summary

  1. With the php client create a point with a blank tag value e.g. boolean false
  2. Send points to influx

Expected behaviour
The data should be ingested successfully.

Actual behaviour
The error "unable to parse" is thrown

Potentially useful info
The following is an example of a var_dump of one such point:

array (
  0 => 
  InfluxDB\Point::__set_state(array(
     'measurement' => 'actionlog',
     'tags' => 
    array (
      'myint' => '370018',
      'mybool' => '',
    ),
     'fields' => 
    array (
      'exitcode' => '0i',
    ),
     'timestamp' => '1469216277',
  )),
)

Converting the boolean value to string using strval(mybool) didn't help I had to manually convert with turnary e.g.

'mybool' => (mybool) ? 'true' : 'false',

Return of listUsers()

Problem

The return of list listUsers() is name of the columns instread of a list of users.

Actual behavior:

Array( 0 => user , 1 => admin)

Expected behavior:

Array( 0 => array( admin => FALSE, user => test_dev), 1 => array( admin => FALSE, user => test_user))

In attachment the patch to fix the problem (IMHO).

fix-listUsers.txt

UDP/IP support

InfluxDB supports UDP/IP and I believe that using UDP is much lighter, for both the server and the client. Are you going to implement support for UDP? Tx.

Adding new points in intuitive manner

Seems more intuitive to me how https://github.com/corley/influxdb-php-sdk is adding new points:

$client->mark([
    "tags" => [
        "dc" => "eu-west-1",
    ],
    "points" => [
        [
            "measurement" => "instance",
            "fields" => [
                "cpu" => 18.12,
                "free" => 712423,
            ],
        ],
    ]
]);

Compared to what we have in the README example here:

    $points = array(
        new Point(
            'test_metric',
            0.64,
            array('host' => 'server01', 'region' => 'us-west'),
            array('cpucount' => 10),
            1435255849
        )
    );

    $newPoints = $database->writePoints($points, Database::PRECISION_SECONDS);

Can we do the same on this repo? It is relatively hard for someone to understand InfluxDB from your example while example at the top makes it much easier. I, myself, don't even know how to rewrite example at the to work with this library.

No access to Point class fields

Hi there, thanks for robust library.

I'm facing problem that I have no way to access data stored into Point instance. All fields of Point are private and have no getters. I need that because my code is built around creating array of Point instances in one place, and in other place I need to update some items of array with another Point instances.

Could fields of Point be at least protected or have getters? Having them protected would perfectly satisfy me, I'd inherit from it and add getters myself.

Doing a group by removes the targeted field

Concrete case: I want to get the last point of each disk partition. So I will group the results by path.

With the following query:

$qb = $this->database->getQueryBuilder()
    ->select('*')
    ->from('disk')
    ->groupBy('path')
    ->limit(1)
    ->orderBy('time', 'DESC')
    ->where(["host = '".$host."'"]);

$result = $qb->getResultSet()->getPoints();

dump($result);

I got:

array:5 [▼
  0 => array:10 [▼
    "time" => "2016-06-02T16:01:40Z"
    "free" => 16423927808
    "fstype" => "aufs"
    "host" => "server-01"
    "inodes_free" => 3072403
    "inodes_total" => 5619712
    "inodes_used" => 2547309
    "total" => 90449113088
    "used" => 69407010816
    "used_percent" => 80.864792962421
  ]
  1 => array:10 [▼
    "time" => "2016-06-02T16:01:40Z"
    "free" => 16423927808
    "fstype" => "ext4"
    "host" => "server-01"
    "inodes_free" => 3072403
    "inodes_total" => 5619712
    "inodes_used" => 2547309
    "total" => 90449113088
    "used" => 69407010816
    "used_percent" => 80.864792962421
  ]
  2 => array:10 [▼
    "time" => "2016-06-02T16:01:40Z"
    "free" => 16423927808
    "fstype" => "ext4"
    "host" => "server-01"
    "inodes_free" => 3072403
    "inodes_total" => 5619712
    "inodes_used" => 2547309
    "total" => 90449113088
    "used" => 69407010816
    "used_percent" => 80.864792962421
  ]
  3 => array:10 [▼
    "time" => "2016-06-02T16:01:40Z"
    "free" => 16423927808
    "fstype" => "ext4"
    "host" => "server-01"
    "inodes_free" => 3072403
    "inodes_total" => 5619712
    "inodes_used" => 2547309
    "total" => 90449113088
    "used" => 69407010816
    "used_percent" => 80.864792962421
  ]
  4 => array:10 [▼
    "time" => "2016-06-02T16:01:40Z"
    "free" => 16423927808
    "fstype" => "ext4"
    "host" => "server-01"
    "inodes_free" => 3072403
    "inodes_total" => 5619712
    "inodes_used" => 2547309
    "total" => 90449113088
    "used" => 69407010816
    "used_percent" => 80.864792962421
  ]
]

And the path field is missing.

So for me, the result is completely useless because I don't know on which part each point is attached.

I think there is two ways to fix it:

  • The quick and BC way: Simply restore the path field to the result.
  • The eloquent but BC break way: replace numeric key of the array by the groupBy field value. This could be done on next major.

Better exception class naming

All exception classes of this library are named Exception.

If we import one of them, the code looks like:

        try {
            $stats = $this->get('influx.wrapper')->getLastServerStat($server->getCompleteName());
        } catch (Exception $e) {

        }

Hard to see at the first move the exception is talking about query, database or whatever.

Having QueryException for example would be a good start.

What do you think?

Support Symfony 3.0

Symfony 3.0 will be released in the shortly (roadmap says November, 2015), but influxdb/influxdb-php requires symfony/event-dispatcher: 2.* that conflicted with symfony 3.0.
Do you can update dependency version to 2.|3.?

Support unix socket

This is a feature request for this configuration offered by InfluxDB:

  unix-socket-enabled = true # enable http service over unix domain socket
  bind-socket = "/var/run/influxdb.sock"

Change `exec('date + %s%N')` to `time()` in README.md

I was just using this api and tried exec('date + %s%N') as described in the README. This did not work for me, then I looked further, I saw that its also possible to do:

list($usec, $sec) = explode(' ', microtime());
$timestamp = sprintf('%d%06d', $sec, $usec*1000000);

But AFAIK this is the same was time(). (Please correct me if I am wrong)

Would you mind if I open a PR to change this?

Auto update on packagist

Hello @thecodeassassin do you have permission to add the packagist's token in order to sync in automatic our update on packagist?

@virgofx thanks for your ping

Thanks a lot
PS at the moment the 1.4.0 is not up to date on packagist

0.1.x Release doesn't support HTTP Auth

It's a pretty simple fix - adding this line to the constructor:

$this->httpClient->setDefaultOption('auth', array($this->username, $this->password));

However - I couldn't see how to do a PR to a correct branch for the 0.1.x releases.

For anyone who finds this issue as well, I got around it by just extending the base class:

class FixedInfluxDBClient extends Client {
  public function __construct($host,$port = 8086,$username = '',$password = '',$ssl = false,$verifySSL = true,$timeout = 0) {
    parent::__construct($host,$port,$username,$password,$ssl,$verifySSL,$timeout);
    $this->httpClient->setDefaultOption('auth', array($this->username, $this->password));
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.