From efaf29e5ef020694849039713afa0027f92f6bbe Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 21 Aug 2019 14:22:31 +0200 Subject: Metrics: Add database access time --- src/Controllers/Metrics/Stats.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/Controllers/Metrics/Stats.php') diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php index a2b37d0c..7098d94f 100644 --- a/src/Controllers/Metrics/Stats.php +++ b/src/Controllers/Metrics/Stats.php @@ -2,7 +2,9 @@ namespace Engelsystem\Controllers\Metrics; +use Carbon\Carbon; use Engelsystem\Database\Database; +use Engelsystem\Models\EventConfig; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Expression as QueryExpression; @@ -262,6 +264,35 @@ class Stats ->count(); } + /** + * @return float + */ + public function databaseRead() + { + $start = microtime(true); + + EventConfig::findOrNew('last_metrics'); + + return microtime(true) - $start; + } + + /** + * @return float + */ + public function databaseWrite() + { + $config = EventConfig::findOrNew('last_metrics'); + $config + ->setAttribute('name', 'last_metrics') + ->setAttribute('value', new Carbon()); + + $start = microtime(true); + + $config->save(); + + return microtime(true) - $start; + } + /** * @param string $level * @return int -- cgit v1.2.3-70-g09d2