From f41d388bf50669b78a562b9c6bfbb31065a24e2b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Mon, 10 Oct 2022 09:13:20 +0000 Subject: [PATCH] separate cumulative metrics --- src/Appwrite/Usage/Calculators/TimeSeries.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Appwrite/Usage/Calculators/TimeSeries.php b/src/Appwrite/Usage/Calculators/TimeSeries.php index 8d5f0f0d73..dc77f94098 100644 --- a/src/Appwrite/Usage/Calculators/TimeSeries.php +++ b/src/Appwrite/Usage/Calculators/TimeSeries.php @@ -319,6 +319,22 @@ class TimeSeries extends Calculator ], ]; + protected array $cumulativeMetrics = [ + 'deployments.$all.storage.size' => [ + 'table' => 'appwrite_usage_deployments_{scope}_storage_size', + ], + 'project.$all.storage.size' => [ + 'table' => 'appwrite_usage_project_{scope}_storage_size', + ], + 'files.$all.storage.size' => [ + 'table' => 'appwrite_usage_files_{scope}_storage_size', + ], + 'files.$bucketId.storage.size' => [ + 'table' => 'appwrite_usage_files_{scope}_storage_size', + 'groupBy' => ['bucketId'] + ], + ]; + public function __construct(Database $database, InfluxDatabase $influxDB, callable $errorHandler = null) { $this->database = $database; @@ -469,5 +485,18 @@ class TimeSeries extends Calculator } } + // for cumulative metrics only get hourly metrics from timeseries + foreach ($this->cumulativeMetrics as $metric => $options) { + try { + $this->syncFromInfluxDB($metric, $options, $this->periods[0]); + } catch (\Exception $e) { + if (is_callable($this->errorHandler)) { + call_user_func($this->errorHandler, $e); + } else { + throw $e; + } + } + } + } }