1
0
Fork 0
mirror of synced 2024-05-21 05:02:37 +12:00
appwrite/app/workers/usage.php

67 lines
1.9 KiB
PHP
Raw Normal View History

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
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);
$projectId = $this->args['projectId'];
2020-07-20 18:43:25 +12:00
$httpMethod = $this->args['httpMethod'];
$httpRequest = $this->args['httpRequest'];
$networkRequestSize = $this->args['networkRequestSize'];
$networkResponseSize = $this->args['networkResponseSize'];
$storage = $this->args['storage'];
2019-05-09 18:54:39 +12:00
2020-07-20 18:43:25 +12:00
$functionExecution = $this->args['functionExecution'];
$functionExecutionTime = $this->args['functionExecutionTime'];
$functionId = $this->args['functionId'];
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)
$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) {
$statsd->increment('executions.all'.$tags.',functionId='.$functionId);
$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.all'.$tags, $networkRequestSize + $networkResponseSize);
$statsd->count('network.inbound'.$tags, $networkRequestSize);
$statsd->count('network.outbound'.$tags, $networkResponseSize);
$statsd->count('storage.all'.$tags, $storage);
2019-05-09 18:54:39 +12:00
}
public function tearDown()
{
// ... Remove environment for this job
}
}