mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
infinity daily metric
This commit is contained in:
@@ -75,7 +75,7 @@ _APP_MAINTENANCE_RETENTION_CACHE=2592000
|
||||
_APP_MAINTENANCE_RETENTION_EXECUTION=1209600
|
||||
_APP_MAINTENANCE_RETENTION_ABUSE=86400
|
||||
_APP_MAINTENANCE_RETENTION_AUDIT=1209600
|
||||
_APP_USAGE_AGGREGATION_INTERVAL=5
|
||||
_APP_USAGE_AGGREGATION_INTERVAL=50000
|
||||
_APP_MAINTENANCE_RETENTION_USAGE_HOURLY=8640000
|
||||
_APP_MAINTENANCE_RETENTION_SCHEDULES=86400
|
||||
_APP_USAGE_STATS=enabled
|
||||
|
||||
@@ -673,6 +673,7 @@ services:
|
||||
- _APP_USAGE_STATS
|
||||
- _APP_LOGGING_PROVIDER
|
||||
- _APP_LOGGING_CONFIG
|
||||
- _APP_USAGE_AGGREGATION_INTERVAL
|
||||
|
||||
appwrite-schedule:
|
||||
entrypoint: schedule
|
||||
|
||||
@@ -15,7 +15,8 @@ class Usage extends Action
|
||||
protected array $periods = [
|
||||
'1h' => 'Y-m-d H:00',
|
||||
'1d' => 'Y-m-d 00:00',
|
||||
'inf' => '0000-00-00 00:00'
|
||||
'inf' => '0000-00-00 00:00',
|
||||
'inf_d' => 'Y-m-d 00:00',
|
||||
];
|
||||
|
||||
protected const INFINITY_PERIOD = '_inf_';
|
||||
|
||||
@@ -39,7 +39,8 @@ class UsageHook extends Usage
|
||||
*/
|
||||
public function action($register, $cache, $pools): void
|
||||
{
|
||||
Timer::tick(30000, function () use ($register, $cache, $pools) {
|
||||
$interval = (int) App::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', '50000');
|
||||
Timer::tick($interval, function () use ($register, $cache, $pools) {
|
||||
|
||||
$offset = count(self::$stats);
|
||||
$projects = array_slice(self::$stats, 0, $offset, true);
|
||||
@@ -66,6 +67,30 @@ class UsageHook extends Usage
|
||||
$time = 'inf' === $period ? null : date($format, time());
|
||||
$id = \md5("{$time}_{$period}_{$key}");
|
||||
|
||||
/**
|
||||
* Infinity daily
|
||||
*/
|
||||
if ('inf_d' === $period) {
|
||||
$infinity = $dbForProject->getDocument('stats', \md5("{self::INFINITY_PERIOD}{$key}"));
|
||||
$infinityDaily = $dbForProject->getDocument('stats', $id);
|
||||
|
||||
if (empty($infinityDaily) && $infinityDaily->isEmpty()) {
|
||||
$dbForProject->createDocument('stats', new Document([
|
||||
'$id' => $id,
|
||||
'period' => $period,
|
||||
'time' => $time,
|
||||
'metric' => $key,
|
||||
'value' => $infinity['value'],
|
||||
'region' => App::getEnv('_APP_REGION', 'default'),
|
||||
]));
|
||||
} else {
|
||||
$infinityDaily->setAttribute('value', $infinity['value']);
|
||||
$dbForProject->updateDocument('stats', $infinityDaily->getId(), $infinityDaily);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
$dbForProject->createDocument('stats', new Document([
|
||||
'$id' => $id,
|
||||
|
||||
Reference in New Issue
Block a user