Skip to content

Latest commit

 

History

History
90 lines (67 loc) · 2.44 KB

index.md

File metadata and controls

90 lines (67 loc) · 2.44 KB

CubeBundle

Introduction

CubeBundle allows you to integrate the library ShowClix/cube-php in your Symfony2 application and interact with Cube collectors and evaluators.

Installation

Installation is done through composer

composer require lmammino/cube-bundle

or add the package to your composer.json directly.

Note that this bundle is in a very early stage and a stable version is not yet available.

After you have installed the package, you just need to add the bundle to your AppKernel.php file:

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new Cube\Bundle\CubeBundle\CubeBundle(),
    // ...
);

Configuration

Cube Bundle configuration adopts sensible defaults that should be fine in most of cases. If your cube collector and evaluator run in localhost and uses their default ports you are ready to go yet. Otherwise, you need to define a cube configuration block in your config.yml:

cube:
    collector:
        host: <collector_host> #default: localhost
        port: <collector_port> #default: 1080
    evaluator:
        host: <evaluator_host> #default: localhost
        port: <evaluator_port> #default: 1081

You can achieve a finer level of configuration if needed, for example you can also define many clients (collectors/evaluators) couples if you use more than once. For all available configuration options, please see the configuration reference.

Usage

The configured cube client is available as cube_client service. You can easily inject it in other services or fetch it within your controller actions.

Register an event

With the following snippet you can send a new event to the cube collector:

client = $this->get('cube_client');

$client->eventPut(array(
    'type' => 'example',
    'time' => time(),
    'data' => array(
        'key1' => 'value1',
    ),
));

Read data from the evaluator

With the following snippet you can read data from the cube evaluator:

client = $this->get('cube_client');

$events = $client->metricGet(array(
    'expression' => 'sum(cube_request)',
    'step' => \Cube\Client::INT_ONE_MINUTE,
    'limit' => 100,
));

foreach ($event in $events) {
    echo "There were {$event['value']} hits during {$event['time']} \n";
}

License

The code is released under the MIT license.