influxdata / influxdb-php Goto Github PK
View Code? Open in Web Editor NEWinfluxdb-php: A PHP Client for InfluxDB, a time series database
Home Page: http://influxdb.com
License: MIT License
influxdb-php: A PHP Client for InfluxDB, a time series database
Home Page: http://influxdb.com
License: MIT License
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) } } } } } } } }
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' 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.
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
Any particular reason why the timeout is set to 0?
https://github.com/influxdata/influxdb-php/blob/master/src/InfluxDB/Client.php#L49
I just encountered a pretty big problem with this. Because there was no timeout, our app was throwing a 504 error and we had no idea what was happening. We had to manually set the timeout to something reasonable so an exception could be called.
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).
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.
Calling InfluxDB\Client::fromDSN
with a DSN that doesn't contain username or password, e.g. "https+influxdb://localhost:8086/testdb"
, will trigger a notice:
PHP Notice: Undefined index: user in src/InfluxDB/Client.php on line 296
PHP Notice: Undefined index: pass in src/InfluxDB/Client.php on line 297
i created a database and created six retentionPolicy on this database.
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.
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
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
i dont't know how it works.
Anyone can help me?
There might be some breaking changes in 0.9.2, particularly with inserting integer values.
Is the library updated to support these changes in 0.9.2 (and soon 0.9.3)?
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
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.
@beckettsean @toddboom @pauldix
Can someone add packagist as a post-service hook to this repository? https://packagist.org/packages/influxdb/influxdb-php
I simulated an InfluxDB server crash to see how my app work.
I got an exception directly from Guzzle library:
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?
We are waiting for a new release that includes this commit 8fcc544 ("Support for Symfony 4").
Thanks
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()
)
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...
Refer to https://github.com/influxdata/influxdb-php/blob/master/src/InfluxDB/Database.php#L89
The "if not exists" syntax in Database::create was defaulted and deprecated before 1.0 release, and crashes with syntax error if used now. The parameter should be removed.
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)
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.
I can't use UDP, is there any way to write points asynchronously?
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?
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.
composer require corley/influxdb-sdk
$options = new Options();
$adapter = new UdpAdapter($options);
$client = new Client();
$client->setAdapter($adapter);
$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?
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
.
I may be missing something, but https://github.com/influxdb/influxdb-php/blob/master/src/InfluxDB/Point.php#L160 validates if parameter is INT or fits within PHP_MAX_INT range. This is not sufficient to carry nano-seconds timestamps.
Why aren't float or double types accepted at face value?
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;
}`
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
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!
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
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 ?
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.
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?
Please use sprintf(%F) to format float values in InfluxDB\Point
Thanks a lot!
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.
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 ?
Summary
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',
The return of list listUsers() is name of the columns instread of a list of users.
Array( 0 => user , 1 => admin)
Array( 0 => array( admin => FALSE, user => test_dev), 1 => array( admin => FALSE, user => test_user))
In attachment the patch to fix the problem (IMHO).
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.
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.
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.
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:
path
field to the result.groupBy
field value. This could be done on next major.@beckettsean @toddboom @pauldix i cannot add the project to travis CI or codeclimate because i do not have admin rights
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?
Why? PHP 5.3 is not supported anymore since 11 months ago. So why should we? http://php.net/eol.php
I really think we should move on. We're in the imminence of PHP 7 and at the same time supporting old branches :(.
is there any preferred way? thanks
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.?
ResultSet's getSeries()
will return only the first element of the parsedResults
. https://github.com/influxdata/influxdb-php/blob/master/src/InfluxDB/ResultSet.php#L104
To reproduce:
$query .= "SELECT * FROM m;"
$query .= "SELECT * FROM m;"
$query .= "SELECT * FROM m;"
$result = $influxDB->query($query);
print_r($result->getSeries());
Instead of return 3 series, it will only return one.
PHP 7.0.19-1
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"
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?
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
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));
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.