diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Controllers/Metrics/Controller.php | 5 | ||||
-rw-r--r-- | src/Controllers/Metrics/Stats.php | 31 | ||||
-rw-r--r-- | src/Models/EventConfig.php | 1 |
3 files changed, 37 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 */ diff --git a/src/Models/EventConfig.php b/src/Models/EventConfig.php index 576a8f0e..2dc6a3d8 100644 --- a/src/Models/EventConfig.php +++ b/src/Models/EventConfig.php @@ -35,6 +35,7 @@ class EventConfig extends BaseModel 'event_start' => 'date', 'event_end' => 'date', 'teardown_end' => 'date', + 'last_metrics' => 'datetime', ]; /** @var bool It could be interesting to know when a value changed the last time */ |