danibrutal / kairosdb-client
A client library for KairosDB written in PHP
Installs: 1 667
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 3
Open Issues: 0
Requires
- guzzlehttp/guzzle: ^6.0
This package is not auto-updated.
Last update: 2024-12-25 11:23:04 UTC
README
Description
A client library for KairosDB written in PHP. This package provides convenience functions to read and write time series data. It uses the HTTP protocol to communicate with your KairosDB cluster.
Getting Started
Install (Composer)
$ composer require 'danibrutal/kairosdb-client:dev-master'
Connecting To Your Database
Connecting to an KairosDB database is straightforward. You will need a host name a port. The default port is 8080.
For more information please check out the KairosDB Docs.
Inserting Data
We can add a single data point:
require 'vendor/autoload.php'; $client = new KairosDB\Client('localhost', 8090); $tags = ['host'=> 'precise64']; $metricName = 'network_out'; for($i=2; $i<100; $i++) { $dataPointValue = $i *2; $client->addDataPoint($metricName, $dataPointValue, $tags); usleep(100); }
Or using batch inserts:
require 'vendor/autoload.php'; $client = new \KairosDB\Client('localhost', 8090); $tags = ['host'=> 'precise64']; $metricName = 'network_out'; $dataPointCollection = new \KairosDB\DataPointCollection($metricName, $tags); for($i=2; $i<100; $i++) { $dataPointValue = $i *2; $dataPointCollection->addPoint($dataPointValue); usleep(100); } $client->addDataPoints($dataPointCollection);
Querying Data Points
The start date is required, but the end date defaults to NOW if not specified. The metric(s) that you are querying for is also required. Optionally, tags may be added to narrow down the search.
require 'vendor/autoload.php'; $client = new KairosDB\Client('localhost', 8090); $queryBuilder = new \KairosDB\QueryBuilder(); $tags = ['host'=> 'precise64']; $query = $queryBuilder ->start(['value'=> '1', 'unit' => 'days']) ->cache(10) ->addMetric('network_in') ->tags($tags) ->build(); $results = $client->query($query);
Querying Metric Names
You can get a list of all metric names in KairosDB.
require 'vendor/autoload.php'; $client = new KairosDB\Client('localhost', 8090); $results = $client->getMetricNames($query);
Querying Tag Names
Similarly you can get a list of all tag names in KairosDB.
require 'vendor/autoload.php'; $client = new KairosDB\Client('localhost', 8090); $results = $client->getTagNames($query);
Querying Tag Values
And a list of all tag values.
require 'vendor/autoload.php'; $client = new KairosDB\Client('localhost', 8090); $results = $client->getTagValues($query);
Custom Data Types
TODO: implement
KairosDB Docs
Please refer to http://kairosdb.github.io/kairosdocs/ for documentation.