Пример #1
0
 public function testCounter()
 {
     $counter = new Metric('example.counter');
     $counter->value = 1;
     $counter->measure_time = 1332848921;
     $collection = new Counters();
     $collection->accept($counter);
     $this->assertEquals('{"counters":[{"name":"example.counter","value":1,"measure_time":1332848921}]}', $collection->toJson());
 }
 public function testToArray()
 {
     $counter = new Metric('example.counter');
     $counter->value = 1;
     $counter->measure_time = 1332848921;
     $counters = new Counters();
     $counters->accept($counter);
     $gauge = new Metric('some.gauge');
     $gauge->value = 1;
     $gauge->measure_time = 1332848921;
     $gauges = new Gauges();
     $gauges->accept($gauge);
     $superCollection = new SuperCollection();
     $superCollection->accept($gauges)->accept($counters);
     $payLoad = $superCollection->toArray();
     //var_dump(json_encode($payLoad));
     $this->markTestIncomplete("Not done yet!");
 }
use Services\Librato\Metrics;
use Services\Librato\Metrics\Metric;
use Services\Librato\Metrics\Counters;
use Services\Librato\Metrics\Gauges;
use Services\Librato\Metrics\SuperCollection;
require './autoload.php';
if (!file_exists(__DIR__ . '/config.php')) {
    die("No config - check out config.php-dist!");
}
$config = (include __DIR__ . '/config.php');
$metrics = new Metrics($config->user, $config->apiKey);
/**
 * @desc Publish metrics of different types: counters and gauges.
 */
$counter1 = new Metric('example-counter1');
$counter1->value = 1;
$counter1->source = 'test';
$counter2 = new Metric('example-counter2');
$counter2->value = 2;
$counter2->source = 'test';
$counters = new Counters();
$counters->accept($counter1)->accept($counter2);
$gauge = new Metric('example-gauge');
$gauge->value = rand(1, 10);
$gauges = new Gauges();
$gauges->accept($gauge);
$collection = new SuperCollection();
$collection->accept($counters)->accept($gauges);
$response = $metrics->update($collection);
var_dump($response);