summaryrefslogtreecommitdiff
path: root/src/Controllers
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-12-18 04:43:13 +0100
committermsquare <msquare@notrademark.de>2018-12-19 22:36:42 +0100
commit9a2f2465116387880282df505e3d3230516604dd (patch)
treed7003c84aa77a0578c4316708a673e6040665359 /src/Controllers
parentc5621b82cfeddee23b81871a53035fde747f73a9 (diff)
metrics: Added more stats
Diffstat (limited to 'src/Controllers')
-rw-r--r--src/Controllers/Metrics/Controller.php39
-rw-r--r--src/Controllers/Metrics/Stats.php132
2 files changed, 171 insertions, 0 deletions
diff --git a/src/Controllers/Metrics/Controller.php b/src/Controllers/Metrics/Controller.php
index 01fe1d6a..0fd26396 100644
--- a/src/Controllers/Metrics/Controller.php
+++ b/src/Controllers/Metrics/Controller.php
@@ -7,6 +7,7 @@ use Engelsystem\Controllers\BaseController;
use Engelsystem\Http\Exceptions\HttpForbidden;
use Engelsystem\Http\Request;
use Engelsystem\Http\Response;
+use Psr\Log\LogLevel;
class Controller extends BaseController
{
@@ -62,6 +63,15 @@ class Controller extends BaseController
['labels' => ['state' => 'arrived', 'working' => 'no'], 'value' => $this->stats->arrivedUsers(false)],
['labels' => ['state' => 'arrived', 'working' => 'yes'], 'value' => $this->stats->arrivedUsers(true)],
],
+ 'licenses' => [
+ 'type' => 'gauge',
+ 'help' => 'The total number of licenses',
+ ['labels' => ['type' => 'forklift'], 'value' => $this->stats->licenses('forklift')],
+ ['labels' => ['type' => 'car'], 'value' => $this->stats->licenses('car')],
+ ['labels' => ['type' => '3.5t'], 'value' => $this->stats->licenses('3.5t')],
+ ['labels' => ['type' => '7.5t'], 'value' => $this->stats->licenses('7.5t')],
+ ['labels' => ['type' => '12.5t'], 'value' => $this->stats->licenses('12.5t')],
+ ],
'users_working' => [
'type' => 'gauge',
['labels' => ['freeloader' => false], $this->stats->currentlyWorkingUsers(false)],
@@ -73,7 +83,36 @@ class Controller extends BaseController
['labels' => ['state' => 'planned'], 'value' => $this->stats->workSeconds(false, false)],
['labels' => ['state' => 'freeloaded'], 'value' => $this->stats->workSeconds(null, true)],
],
+ 'worklog_seconds' => ['type' => 'gauge', $this->stats->worklogSeconds()],
+ 'shifts' => ['type' => 'gauge', $this->stats->shifts()],
+ 'announcements' => [
+ 'type' => 'gauge',
+ ['labels' => ['type' => 'news'], 'value' => $this->stats->announcements(false)],
+ ['labels' => ['type' => 'meeting'], 'value' => $this->stats->announcements(true)],
+ ],
+ 'questions' => [
+ 'type' => 'gauge',
+ ['labels' => ['answered' => true], 'value' => $this->stats->questions(true)],
+ ['labels' => ['answered' => false], 'value' => $this->stats->questions(false)],
+ ],
+ 'messages' => ['type' => 'gauge', $this->stats->messages()],
+ 'password_resets' => ['type' => 'gauge', $this->stats->passwordResets()],
'registration_enabled' => ['type' => 'gauge', $this->config->get('registration_enabled')],
+ 'sessions' => ['type' => 'gauge', $this->stats->sessions()],
+ 'log_entries' => [
+ 'type' => 'counter',
+ [
+ 'labels' => ['level' => LogLevel::EMERGENCY],
+ 'value' => $this->stats->logEntries(LogLevel::EMERGENCY)
+ ],
+ ['labels' => ['level' => LogLevel::ALERT], 'value' => $this->stats->logEntries(LogLevel::ALERT)],
+ ['labels' => ['level' => LogLevel::CRITICAL], 'value' => $this->stats->logEntries(LogLevel::CRITICAL)],
+ ['labels' => ['level' => LogLevel::ERROR], 'value' => $this->stats->logEntries(LogLevel::ERROR)],
+ ['labels' => ['level' => LogLevel::WARNING], 'value' => $this->stats->logEntries(LogLevel::WARNING)],
+ ['labels' => ['level' => LogLevel::NOTICE], 'value' => $this->stats->logEntries(LogLevel::NOTICE)],
+ ['labels' => ['level' => LogLevel::INFO], 'value' => $this->stats->logEntries(LogLevel::INFO)],
+ ['labels' => ['level' => LogLevel::DEBUG], 'value' => $this->stats->logEntries(LogLevel::DEBUG)],
+ ],
];
$data['scrape_duration_seconds'] = [
diff --git a/src/Controllers/Metrics/Stats.php b/src/Controllers/Metrics/Stats.php
index 891f8c80..838411d1 100644
--- a/src/Controllers/Metrics/Stats.php
+++ b/src/Controllers/Metrics/Stats.php
@@ -97,6 +97,31 @@ class Stats
}
/**
+ * @param string $vehicle
+ * @return int
+ * @codeCoverageIgnore
+ */
+ public function licenses($vehicle = null)
+ {
+ $mapping = [
+ 'forklift' => 'has_license_forklift',
+ 'car' => 'has_license_car',
+ '3.5t' => 'has_license_3_5t_transporter',
+ '7.5t' => 'has_license_7_5t_truck',
+ '12.5t' => 'has_license_12_5t_truck',
+ ];
+
+ $query = $this
+ ->getQuery('UserDriverLicenses');
+
+ if (!is_null($vehicle)) {
+ $query->where($mapping[$vehicle], '=', true);
+ }
+
+ return $query->count();
+ }
+
+ /**
* The number of worked shifts
*
* @param bool|null $done
@@ -122,6 +147,113 @@ class Stats
}
/**
+ * @return int
+ * @codeCoverageIgnore
+ */
+ public function worklogSeconds()
+ {
+ return round($this
+ ->getQuery('UserWorkLog')
+ ->sum($this->raw('work_hours * 60*60')));
+ }
+
+ /**
+ * @return int
+ * @codeCoverageIgnore
+ */
+ public function shifts()
+ {
+ return $this
+ ->getQuery('Shifts')
+ ->count();
+ }
+
+ /**
+ * @param bool $meeting
+ * @return int
+ * @codeCoverageIgnore
+ */
+ public function announcements($meeting = null)
+ {
+ $query = $this
+ ->getQuery('News');
+
+ if (!is_null($meeting)) {
+ $query->where('Treffen', '=', $meeting);
+ }
+
+ return $query->count();
+ }
+
+ /**
+ * @param bool $answered
+ * @return int
+ * @codeCoverageIgnore
+ */
+ public function questions($answered = null)
+ {
+ $query = $this
+ ->getQuery('Questions');
+
+ if (!is_null($answered)) {
+ if ($answered) {
+ $query->whereNotNull('AID');
+ } else {
+ $query->whereNull('AID');
+ }
+ }
+
+ return $query->count();
+ }
+
+ /**
+ * @return int
+ * @codeCoverageIgnore
+ */
+ public function messages()
+ {
+ return $this
+ ->getQuery('Messages')
+ ->count();
+ }
+
+ /**
+ * @return int
+ */
+ public function sessions()
+ {
+ return $this
+ ->getQuery('sessions')
+ ->count();
+ }
+
+ /**
+ * @param string $level
+ * @return int
+ */
+ public function logEntries($level = null)
+ {
+ $query = $this
+ ->getQuery('log_entries');
+
+ if (!is_null($level)) {
+ $query->where('level', '=', $level);
+ }
+
+ return $query->count();
+ }
+
+ /**
+ * @return int
+ */
+ public function passwordResets()
+ {
+ return $this
+ ->getQuery('password_resets')
+ ->count();
+ }
+
+ /**
* @param string $table
* @return QueryBuilder
*/