showclix / cube-php
Cube 的 PHP 客户端
0.1.3
2021-03-18 15:48 UTC
Requires
- php: >=5.3
- nategood/httpful: ~0.3
This package is not auto-updated.
Last update: 2024-09-13 07:56:19 UTC
README
支持与 Cube 收集器和评估器通信的 Cube 客户端。
使用方法
// Create a Client pointed at a local collector and evaluator $client = \Cube\Client::createHttpClient(array( 'collector' => array( 'host' => 'localhost', 'port' => 1080, ), 'evaluator' => array( 'host' => 'localhost', 'port' => 1081, ), 'secure' => true, )); $res = $client->metricGet(array( 'expression' => 'sum(cube_request)', 'step' => \Cube\Client::INT_ONE_MINUTE, 'limit' => 100, )); echo "There were {$res[0]['value']} hits during {$res[0]['time']}";
安装
通过 composer
composer.phar install showclix/cube-php
API
\Cube\Client
[静态] createHttpClient(array $conf)
参数 array $conf
配置数组。例如
array( 'collector' => array( 'host' => 'localhost', 'port' => 1080, ), 'evaluator' => array( 'host' => 'localhost', 'port' => 1081, ), 'secure' => true, )
返回 \Cube\Client
eventPut(array $event)
参数 array $event
要将到 cube 推送的事件。需要类型、时间和数据选项。
array( 'type' => 'example', 'time' => time(), 'data' => array( 'key' => 'value', ), )
返回来自 Cube 的数组响应
eventGet(array $query)
参数 array $query
返回数组
示例
$query = array( 'expression' => 'request.eq(path, "search")', // cube expression 'limit' => 10, // limit (optional) ); $client->metricGet($query);
metricGet(array $query)
参数 array $query 向 cube 评估器发送的度量查询
返回数组
示例
$query = array( 'expression' => 'sum(type_name)', // cube expression 'start' => strtotime('-1 day'), // start time (optional) 'stop' => time(), // end time (optional) 'limit' => 10, // limit (optional) 'step' => Client::INT_ONE_MINUTE, // time grouping interval ); $res = $client->metricGet($query); echo "There were {$res[0]['value']} during {$res[0]['time']}";
typesGet()
返回 cube 中当前所有类型的数组
待办事项
- 实现 \Cube\Connection\WebSocketConnection
- 实现 \Cube\Connection\UdpConnection
- 添加 Travis CI 集成,包括设置和安装 Cube/Mongo 的钩子