v1.6.29 : chemins IP triés par date, un par ligne avec compteur
- Drill-down IP : articles/livres affichés un par ligne (compteur entre parenthèses), triés par date de dernier accès desc
- AccessLogParser : ipPathTs trace le dernier timestamp par chemin/IP
- ip_top_paths : structure {n, ts} au lieu de count simple
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+28
-18
@@ -30,7 +30,7 @@ class AccessLogParser
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{pages:array<string,int>,books:array<string,int>,ips:array<string,int>,pages_by_day:array<string,list<int>>,ips_by_day:array<string,list<int>>,ip_top_paths:array<string,array<string,int>>}
|
||||
* @return array{pages:array<string,int>,books:array<string,int>,ips:array<string,int>,pages_by_day:array<string,list<int>>,ips_by_day:array<string,list<int>>,ip_top_paths:array<string,array<string,array{n:int,ts:int}>>}
|
||||
*/
|
||||
public function stats(): array
|
||||
{
|
||||
@@ -44,16 +44,17 @@ class AccessLogParser
|
||||
}
|
||||
}
|
||||
|
||||
$cutoff = strtotime("-{$this->days} days midnight") ?: (time() - $this->days * 86400);
|
||||
$pages = [];
|
||||
$books = [];
|
||||
$ips = [];
|
||||
$dayPages = [];
|
||||
$ipDays = []; // [ip => [dayOffset => count]]
|
||||
$ipPaths = []; // [ip => [path => count]]
|
||||
$cutoff = strtotime("-{$this->days} days midnight") ?: (time() - $this->days * 86400);
|
||||
$pages = [];
|
||||
$books = [];
|
||||
$ips = [];
|
||||
$dayPages = [];
|
||||
$ipDays = []; // [ip => [dayOffset => count]]
|
||||
$ipPaths = []; // [ip => [path => count]]
|
||||
$ipPathTs = []; // [ip => [path => last_timestamp]]
|
||||
|
||||
foreach ($this->logFiles() as $file) {
|
||||
$this->parseFile($file, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
||||
$this->parseFile($file, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths, $ipPathTs);
|
||||
}
|
||||
|
||||
arsort($pages);
|
||||
@@ -86,7 +87,10 @@ class AccessLogParser
|
||||
|
||||
$paths = $ipPaths[$ip] ?? [];
|
||||
arsort($paths);
|
||||
$ipTopPaths[$ip] = array_slice($paths, 0, 10, true);
|
||||
$ipTopPaths[$ip] = [];
|
||||
foreach (array_slice($paths, 0, 10, true) as $p => $cnt) {
|
||||
$ipTopPaths[$ip][$p] = ['n' => $cnt, 'ts' => $ipPathTs[$ip][$p] ?? 0];
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
@@ -152,7 +156,7 @@ class AccessLogParser
|
||||
return (int) strtotime("{$m[1]} {$m[2]} {$m[3]} {$m[4]} {$m[5]}");
|
||||
}
|
||||
|
||||
private function parseLine(string $line, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths): void
|
||||
private function parseLine(string $line, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths, array &$ipPathTs): void
|
||||
{
|
||||
if (!preg_match(self::RE, $line, $m)) {
|
||||
return;
|
||||
@@ -175,9 +179,12 @@ class AccessLogParser
|
||||
if ($publicIp) {
|
||||
$ips[$ip] = ($ips[$ip] ?? 0) + 1;
|
||||
}
|
||||
$dayPages[$path][$dayOffset] = ($dayPages[$path][$dayOffset] ?? 0) + 1;
|
||||
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
||||
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
||||
$dayPages[$path][$dayOffset] = ($dayPages[$path][$dayOffset] ?? 0) + 1;
|
||||
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
||||
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
||||
if ($tsVal > ($ipPathTs[$ip][$path] ?? 0)) {
|
||||
$ipPathTs[$ip][$path] = $tsVal;
|
||||
}
|
||||
} elseif (str_starts_with($path, '/book/') && strlen($path) > 6) {
|
||||
$books[$path] = ($books[$path] ?? 0) + 1;
|
||||
if ($publicIp) {
|
||||
@@ -185,10 +192,13 @@ class AccessLogParser
|
||||
}
|
||||
$ipDays[$ip][$dayOffset] = ($ipDays[$ip][$dayOffset] ?? 0) + 1;
|
||||
$ipPaths[$ip][$path] = ($ipPaths[$ip][$path] ?? 0) + 1;
|
||||
if ($tsVal > ($ipPathTs[$ip][$path] ?? 0)) {
|
||||
$ipPathTs[$ip][$path] = $tsVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function parseFile(array $file, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths): void
|
||||
private function parseFile(array $file, int $cutoff, array &$pages, array &$books, array &$ips, array &$dayPages, array &$ipDays, array &$ipPaths, array &$ipPathTs): void
|
||||
{
|
||||
if ($file['type'] === 'tgz') {
|
||||
try {
|
||||
@@ -199,7 +209,7 @@ class AccessLogParser
|
||||
continue;
|
||||
}
|
||||
foreach (explode("\n", $content) as $line) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths, $ipPathTs);
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
@@ -212,7 +222,7 @@ class AccessLogParser
|
||||
while (!gzeof($h)) {
|
||||
$line = gzgets($h, 8192);
|
||||
if ($line !== false) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths, $ipPathTs);
|
||||
}
|
||||
}
|
||||
gzclose($h);
|
||||
@@ -222,7 +232,7 @@ class AccessLogParser
|
||||
return;
|
||||
}
|
||||
while (($line = fgets($h)) !== false) {
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths);
|
||||
$this->parseLine($line, $cutoff, $pages, $books, $ips, $dayPages, $ipDays, $ipPaths, $ipPathTs);
|
||||
}
|
||||
fclose($h);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user