Commit 343ad345 authored by Dominik Hebeler's avatar Dominik Hebeler

Extended count script

parent ebbc468d
...@@ -16,18 +16,20 @@ class AdminInterface extends Controller ...@@ -16,18 +16,20 @@ class AdminInterface extends Controller
// Now we gonna check which stats we can find // Now we gonna check which stats we can find
$stati = array(); $stati = array();
foreach($names as $name){ foreach ($names as $name) {
$stats = Redis::hgetall($name . ".stats"); $stats = Redis::hgetall($name . ".stats");
if(sizeof($stats) > 0){ if (sizeof($stats) > 0) {
$fetcherStatus = Redis::get($name); $fetcherStatus = Redis::get($name);
$stati[$name]["status"] = $fetcherStatus; $stati[$name]["status"] = $fetcherStatus;
foreach($stats as $pid => $value){ foreach ($stats as $pid => $value) {
if(strstr($value, ";")){ if (strstr($value, ";")) {
$value = explode(";", $value); $value = explode(";", $value);
$connection = json_decode(base64_decode($value[0]), true); $connection = json_decode(base64_decode($value[0]), true);
foreach($connection as $key => $val){ foreach ($connection as $key => $val) {
if(strstr($key, "_time")) if (strstr($key, "_time")) {
$stati[$name]["fetcher"][$pid]["connection"][$key] = $val; $stati[$name]["fetcher"][$pid]["connection"][$key] = $val;
}
} }
$stati[$name]["fetcher"][$pid]["poptime"] = $value[1]; $stati[$name]["fetcher"][$pid]["poptime"] = $value[1];
} }
...@@ -37,21 +39,21 @@ class AdminInterface extends Controller ...@@ -37,21 +39,21 @@ class AdminInterface extends Controller
// So now we can generate Median Times for every Fetcher // So now we can generate Median Times for every Fetcher
$fetcherCount = 0; $fetcherCount = 0;
foreach($stati as $engineName => $engineStats){ foreach ($stati as $engineName => $engineStats) {
$connection = array(); $connection = array();
$poptime = 0; $poptime = 0;
$fetcherCount += sizeof($engineStats["fetcher"]); $fetcherCount += sizeof($engineStats["fetcher"]);
foreach($engineStats["fetcher"] as $pid => $stats){ foreach ($engineStats["fetcher"] as $pid => $stats) {
foreach($stats["connection"] as $key => $value){ foreach ($stats["connection"] as $key => $value) {
if(!isset($connection[$key])){ if (!isset($connection[$key])) {
$connection[$key] = $value; $connection[$key] = $value;
}else{ } else {
$connection[$key] += $value; $connection[$key] += $value;
} }
} }
$poptime += floatval($stats["poptime"]); $poptime += floatval($stats["poptime"]);
} }
foreach($connection as $key => $value){ foreach ($connection as $key => $value) {
$connection[$key] /= sizeof($engineStats["fetcher"]); $connection[$key] /= sizeof($engineStats["fetcher"]);
} }
$poptime /= sizeof($engineStats["fetcher"]); $poptime /= sizeof($engineStats["fetcher"]);
...@@ -70,13 +72,14 @@ class AdminInterface extends Controller ...@@ -70,13 +72,14 @@ class AdminInterface extends Controller
return $response; return $response;
} }
private function getSearchEngineNames(){ private function getSearchEngineNames()
{
$url = config_path() . "/sumas.xml"; $url = config_path() . "/sumas.xml";
$xml = simplexml_load_file($url); $xml = simplexml_load_file($url);
$sumas = $xml->xpath("suma"); $sumas = $xml->xpath("suma");
$names = array(); $names = array();
foreach($sumas as $suma){ foreach ($sumas as $suma) {
$names[] = $suma["name"]->__toString(); $names[] = $suma["name"]->__toString();
} }
return $names; return $names;
...@@ -85,30 +88,43 @@ class AdminInterface extends Controller ...@@ -85,30 +88,43 @@ class AdminInterface extends Controller
public function count(Request $request) public function count(Request $request)
{ {
$days = intval($request->input('days', 28)); $days = intval($request->input('days', 28));
if(!is_int($days) || $days <= 0) $days = 28; $interface = $request->input('interface', 'all');
$logToday = "mg3.log"; if (!is_int($days) || $days <= 0) {
if (file_exists("/var/log/metager/" . $logToday)) { $days = 28;
$logToday = file("/var/log/metager/" . $logToday); }
$logToday = "/var/log/metager/mg3.log";
if (file_exists($logToday)) {
if ($interface === "all") {
$logToday = exec("cat $logToday | wc -l");
} else {
$logToday = exec("cat $logToday | grep interface=" . $interface . " | wc -l");
}
} else { } else {
return redirect(''); return redirect('');
} }
$oldLogs = []; $oldLogs = [];
$yesterday = 0; $rekordTag = 0;
$rekordTag = 0;
$rekordTagDate = ""; $rekordTagDate = "";
$size = 0; $size = 0;
$count = 0; $count = 0;
for ($i = 1; $i <= $days; $i++) { for ($i = 1; $i <= $days; $i++) {
$logDate = "/var/log/metager/archive/mg3.log.$i"; $logDate = "/var/log/metager/archive/mg3.log.$i";
if (file_exists($logDate)) { if (file_exists($logDate)) {
$sameTime = exec("grep -n '" . date('H') . ":" . date('i') . ":' $logDate | tail -1 | cut -f1 -d':'"); if ($interface === "all") {
$insgesamt = exec("wc -l $logDate | cut -f1 -d' '"); $sameTime = exec("awk -v hour=\"" . date('H') . "\" -v minute=\"" . date('i') . "\" -v second=\"" . date('s') . "\" -f " . app_path('get_dates.awk') . " " . $logDate . " | wc -l");
$insgesamt = exec("wc -l $logDate | cut -f1 -d' '");
} else {
$sameTime = exec("awk -v hour=\"" . date('H') . "\" -v minute=\"" . date('i') . "\" -v second=\"" . date('s') . "\" -f " . app_path('get_dates.awk') . " " . $logDate . " | grep interface=" . $interface . " | wc -l");
$insgesamt = exec("cat $logDate | grep interface=" . $interface . " | wc -l");
}
if ($insgesamt > $rekordTag) { if ($insgesamt > $rekordTag) {
$rekordTag = $insgesamt; $rekordTag = $insgesamt;
$rekordTagSameTime = $sameTime; $rekordTagSameTime = $sameTime;
$rekordTagDate = date("d.m.Y", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $i, date("Y"))); $rekordTagDate = date("d.m.Y", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $i, date("Y")));
} }
$oldLogs[$i]['sameTime'] = number_format(floatval($sameTime), 0, ",", "."); $oldLogs[$i]['sameTime'] = number_format(floatval($sameTime), 0, ",", ".");
$oldLogs[$i]['insgesamt'] = number_format(floatval($insgesamt), 0, ",", "."); $oldLogs[$i]['insgesamt'] = number_format(floatval($insgesamt), 0, ",", ".");
# Nun noch den median: # Nun noch den median:
$count += $insgesamt; $count += $insgesamt;
...@@ -120,34 +136,34 @@ class AdminInterface extends Controller ...@@ -120,34 +136,34 @@ class AdminInterface extends Controller
} }
} }
if($request->input('out', 'web') === "web"){ if ($request->input('out', 'web') === "web") {
return view('admin.count') return view('admin.count')
->with('title', 'Suchanfragen - MetaGer') ->with('title', 'Suchanfragen - MetaGer')
->with('today', number_format(floatval(sizeof($logToday)), 0, ",", ".")) ->with('today', number_format(floatval($logToday), 0, ",", "."))
->with('oldLogs', $oldLogs) ->with('oldLogs', $oldLogs)
->with('rekordCount', number_format(floatval($rekordTag), 0, ",", ".")) ->with('rekordCount', number_format(floatval($rekordTag), 0, ",", "."))
->with('rekordTagSameTime', number_format(floatval($rekordTagSameTime), 0, ",", ".")) ->with('rekordTagSameTime', number_format(floatval($rekordTagSameTime), 0, ",", "."))
->with('rekordDate', $rekordTagDate) ->with('rekordDate', $rekordTagDate)
->with('days', $days); ->with('days', $days);
}else{ } else {
$result = ""; $result = "";
foreach($oldLogs as $key => $value){ foreach ($oldLogs as $key => $value) {
$resultTmp = '"' . date("D, d M y", mktime(date("H"),date("i"), date("s"), date("m"), date("d")-$key, date("Y"))) . '",'; $resultTmp = '"' . date("D, d M y", mktime(date("H"), date("i"), date("s"), date("m"), date("d") - $key, date("Y"))) . '",';
$resultTmp .= '"' . $value['sameTime'] . '",'; $resultTmp .= '"' . $value['sameTime'] . '",';
$resultTmp .= '"' . $value['insgesamt'] . '",'; $resultTmp .= '"' . $value['insgesamt'] . '",';
$resultTmp .= '"' . $value['median'] . '"' . "\r\n"; $resultTmp .= '"' . $value['median'] . '"' . "\r\n";
$result = $resultTmp . $result; $result = $resultTmp . $result;
} }
return response($result, 200) return response($result, 200)
->header('Content-Type', 'text/csv') ->header('Content-Type', 'text/csv')
->header('Content-Disposition', 'attachment; filename="count.csv"'); ->header('Content-Disposition', 'attachment; filename="count.csv"');
} }
} }
public function check() public function check()
{ {
$q = ""; $q = "";
$redis = Redis::connection('redisLogs'); $redis = Redis::connection('redisLogs');
if ($redis) { if ($redis) {
$q = $redis->lrange("logs.search", -1, -1)[0]; $q = $redis->lrange("logs.search", -1, -1)[0];
......
BEGIN {
end_t = mktime("2019 02 25 " hour " " minute " " second)
FS="[: \\]]"
}
{
now = mktime("2019 02 25 " $4 " " $5 " " $6)
if(now <= end_t) {print}
}
...@@ -3,9 +3,30 @@ ...@@ -3,9 +3,30 @@
@section('title', $title ) @section('title', $title )
@section('content') @section('content')
<h2>{{ exec("uptime") }}</h2> <p>{{ exec("uptime") }}</p>
@if( isset($rekordDate) && isset($rekordTagSameTime) && isset($rekordCount) )
<p>Rekord am {{ $rekordDate }} zur gleichen Zeit <span class="text-info">{{ $rekordTagSameTime }}</span> - insgesamt <span class="text-danger">{{ $rekordCount }}</span></p>
@endif
<p>Mittelwert der letzten {{ sizeof($oldLogs) }} Tage: {{ $oldLogs[sizeof($oldLogs)]['median'] }}</p>
<table class="table table-striped"> <table class="table table-striped">
<caption>Daten der letzten <form method="POST"><input type="number" name="days" value="{{$days}}" /> Tage <button type="submit" class="btn btn-sm btn-default">Aktualisieren</button><button type="submit" name="out" value="csv" class="btn btn-sm btn-default">Als CSV exportieren</button></form></caption> <caption>
<form method="POST" style="display: flex; align-items: center;">
<div class="form-group" style="max-width: 100px; margin-right: 8px;">
<label for="days">Tage</label>
<input class="form-control" type="number" id="days" name="days" value="{{$days}}" />
</div>
<div class="form-group" style="max-width: 100px; margin-right: 8px;">
<label for="interface">Sprache</label>
<select class="form-control" name="interface" id="interface"><option value="all" {{ (Request::input('interface', 'all') == "all" ? "selected" : "")}}>Alle</option><option value="de" {{ (Request::input('interface', 'all') == "de" ? "selected" : "")}}>DE</option><option value="en" {{ (Request::input('interface', 'all') == "en" ? "selected" : "")}}>EN</option></select>
</div>
<div id="refresh" style="margin-top: 11px; margin-right: 8px;">
<button type="submit" class="btn btn-sm btn-default">Aktualisieren</button>
</div>
<div id="export" style="margin-top: 11px;">
<button type="submit" name="out" value="csv" class="btn btn-sm btn-default">Als CSV exportieren</button>
</div>
</form>
</caption>
<tr> <tr>
<th>Datum</th> <th>Datum</th>
<th>Suchanfragen zur gleichen Zeit</th> <th>Suchanfragen zur gleichen Zeit</th>
...@@ -14,7 +35,7 @@ ...@@ -14,7 +35,7 @@
</tr> </tr>
@if( isset($today) ) @if( isset($today) )
<tr> <tr>
<td>{{ date("D, d M y", mktime(date("H"),date("i"), date("s"), date("m"), date("d"), date("Y"))) }}</td> <td>{{ Carbon::now()->format('D, d.m.Y') }}</td>
<td>{{ $today }}</td> <td>{{ $today }}</td>
<td>???</td> <td>???</td>
<td>???</td> <td>???</td>
...@@ -22,14 +43,12 @@ ...@@ -22,14 +43,12 @@
@endif @endif
@foreach($oldLogs as $key => $value) @foreach($oldLogs as $key => $value)
<tr> <tr>
<td>{{ date("D, d M y", mktime(date("H"),date("i"), date("s"), date("m"), date("d")-$key, date("Y"))) }}</td> <td>{{ Carbon::now()->subDays($key)->format('D, d.m.Y') }}</td>
<td>{{ $value['sameTime'] }}</td> <td>{{ $value['sameTime'] }}</td>
<td>{{ $value['insgesamt'] }}</td> <td>{{ $value['insgesamt'] }}</td>
<td>{{ $value['median'] }}</td> <td>{{ $value['median'] }}</td>
</tr> </tr>
@endforeach @endforeach
</table> </table>
@if( isset($rekordDate) && isset($rekordTagSameTime) && isset($rekordCount) )
<h3>Rekord am {{ $rekordDate }} zur gleichen Zeit <span class="text-info">{{ $rekordTagSameTime }}</span> - insgesamt <span class="text-danger">{{ $rekordCount }}</span></h3>
@endif
@endsection @endsection
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment