2019-05-09 18:54:39 +12:00
|
|
|
<?php
|
|
|
|
|
2020-06-30 23:09:28 +12:00
|
|
|
use Utopia\App;
|
2020-05-10 04:39:50 +12:00
|
|
|
use Utopia\CLI\Console;
|
2020-03-29 01:42:16 +13:00
|
|
|
|
2019-09-07 05:08:48 +12:00
|
|
|
require_once __DIR__.'/../init.php';
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2020-06-20 23:20:49 +12:00
|
|
|
\cli_set_process_title('Usage V1 Worker');
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2020-05-10 04:39:50 +12:00
|
|
|
Console::success(APP_NAME.' usage worker v1 has started');
|
2019-05-09 18:54:39 +12:00
|
|
|
|
|
|
|
class UsageV1
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public $args = [];
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function perform()
|
|
|
|
{
|
2020-03-29 01:42:16 +13:00
|
|
|
global $register;
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2020-07-06 07:46:04 +12:00
|
|
|
$statsd = $register->get('statsd', true);
|
|
|
|
|
2019-09-07 05:08:48 +12:00
|
|
|
$projectId = $this->args['projectId'];
|
|
|
|
$method = $this->args['method'];
|
|
|
|
$request = $this->args['request'];
|
|
|
|
$response = $this->args['response'];
|
|
|
|
$storage = $this->args['storage'];
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2020-06-30 23:09:28 +12:00
|
|
|
$tags = ",project={$projectId},version=".App::getEnv('_APP_VERSION', 'UNKNOWN').'';
|
2019-05-09 18:54:39 +12:00
|
|
|
|
|
|
|
// the global namespace is prepended to every key (optional)
|
2019-09-07 05:08:48 +12:00
|
|
|
$statsd->setNamespace('appwrite.usage');
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2020-06-20 23:20:49 +12:00
|
|
|
$statsd->increment('requests.all'.$tags.',method='.\strtolower($method));
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2019-09-07 05:08:48 +12:00
|
|
|
$statsd->count('network.all'.$tags, $request + $response);
|
|
|
|
$statsd->count('network.inbound'.$tags, $request);
|
|
|
|
$statsd->count('network.outbound'.$tags, $response);
|
|
|
|
$statsd->count('storage.all'.$tags, $storage);
|
2019-05-09 18:54:39 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
// ... Remove environment for this job
|
|
|
|
}
|
2019-09-07 05:08:48 +12:00
|
|
|
}
|