diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2019-08-21 14:22:31 +0200 |
---|---|---|
committer | Igor Scheller <igor.scheller@igorshp.de> | 2019-08-21 14:22:31 +0200 |
commit | efaf29e5ef020694849039713afa0027f92f6bbe (patch) | |
tree | fd96fcd0f460a180e2399a7de2174cee86faaf00 /src/Controllers | |
parent | 4d4fb81cd3dbe276f684feecd03c8fc49c700df0 (diff) |
Metrics: Add database access time
Diffstat (limited to 'src/Controllers')
-rw-r--r-- | src/Controllers/Metrics/Controller.php | 5 | ||||
-rw-r--r-- | src/Controllers/Metrics/Stats.php | 31 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php index ffb2a41b..99b71335 100644 --- a/src/Controllers/Metrics/Controller.php +++ b/src/Controllers/Metrics/Controller.php @@ -131,6 +131,11 @@ class Controller extends BaseController 'messages' => ['type' => 'gauge', $this->stats->messages()], 'password_resets' => ['type' => 'gauge', $this->stats->passwordResets()], 'registration_enabled' => ['type' => 'gauge', $this->config->get('registration_enabled')], + 'database' => [ + 'type' => 'gauge', + ['labels' => ['type' => 'read'], 'value' => $this->stats->databaseRead()], + ['labels' => ['type' => 'write'], 'value' => $this->stats->databaseWrite()], + ], 'sessions' => ['type' => 'gauge', $this->stats->sessions()], 'log_entries' => [ 'type' => 'counter', 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; @@ -263,6 +265,35 @@ class Stats } /** + * @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 */ |