From dc9afe2adf16e1375001eca9bc73c2211f73e27c Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 14 Sep 2018 15:50:37 -0500 Subject: [PATCH] metrics/access/ingest: detect product image paths and included in dump. --- metrics/access/ingest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/metrics/access/ingest.php b/metrics/access/ingest.php index 57c1a1a9..5582a537 100755 --- a/metrics/access/ingest.php +++ b/metrics/access/ingest.php @@ -3,11 +3,13 @@ const REGEX_LINE = '/\S+ \S+ \S+ \[([^:]+:\d+:\d+:\d+ [^\]]+)\] "(\S+)(?: (\S+) \S+)?" (\S+) (\S+) "[^"]*" "[^"]*" .* size:(\S+) \S+(?: +"?(\S+-\S+-\S+-\S+-[^\s"]+|-)"? "?(dvd|ftp|-)"?)?/'; const REGEX_PRODUCT = '#/(?:(tumbleweed)|distribution/(?:leap/)?(\d+\.\d+)|openSUSE(?:_|:/)(?:leap(?:_|:/))?(factory|tumbleweed|\d+\.\d+))#i'; +const REGEX_IMAGE = '#(?:/(?:iso|live)/[^/]+-(DVD|NET|GNOME-Live|KDE-Live|Rescue-CD|Kubic-DVD)-[^/]+\.iso(?:\.torrent)?|/jeos/[^/]+-(JeOS)\.[^/]+\.(?:qcow2|vhdx|vmdk|vmx)$)#'; $total = 0; $total_invalid = 0; $total_product = []; $unique_product = []; +$total_image_product = []; $file = $argc == 2 ? $argv[1] : 'php://stdin'; $handle = fopen($file, 'r'); @@ -40,6 +42,15 @@ while (($line = fgets($handle)) !== false) { if (!isset($unique_product[$product][$uuid])) $unique_product[$product][$uuid] = 0; $unique_product[$product][$uuid] += 1; } + + if (preg_match(REGEX_IMAGE, $match[3], $match_image)) { + // Remove empty match groups and select non-all match. + $values = array_filter($match_image); + $image = next($values); + if (!isset($total_image_product[$product])) $total_image_product[$product] = []; + if (!isset($total_image_product[$product][$image])) $total_image_product[$product][$image] = 0; + $total_image_product[$product][$image] += 1; + } } $position = ftell($handle); fclose($handle); @@ -54,6 +65,7 @@ echo json_encode([ 'total' => $total, 'total_product' => $total_product, 'unique_product' => $unique_product, + 'total_image_product' => $total_image_product, 'total_invalid' => $total_invalid, 'bytes' => $position, ]) . "\n"; // JSON_PRETTY_PRINT for debugging.