diff --git a/app/Http/Controllers/AdminInterface.php b/app/Http/Controllers/AdminInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..b0d2117a644121d973a573c21d6aa7756c7589a6 --- /dev/null +++ b/app/Http/Controllers/AdminInterface.php @@ -0,0 +1,31 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; + +use App\Http\Requests; +use Redis; + +class AdminInterface extends Controller +{ + public function index () + { + # Zunächst einmal die Redis-Verbindung: + $redis = Redis::connection('redisLogs'); + + # Dann lesen wir alle Server aus: + $member = $redis->smembers('logs.worker'); + + # Jetzt besorgen wir uns die Daten für jeden Server: + $data = []; + foreach( $member as $mem ) + { + $tmp = $redis->hgetall('logs.worker.' . $mem); + $data[$mem] = $tmp; + } + return view('admin') + ->with('data', $data) + ->with('title', "Admin-Interface-MetaGer"); + } +} diff --git a/app/Http/routes.php b/app/Http/routes.php index 1d421d716b09f13adb5b62129c62e819785fb849..b0067734230a29d188145809abf7f9b79efc55eb 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -112,6 +112,8 @@ ->with('navbarFocus', 'dienste'); }); + Route::get('admin', 'AdminInterface@index'); + Route::get('settings', 'StartpageController@loadSettings'); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 35471f6ff156325ed0fdb98b03e611c2cd43f675..775130e3a86c242e9874cf01037b2e4ef351ee17 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,7 +2,12 @@ namespace App\Providers; +use Queue; +use Log; +use Redis; use Illuminate\Support\ServiceProvider; +use Illuminate\Queue\Events\JobProcessed; +use Illuminate\Queue\Events\JobProcessing; class AppServiceProvider extends ServiceProvider { @@ -13,7 +18,36 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { - // + + # Wir loggen im Redis-System für jede Sekunde des Tages, wie viele Worker aktiv am Laufen waren. + # Dies ist notwendig, damit wir mitbekommen können, ab welchem Zeitpunkt wir zu wenig Worker zur Verfügung haben. + Queue::before(function (JobProcessing $event) { + $this->begin = strtotime(date(DATE_RFC822, mktime(date("H"),date("i"), date("s"), date("m"), date("d"), date("Y")))); + }); + Queue::after(function (JobProcessed $event) { + $today = strtotime(date(DATE_RFC822, mktime(0,0,0, date("m"), date("d"), date("Y")))); + $end = strtotime(date(DATE_RFC822, mktime(date("H"),date("i"), date("s"), date("m"), date("d"), date("Y")))) - $today; + $expireAt = strtotime(date(DATE_RFC822, mktime(0,0,0, date("m"), date("d")+1, date("Y")))); + $redis = Redis::connection('redisLogs'); + $p = getmypid(); + $host = gethostname(); + $begin = $this->begin - $today; + $redis->pipeline(function($pipe) use ($p, $expireAt, $host, $begin, $end) + { + for( $i = $begin; $i <= $end; $i++) + { + $pipe->sadd("logs.worker.$host.$i", strval($p)); + $pipe->expire("logs.worker.$host.$i", 10); + $pipe->eval("redis.call('hset', 'logs.worker.$host', '$i', redis.call('scard', 'logs.worker.$host.$i'))", 0); + $pipe->sadd("logs.worker", $host); + if( date("H") !== 0 ) + { + $pipe->expire("logs.worker.$host", $expireAt); + $pipe->expire("logs.worker", $expireAt); + } + } + }); + }); } /** diff --git a/composer.lock b/composer.lock index e115efec9a5676ceddeff7f8d2f18a53ee366738..48ec57eff7b9eabbd38611cf92589dc2e9cea448 100644 --- a/composer.lock +++ b/composer.lock @@ -1328,23 +1328,23 @@ }, { "name": "swiftmailer/swiftmailer", - "version": "v5.4.2", + "version": "v5.4.3", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "d8db871a54619458a805229a057ea2af33c753e8" + "reference": "4cc92842069c2bbc1f28daaaf1d2576ec4dfe153" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/d8db871a54619458a805229a057ea2af33c753e8", - "reference": "d8db871a54619458a805229a057ea2af33c753e8", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/4cc92842069c2bbc1f28daaaf1d2576ec4dfe153", + "reference": "4cc92842069c2bbc1f28daaaf1d2576ec4dfe153", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "mockery/mockery": "~0.9.1,<0.9.4" + "mockery/mockery": "~0.9.1" }, "type": "library", "extra": { @@ -1377,7 +1377,7 @@ "mail", "mailer" ], - "time": "2016-05-01 08:45:47" + "time": "2016-07-08 11:51:25" }, { "name": "symfony/console", diff --git a/database/metager.sqlite b/database/metager.sqlite index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c137bd09eb073efcb5f2b6db4f36729f0a8172f9 100644 Binary files a/database/metager.sqlite and b/database/metager.sqlite differ diff --git a/resources/views/admin.blade.php b/resources/views/admin.blade.php new file mode 100644 index 0000000000000000000000000000000000000000..61cbcf091159a1cea51d76960a882cba62966a59 --- /dev/null +++ b/resources/views/admin.blade.php @@ -0,0 +1,60 @@ +@extends('layouts.subPages') + +@section('title', $title ) + +@section('content') + +@foreach( $data as $serverName => $dataPoints ) +<div> +<h1>{{ $serverName }}</h1> +<svg width="100%" height="500px"> + <!-- Zunächst die Achsen: --> + <!-- Y-Achse --> + <line x1="1%" y1="0" x2="1%" y2="95%" style="stroke:rgb(0,0,0);stroke-width:3" /> + <line x1="1%" y1="0" x2="0" y2="3%" style="stroke:rgb(0,0,0);stroke-width:3" /> + <line x1="1%" y1="0" x2="2%" y2="3%" style="stroke:rgb(0,0,0);stroke-width:3" /> + + <!-- Beschriftungen der Y-Achse --> + @for( $y = ((95-0) / 10); $y < ((95-0) / 10) * 10; $y = $y + ((95-0) / 10) ) + <line x1="0.5%" y1="{{ $y }}%" x2="1.5%" y2="{{ $y }}%" style="stroke:rgb(0,0,0);stroke-width:1" /> + <text x="1.8%" y="{{ $y }}%" fill="black" style="font-size:10px;">{{ 100 - (($y / 95)*100) }}</text> + @endfor + <text x="3%" y="2%" fill="red">Anzahl Worker: x</text> + + <!-- X-Achse --> + <line x1="1%" y1="95%" x2="99%" y2="95%" style="stroke:rgb(0,0,0);stroke-width:3" /> + <line x1="99%" y1="95%" x2="98%" y2="92%" style="stroke:rgb(0,0,0);stroke-width:3" /> + <line x1="99%" y1="95%" x2="98%" y2="98%" style="stroke:rgb(0,0,0);stroke-width:3" /> + + <!-- Beschriftungen der X-Achse --> + @for( $x = (((99-1) / 24) + 1); $x < 98.9; $x = ($x + ((99-1) / 24)) ) + <line x1="{{ $x }}%" y1="93%" x2="{{ $x }}%" y2="97%" style="stroke:rgb(0,0,0);stroke-width:1" /> + <text x="{{ $x }}%" y="99%" fill="black" style="font-size:10px;">{{ (($x-1) / 98)*24 }}</text> + @endfor + <text x="95%" y="90%" fill="red">Zeit (h): y</text> + + <!-- Nun die Datenpunkte: --> + <?php + $count = 0; + + foreach($dataPoints as $key => $value) + { + if($count > 0) + { + $x1 = ($oldKey / 86400) * 98; + $x2 = ($key / 86400) * 98; + + $y1 = 95 - (($oldVal / 100) * 95); + $y2 = 95 - (($value / 100) * 95); + echo '<line x1="'.$x1.'%" y1="'.$y1.'%" x2="'.$x2.'%" y2="'.$y2.'%" style="stroke:rgb(0,0,0);stroke-width:1" />'; + } + $oldKey = $key; + $oldVal = $value; + $count++; + } + ?> +</svg> +</div> +@endforeach + +@endsection \ No newline at end of file