Merge pull request #817 from lohanidamodar/feat-disable-usage-stats
Feat disable usage stats
This commit is contained in:
commit
bce0933cc2
13 changed files with 194 additions and 159 deletions
1
.env
1
.env
|
@ -35,3 +35,4 @@ _APP_FUNCTIONS_MEMORY=128
|
|||
_APP_FUNCTIONS_MEMORY_SWAP=128
|
||||
_APP_MAINTENANCE_INTERVAL=86400
|
||||
_APP_SYSTEM_RESPONSE_FORMAT=
|
||||
_APP_USAGE_STATS=enabled
|
|
@ -99,6 +99,7 @@ ENV _APP_SERVER=swoole \
|
|||
_APP_FUNCTIONS_MEMORY_SWAP=128 \
|
||||
_APP_SETUP=self-hosted \
|
||||
_APP_VERSION=$VERSION \
|
||||
_APP_USAGE_STATS=enabled \
|
||||
# 1 Day = 86400 s
|
||||
_APP_MAINTENANCE_INTERVAL=86400
|
||||
#ENV _APP_SMTP_SECURE ''
|
||||
|
|
|
@ -93,6 +93,14 @@ return [
|
|||
'required' => false,
|
||||
'question' => '',
|
||||
],
|
||||
[
|
||||
'name' => '_APP_USAGE_STATS',
|
||||
'description' => 'This variable allows you to disable the collection and displaying of usage stats. This value is set to \'enabled\' by default, to disable the usage stats set the value to \'disabled\'. When disabled, it\'s recommended to turn off the Worker Usage, Influxdb and Telegraf containers for better resource usage.',
|
||||
'introduction' => '0.7.0',
|
||||
'default' => 'enabled',
|
||||
'required' => false,
|
||||
'question' => '',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
|
|
|
@ -157,6 +157,7 @@ App::get('/v1/functions/:functionId/usage')
|
|||
throw new Exception('Function not found', 404);
|
||||
}
|
||||
|
||||
if($App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
|
||||
$period = [
|
||||
'24h' => [
|
||||
'start' => DateTime::createFromFormat('U', \strtotime('-24 hours')),
|
||||
|
@ -246,6 +247,9 @@ App::get('/v1/functions/:functionId/usage')
|
|||
}, $compute)),
|
||||
],
|
||||
]);
|
||||
} else {
|
||||
$response->json([]);
|
||||
}
|
||||
});
|
||||
|
||||
App::put('/v1/functions/:functionId')
|
||||
|
|
|
@ -176,6 +176,8 @@ App::get('/v1/projects/:projectId/usage')
|
|||
throw new Exception('Project not found', 404);
|
||||
}
|
||||
|
||||
if(App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
|
||||
|
||||
$period = [
|
||||
'24h' => [
|
||||
'start' => DateTime::createFromFormat('U', \strtotime('-24 hours')),
|
||||
|
@ -243,6 +245,12 @@ App::get('/v1/projects/:projectId/usage')
|
|||
];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$requests = [];
|
||||
$network = [];
|
||||
$functions = [];
|
||||
}
|
||||
|
||||
|
||||
// Users
|
||||
|
||||
|
|
|
@ -309,8 +309,8 @@ App::shutdown(function ($utopia, $request, $response, $project, $events, $audits
|
|||
}
|
||||
|
||||
$route = $utopia->match($request);
|
||||
|
||||
if ($project->getId()
|
||||
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled'
|
||||
&& $project->getId()
|
||||
&& $mode !== APP_MODE_ADMIN //TODO: add check to make sure user is admin
|
||||
&& !empty($route->getLabel('sdk.namespace', null))) { // Don't calculate console usage on admin mode
|
||||
|
||||
|
|
|
@ -122,7 +122,8 @@ App::get('/console/home')
|
|||
/** @var Utopia\View $layout */
|
||||
|
||||
$page = new View(__DIR__.'/../../views/console/home/index.phtml');
|
||||
|
||||
$page
|
||||
->setParam('usageStatsEnabled',App::getEnv('_APP_USAGE_STATS','enabled') == 'enabled');
|
||||
$layout
|
||||
->setParam('title', APP_NAME.' - Console')
|
||||
->setParam('body', $page);
|
||||
|
@ -390,6 +391,7 @@ App::get('/console/functions/function')
|
|||
->setParam('fileLimit', App::getEnv('_APP_STORAGE_LIMIT', 0))
|
||||
->setParam('fileLimitHuman', Storage::human(App::getEnv('_APP_STORAGE_LIMIT', 0)))
|
||||
->setParam('timeout', (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900))
|
||||
->setParam('usageStatsEnabled',App::getEnv('_APP_USAGE_STATS','enabled') == 'enabled');
|
||||
;
|
||||
|
||||
$layout
|
||||
|
|
|
@ -3,6 +3,7 @@ $fileLimit = $this->getParam('fileLimit', 0);
|
|||
$fileLimitHuman = $this->getParam('fileLimitHuman', 0);
|
||||
$events = array_keys($this->getParam('events', []));
|
||||
$timeout = $this->getParam('timeout', 900);
|
||||
$usageStatsEnabled = $this->getParam('usageStatsEnabled',true);
|
||||
?>
|
||||
<div
|
||||
data-service="functions.get"
|
||||
|
@ -240,6 +241,7 @@ $timeout = $this->getParam('timeout', 900);
|
|||
</div>
|
||||
</div>
|
||||
</li>
|
||||
<?php if($usageStatsEnabled): ?>
|
||||
<li data-state="/console/functions/function/monitors?id={{router.params.id}}&project={{router.params.project}}">
|
||||
|
||||
<form class="pull-end margin-start-small margin-top-small" data-ls-if="{{usage.range}} !== '90d'"
|
||||
|
@ -318,6 +320,7 @@ $timeout = $this->getParam('timeout', 900);
|
|||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<li data-state="/console/functions/function/logs?id={{router.params.id}}&project={{router.params.project}}">
|
||||
|
||||
<div class="text-fade text-size-small pull-end margin-top" data-ls-bind="{{project-function-executions.sum}} executions found"></div>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
$graph = $this->getParam('graph', false);
|
||||
$usageStatsEnabled = $this->getParam('usageStatsEnabled',true);
|
||||
?>
|
||||
|
||||
<div class="cover margin-bottom-small">
|
||||
|
@ -68,7 +69,7 @@ $graph = $this->getParam('graph', false);
|
|||
data-param-project-id="{{router.params.project}}"
|
||||
data-param-range="30d">
|
||||
|
||||
<?php if (!$graph) : ?>
|
||||
<?php if (!$graph && $usageStatsEnabled): ?>
|
||||
<div class="box dashboard">
|
||||
<div class="row responsive">
|
||||
<div class="col span-9">
|
||||
|
|
|
@ -76,6 +76,7 @@ services:
|
|||
- _APP_SMTP_SECURE
|
||||
- _APP_SMTP_USERNAME
|
||||
- _APP_SMTP_PASSWORD
|
||||
- _APP_USAGE_STATS
|
||||
- _APP_INFLUXDB_HOST
|
||||
- _APP_INFLUXDB_PORT
|
||||
- _APP_STORAGE_LIMIT
|
||||
|
@ -239,6 +240,7 @@ services:
|
|||
- _APP_FUNCTIONS_CPUS
|
||||
- _APP_FUNCTIONS_MEMORY
|
||||
- _APP_FUNCTIONS_MEMORY_SWAP
|
||||
- _APP_USAGE_STATS
|
||||
|
||||
appwrite-worker-mails:
|
||||
image: appwrite/appwrite:<?php echo $version."\n"; ?>
|
||||
|
|
|
@ -471,7 +471,9 @@ class FunctionsV1
|
|||
->setParam('networkResponseSize', 0)
|
||||
;
|
||||
|
||||
if($App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {
|
||||
$usage->trigger();
|
||||
}
|
||||
|
||||
$this->cleanup();
|
||||
}
|
||||
|
|
|
@ -100,6 +100,7 @@ services:
|
|||
- _APP_SMTP_SECURE
|
||||
- _APP_SMTP_USERNAME
|
||||
- _APP_SMTP_PASSWORD
|
||||
- _APP_USAGE_STATS
|
||||
- _APP_INFLUXDB_HOST
|
||||
- _APP_INFLUXDB_PORT
|
||||
- _APP_STORAGE_LIMIT
|
||||
|
@ -292,6 +293,7 @@ services:
|
|||
- _APP_FUNCTIONS_CPUS
|
||||
- _APP_FUNCTIONS_MEMORY
|
||||
- _APP_FUNCTIONS_MEMORY_SWAP
|
||||
- _APP_USAGE_STATS
|
||||
|
||||
appwrite-worker-mails:
|
||||
entrypoint: worker-mails
|
||||
|
|
|
@ -78,6 +78,7 @@ services:
|
|||
- _APP_DB_SCHEMA
|
||||
- _APP_DB_USER
|
||||
- _APP_DB_PASS
|
||||
- _APP_USAGE_STATS
|
||||
- _APP_INFLUXDB_HOST
|
||||
- _APP_INFLUXDB_PORT
|
||||
- _APP_STORAGE_LIMIT
|
||||
|
|
Loading…
Reference in a new issue