Commit 563f0054 authored by Dominik Hebeler's avatar Dominik Hebeler

Merge branch '953-count-script-is-missing-a-value' into 'development'

Resolve "Count Script is missing a value"

Closes #953

See merge request !1566
parents 47598c2b 3f3f5d4a
......@@ -144,11 +144,6 @@ class AdminInterface extends Controller
$size = 0;
$count = 0;
$now = Carbon::now()->subMinutes(Carbon::now()->minute % 5)->format('H:i');
if ($now === "00:00") {
$now = "00:05";
}
foreach ($logs as $key => $stats) {
if ($key === 0) {
// Log for today
......@@ -156,7 +151,16 @@ class AdminInterface extends Controller
continue;
}
$insgesamt = empty($stats->insgesamt->{$interface}) ? 0 : $stats->insgesamt->{$interface};
$sameTime = empty($stats->time->{$now}->{$interface}) ? 0 : $stats->time->{$now}->{$interface};
$sameTime = 0;
$now = Carbon::now();
$now->hour = 0;
$now->minute = 0;
$now->second = 0;
while($now->lessThanOrEqualTo(Carbon::now())){
$sameTime += empty($stats->time->{$now->format('H:i')}->{$interface}) ? 0 : $stats->time->{$now->format('H:i')}->{$interface};
$now->addMinutes(5);
}
if ($insgesamt > $rekordTag) {
$rekordTag = $insgesamt;
......
......@@ -43,28 +43,37 @@ class ConvertCountFile implements ShouldQueue
try {
$fh = fopen($this->files["logFile"], "r");
$currentLogTime = Carbon::now()->hour(0)->minute(0)->second(0)->addMinutes(5);
while ($fh !== false && ($line = fgets($fh)) !== false) {
$logTime = [];
$interface = "";
// i.e. [Wed Apr 17 00:00:01] ref=https://metager.de/ time=0.51 serv=web interface=de
if (preg_match('/(\d{2}:\d{2}:\d{2}).*?\sinterface=(\S+)/', $line, $matches)) {
// Create Date Object
$logTime = explode(":", $matches[1]);
$logTime = $matches[1];
$interface = $matches[2];
} else if (preg_match('/\[[a-zA-z]{3},\s\d{2}\s[a-zA-Z]{3}\s\d{2}\s(\d{2}:\d{2}:\d{2})/', $line, $matches)) {
$logTime = explode(":", $matches[1]);
} else if (preg_match('/\[\d{2}\/\d{2}\/\d{4}:(\d{2}:\d{2}:\d{2})/', $line, $matches)) {
$logTime = explode(":", $matches[1]);
} else {
continue;
}
$thatTime = \DateTime::createFromFormat('H:i:s', $logTime);
$thatTime->sub(new \DateInterval("PT" . ($thatTime->format('i') % 5) . "M"));
while (!$fullRound && ((intval($logTime[0]) * 60) + intval($logTime[1])) > (($currentLogTime->hour * 60) + $currentLogTime->minute)) {
$result["time"][$currentLogTime->format('H:i')] = $result["insgesamt"];
$currentLogTime->addMinutes(5);
if ($currentLogTime->hour === 0 && $currentLogTime->minute === 0) {
$fullRound = true;
if(empty($result["time"][$thatTime->format('H:i')])){
$result["time"][$thatTime->format('H:i')] = [
"insgesamt" => [
"all" => 0,
],
];
}
if(empty($result["time"][$thatTime->format('H:i')]["all"])){
$result["time"][$thatTime->format('H:i')]["all"] = 1;
}else{
$result["time"][$thatTime->format('H:i')]["all"]++;
}
if (!empty($interface)) {
if(empty($result["time"][$thatTime->format('H:i')][$interface])){
$result["time"][$thatTime->format('H:i')][$interface] = 1;
}else{
$result["time"][$thatTime->format('H:i')][$interface]++;
}
}
// Update the total statistics
......@@ -81,10 +90,6 @@ class ConvertCountFile implements ShouldQueue
}
}
}
if (empty($result["time"][$currentLogTime->format('H:i')])) {
$result["time"][$currentLogTime->format('H:i')] = $result["insgesamt"];
}
} catch (\ErrorException $e) {
$error = true;
} finally {
......
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