Skip to content
Snippets Groups Projects
Commit e2b495b5 authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Merge branch 'development' into 'master'

Extended count script

See merge request !1414
parents 781ca1b8 343ad345
No related branches found
No related tags found
2 merge requests!1504Master,!1414Extended count script
......@@ -16,18 +16,20 @@ class AdminInterface extends Controller
// Now we gonna check which stats we can find
$stati = array();
foreach($names as $name){
foreach ($names as $name) {
$stats = Redis::hgetall($name . ".stats");
if(sizeof($stats) > 0){
if (sizeof($stats) > 0) {
$fetcherStatus = Redis::get($name);
$stati[$name]["status"] = $fetcherStatus;
foreach($stats as $pid => $value){
if(strstr($value, ";")){
foreach ($stats as $pid => $value) {
if (strstr($value, ";")) {
$value = explode(";", $value);
$connection = json_decode(base64_decode($value[0]), true);
foreach($connection as $key => $val){
if(strstr($key, "_time"))
foreach ($connection as $key => $val) {
if (strstr($key, "_time")) {
$stati[$name]["fetcher"][$pid]["connection"][$key] = $val;
}
}
$stati[$name]["fetcher"][$pid]["poptime"] = $value[1];
}
......@@ -37,21 +39,21 @@ class AdminInterface extends Controller
// So now we can generate Median Times for every Fetcher
$fetcherCount = 0;
foreach($stati as $engineName => $engineStats){
foreach ($stati as $engineName => $engineStats) {
$connection = array();
$poptime = 0;
$fetcherCount += sizeof($engineStats["fetcher"]);
foreach($engineStats["fetcher"] as $pid => $stats){
foreach($stats["connection"] as $key => $value){
if(!isset($connection[$key])){
foreach ($engineStats["fetcher"] as $pid => $stats) {
foreach ($stats["connection"] as $key => $value) {
if (!isset($connection[$key])) {
$connection[$key] = $value;
}else{
} else {
$connection[$key] += $value;
}
}
$poptime += floatval($stats["poptime"]);
}
foreach($connection as $key => $value){
foreach ($connection as $key => $value) {
$connection[$key] /= sizeof($engineStats["fetcher"]);
}
$poptime /= sizeof($engineStats["fetcher"]);
......@@ -70,13 +72,14 @@ class AdminInterface extends Controller
return $response;
}
private function getSearchEngineNames(){
private function getSearchEngineNames()
{
$url = config_path() . "/sumas.xml";
$xml = simplexml_load_file($url);
$sumas = $xml->xpath("suma");
$names = array();
foreach($sumas as $suma){
foreach ($sumas as $suma) {
$names[] = $suma["name"]->__toString();
}
return $names;
......@@ -85,30 +88,43 @@ class AdminInterface extends Controller
public function count(Request $request)
{
$days = intval($request->input('days', 28));
if(!is_int($days) || $days <= 0) $days = 28;
$logToday = "mg3.log";
if (file_exists("/var/log/metager/" . $logToday)) {
$logToday = file("/var/log/metager/" . $logToday);
$interface = $request->input('interface', 'all');
if (!is_int($days) || $days <= 0) {
$days = 28;
}
$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 {
return redirect('');
}
$oldLogs = [];
$yesterday = 0;
$rekordTag = 0;
$oldLogs = [];
$rekordTag = 0;
$rekordTagDate = "";
$size = 0;
$count = 0;
$size = 0;
$count = 0;
for ($i = 1; $i <= $days; $i++) {
$logDate = "/var/log/metager/archive/mg3.log.$i";
if (file_exists($logDate)) {
$sameTime = exec("grep -n '" . date('H') . ":" . date('i') . ":' $logDate | tail -1 | cut -f1 -d':'");
$insgesamt = exec("wc -l $logDate | cut -f1 -d' '");
if ($interface === "all") {
$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) {
$rekordTag = $insgesamt;
$rekordTag = $insgesamt;
$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, ",", ".");
# Nun noch den median:
$count += $insgesamt;
......@@ -120,34 +136,34 @@ class AdminInterface extends Controller
}
}
if($request->input('out', 'web') === "web"){
if ($request->input('out', 'web') === "web") {
return view('admin.count')
->with('title', 'Suchanfragen - MetaGer')
->with('today', number_format(floatval(sizeof($logToday)), 0, ",", "."))
->with('today', number_format(floatval($logToday), 0, ",", "."))
->with('oldLogs', $oldLogs)
->with('rekordCount', number_format(floatval($rekordTag), 0, ",", "."))
->with('rekordTagSameTime', number_format(floatval($rekordTagSameTime), 0, ",", "."))
->with('rekordDate', $rekordTagDate)
->with('days', $days);
}else{
$result = "";
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 .= '"' . $value['sameTime'] . '",';
$resultTmp .= '"' . $value['insgesamt'] . '",';
$resultTmp .= '"' . $value['median'] . '"' . "\r\n";
$result = $resultTmp . $result;
}
return response($result, 200)
->header('Content-Type', 'text/csv')
->header('Content-Disposition', 'attachment; filename="count.csv"');
} else {
$result = "";
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 .= '"' . $value['sameTime'] . '",';
$resultTmp .= '"' . $value['insgesamt'] . '",';
$resultTmp .= '"' . $value['median'] . '"' . "\r\n";
$result = $resultTmp . $result;
}
return response($result, 200)
->header('Content-Type', 'text/csv')
->header('Content-Disposition', 'attachment; filename="count.csv"');
}
}
public function check()
{
$q = "";
$q = "";
$redis = Redis::connection('redisLogs');
if ($redis) {
$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 @@
@section('title', $title )
@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">
<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>
<th>Datum</th>
<th>Suchanfragen zur gleichen Zeit</th>
......@@ -14,7 +35,7 @@
</tr>
@if( isset($today) )
<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>???</td>
<td>???</td>
......@@ -22,14 +43,12 @@
@endif
@foreach($oldLogs as $key => $value)
<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['insgesamt'] }}</td>
<td>{{ $value['median'] }}</td>
</tr>
@endforeach
</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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment