示例#1
0
 public function testNewHttpClient()
 {
     $metrics = new Metrics('foo', 'bar');
     $request = $metrics->getRequest('foo', 'bar');
     $this->assertInstanceOf('\\HTTP_Request2', $request);
 }
示例#2
0
<?php

use Services\Librato\Metrics;
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 Delete all metrics which start with 'blah-foo-miss-'
 */
$filter = 'blah-foo-miss-';
while (true) {
    $gauges = $metrics->get();
    foreach ($gauges->metrics as $metric) {
        if (strpos($metric->name, $filter) === false) {
            continue;
        }
        echo "Deleting {$metric->name}" . PHP_EOL;
        if ($metrics->delete($metric->name) === false) {
            echo "Error deleting: {$metric->name}" . PHP_EOL;
            exit;
        }
    }
    echo "Still left: {$gauges->query->total}" . PHP_EOL;
    if ($gauges->query->total < 20) {
        break;
    }
}
示例#3
0
<?php

use Services\Librato\Metrics;
use Services\Librato\Metrics\Metric;
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 some metrics!
 */
$counter1 = new Metric('example-counter1');
$counter1->value = 1;
$counter1->source = 'test';
$counter2 = new Metric('example-counter2');
$counter2->value = 2;
$counter2->source = 'test';
$response = $metrics->update(array($counter1, $counter2));
var_dump($response);
<?php

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);