1
0
Fork 0
mirror of synced 2024-07-03 13:41:01 +12:00
appwrite/app/workers/usage.php

73 lines
2.1 KiB
PHP
Raw Normal View History

2019-05-09 18:54:39 +12:00
<?php
2021-03-10 21:08:17 +13:00
use Appwrite\Resque\Worker;
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
2021-03-25 01:13:59 +13:00
require_once __DIR__.'/../workers.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
2021-03-10 21:08:17 +13:00
class UsageV1 extends Worker
2019-05-09 18:54:39 +12:00
{
/**
* @var array
*/
public $args = [];
2021-03-10 21:08:17 +13:00
public function init(): void
2019-05-09 18:54:39 +12:00
{
}
2021-03-10 21:08:17 +13:00
public function execute(): void
2019-05-09 18:54:39 +12:00
{
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-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)
$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
}
2021-03-10 21:08:17 +13:00
public function shutdown(): void
2019-05-09 18:54:39 +12:00
{
}
}