3 ;; This script performs per-IP access analysis of the nginx access
4 ;; log. This is translated into a display format of:
5 ;; total-count hit-count IP path
7 (signal 2 (fn (x) (exit 0)))
9 (setf DISPLAY-TOTALS (and (find "--tot" (main-args)) true))
11 ; "Object" holding data for an IP
13 ; (self 2) = total-count
14 ; (self 3) = a-list of (path hit-count)
16 (define (ROW:ROW IP) (list (context) IP 0 (list)))
18 (define (add-path PATH)
19 (unless (assoc PATH (self 3)) (push (list PATH 0) (self 3)))
20 (inc (lookup PATH (self 3)))
24 (if MAIN:DISPLAY-TOTALS (list (list (self 2) (length (self 3)) (self 1)))
25 (sort (map (fn (P) (list (self 2) (P 1) (self 1) (P 0))) (self 3)))))
29 ; Table of rows, keyed by IP
32 (while (setf LINE (read-line))
33 (when (regex "^([^ ]+)[^\"]*[^ ]+ ([^ ]+)" LINE 0)
34 (let ((IP $1) (PATH $2))
35 (unless (IPS IP) (IPS IP (ROW IP)))
36 (:add-path (IPS IP) PATH))))
39 (sort (flat (map (fn (R) (:display R)) (map last (IPS))) 1) >))