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
|
|
|
|
2021-01-15 19:02:48 +13:00
|
|
|
Console::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 = [];
|
|
|
|
|
2020-10-01 11:01:25 +13:00
|
|
|
public function setUp(): void
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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'];
|
2020-07-21 22:33:23 +12:00
|
|
|
|
|
|
|
$storage = $this->args['storage'];
|
|
|
|
|
2020-07-20 18:43:25 +12:00
|
|
|
$networkRequestSize = $this->args['networkRequestSize'];
|
|
|
|
$networkResponseSize = $this->args['networkResponseSize'];
|
|
|
|
|
2020-07-21 22:33:23 +12:00
|
|
|
$httpMethod = $this->args['httpMethod'];
|
|
|
|
$httpRequest = $this->args['httpRequest'];
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2020-07-21 22:33:23 +12:00
|
|
|
$functionId = $this->args['functionId'];
|
2020-07-20 18:43:25 +12:00
|
|
|
$functionExecution = $this->args['functionExecution'];
|
|
|
|
$functionExecutionTime = $this->args['functionExecutionTime'];
|
2020-07-24 02:59:44 +12:00
|
|
|
$functionStatus = $this->args['functionStatus'];
|
2020-07-20 18:43:25 +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-07-20 18:43:25 +12:00
|
|
|
if($httpRequest >= 1) {
|
|
|
|
$statsd->increment('requests.all'.$tags.',method='.\strtolower($httpMethod));
|
|
|
|
}
|
|
|
|
|
|
|
|
if($functionExecution >= 1) {
|
2020-07-24 02:59:44 +12:00
|
|
|
$statsd->increment('executions.all'.$tags.',functionId='.$functionId.',functionStatus='.$functionStatus);
|
|
|
|
var_dump($tags.',functionId='.$functionId.',functionStatus='.$functionStatus);
|
2020-07-20 18:43:25 +12:00
|
|
|
$statsd->count('executions.time'.$tags.',functionId='.$functionId, $functionExecutionTime);
|
|
|
|
}
|
2019-05-09 18:54:39 +12:00
|
|
|
|
2020-07-20 18:43:25 +12:00
|
|
|
$statsd->count('network.inbound'.$tags, $networkRequestSize);
|
|
|
|
$statsd->count('network.outbound'.$tags, $networkResponseSize);
|
2020-07-21 22:33:23 +12:00
|
|
|
$statsd->count('network.all'.$tags, $networkRequestSize + $networkResponseSize);
|
|
|
|
|
|
|
|
if($storage >= 1) {
|
|
|
|
$statsd->count('storage.all'.$tags, $storage);
|
|
|
|
}
|
2019-05-09 18:54:39 +12:00
|
|
|
}
|
|
|
|
|
2020-10-01 11:01:25 +13:00
|
|
|
public function tearDown(): void
|
2019-05-09 18:54:39 +12:00
|
|
|
{
|
|
|
|
// ... Remove environment for this job
|
|
|
|
}
|
2019-09-07 05:08:48 +12:00
|
|
|
}
|