mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
b5cb30a50d07a082533753840441d00452bbbced
InfluxDB PHP SDK
Send metrics to InfluxDB and query for any data.
Add new points:
$client->mark("app.search", [
"key" => "this is my search"
]);
Retrieve existing points:
$results = $client->query("select * from app.search");
InfluxDB client adapters
Actually we supports two adapters
- UDP/IP - in order to send data via UDP (datagram)
- HTTP JSON - in order to send/retrieve using HTTP (connection oriented)
Using UDP/IP Adapter
Actually "socket" php library is used for UDP/IP adapter
$options = new Options();
$adapter = new UdpAdapter($options);
$client = new Client();
$client->setAdapter($adapter);
Using HTTP Adapter
Actually Guzzle is used as HTTP client library
$options = new Options();
$adapter = new GuzzleAdapter($options);
$client = new Client();
$client->setAdapter($adapter);
Query InfluxDB
You can query the time series database using the query method.
$influx->query("select * from mine");
$influx->query("select * from mine", "s"); // with time_precision
You can query the database only if the adapter is queryable (implements QueryableInterface),
actually GuzzleAdapter.
The adapter returns the json decoded body of the InfluxDB response, something like:
array(1) {
[0] =>
class stdClass#1 (3) {
public $name =>
string(8) "tcp.test"
public $columns =>
array(3) {
[0] =>
string(4) "time"
[1] =>
string(15) "sequence_number"
[2] =>
string(4) "mark"
}
public $points =>
array(1) {
[0] =>
array(3) {
[0] =>
int(1410545635590)
[1] =>
int(2390001)
[2] =>
string(7) "element"
}
}
}
}
Install it
Just use composer
php composer.phar require corley/influxdb-sdk:dev-master
Or place it in your require section
{
"require": {
// ...
"corley/influxdb-sdk": "dev-master"
}
}
Prepare lib dependencies
Use your DiC or Service Locator in order to provide a configured client
<?php
use InfluxDB\Client;
use InfluxDB\Options;
use InfluxDB\Adapter\GuzzleAdapter as InfluxHttpAdapter;
use GuzzleHttp\Client as GuzzleHttpClient;
$options = new Options();
$options->setHost("analytics.mine.domain.tld");
$options->setPort(8086);
$options->setUsername("root");
$options->setPassword("root");
$options->setDatabase("mine");
$guzzleHttp = new GuzzleHttpClient();
$adapter = new InfluxHttpAdapter($guzzleHttp, $options);
$influx = new Client();
$influx->setAdapter($adapter);
$influx->mark("tcp.test", ["mark" => "element"]);
Languages
PHP
85.1%
JavaScript
6.6%
Blade
4.3%
CSS
1.8%
Python
1.1%
Other
1%