1
0
Fork 0
mirror of synced 2024-07-04 06:00:53 +12:00
appwrite/app/workers/usage.php

82 lines
2.5 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');
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
{
}
public function run(): 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
2021-04-01 23:59:11 +13:00
/** @var \Domnikl\Statsd\Client $statsd */
2020-07-06 07:46:04 +12:00
$statsd = $register->get('statsd', true);
2021-05-01 03:09:15 +12:00
$projectId = $this->args['projectId'] ?? '';
2020-07-21 22:33:23 +12:00
2021-05-01 03:09:15 +12:00
$storage = $this->args['storage'] ?? 0;
2020-07-21 22:33:23 +12:00
2021-04-01 23:59:11 +13:00
$networkRequestSize = $this->args['networkRequestSize'] ?? 0;
$networkResponseSize = $this->args['networkResponseSize'] ?? 0;
2020-07-20 18:43:25 +12:00
2021-05-01 03:09:15 +12:00
$httpMethod = $this->args['httpMethod'] ?? '';
$httpRequest = $this->args['httpRequest'] ?? 0;
2019-05-09 18:54:39 +12:00
2021-06-10 23:12:45 +12:00
$functionId = $this->args['functionId'] ?? '';
2021-05-01 03:09:15 +12:00
$functionExecution = $this->args['functionExecution'] ?? 0;
$functionExecutionTime = $this->args['functionExecutionTime'] ?? 0;
$functionStatus = $this->args['functionStatus'] ?? '';
2020-07-20 18:43:25 +12:00
$realtimeConnections = $this->args['realtimeConnections'] ?? 0;
$realtimeMessages = $this->args['realtimeMessages'] ?? 0;
2021-04-01 23:59:11 +13: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);
2020-07-20 18:43:25 +12:00
$statsd->count('executions.time'.$tags.',functionId='.$functionId, $functionExecutionTime);
}
2019-05-09 18:54:39 +12:00
2021-04-01 23:59:11 +13:00
if($realtimeConnections >= 1) {
$statsd->count('realtime.clients'.$tags, $realtimeConnections);
}
if($realtimeMessages >= 1) {
2021-06-10 23:12:45 +12:00
$statsd->count('realtime.messages'.$tags, $realtimeMessages);
2021-04-01 23:59:11 +13: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
{
}
}