till/services_librato

PHP API wrapper for Librato's metric service

1.0.0-alpha1 2012-10-23 16:25 UTC

This package is auto-updated.

Last update: 2024-04-11 12:59:53 UTC


README

This is a work in progress where we implement the Librato API as we move forward.

Current work in progress: Services\Librato\Metrics:

  • delete metrics
  • publish metrics
  • get metrics

Services\Librato\Metrics

The most interesting bit is publishing metrics. Currently, you can public an individual metric, or multiple.

A metric is created with the following code:

<?php
use Services\Librato\Metrics\Metric;
$metric         = new Metric('counter);
$metric->value  = 1;
$metric->source = 'production'; // this is optional

By default my code assumes 'gauges', so in order to send a counter, you'll have to do the following:

<?php
use Services\Librato\Metrics;
use Services\Librato\Metrics\Counters;
// create metric

$counters = new Counters();
$counters->accept($metric);

$metrics = new Metrics('youremail', 'yourapikey');
var_dump($metrics->update($counters)); // should output 'true'

If you'd like to mix counters and gauges and submit them in one request (preferrable :)) use a SuperCollection:

<?php
use Services\Librato\Metrics;
use Services\Librato\Metrics\Counters;
use Services\Librato\Metrics\Gauges;
use Services\Librato\Metrics\SuperCollection;

// create metrics
$counters = new Counters;
$counters->accept($metric);

$gauges = new Gauges;
$gauges->accept($anotherMetric);

$collection = new SuperCollection;
$collection->accept($counters)->accept($gauges);

$metrics = new Metrics('youremail', 'yourapikey');
var_dump($metrics->update($counters)); // should output 'true'

For more, check out the examples directory!

Services\Librato\Annotations

One can also create and retrieve annotations. Here is an example:

<?php
use Services\Librato\Annotations;
$annotations = new Annotations($user, $apiKey);
$annotations->create('streamName', 'title', 'source', 'desc', time() - 60, time() - 5);

License

New BSD License.