commit - 48138d0986aa809d5a0255d6f4722bbc6183caaa
commit + 0b40c15e266f55c907b0ccba7e58046c91a475fc
blob - /dev/null
blob + 72e14ea8e48f1c30c69ab770e2c6341a6218a836 (mode 644)
--- /dev/null
+++ bin/hits
+#!/usr/bin/awk -f
+
+# skip requests with bad method
+<UNKNOWN> {
+ next
+}
+
+{
+ host = $1
+ path = host $8
+ hits[path]++
+}
+
+END {
+ for (path in hits) {
+ printf "%d %s\n", hits[path], path
+ }
+}
blob - /dev/null
blob + 2b3a642505a9ae2be2a99b040c0bdb1ff42decd1 (mode 644)
--- /dev/null
+++ man/hits.1
+.Dd
+.Dt HITS 1
+.Sh NAME
+.Nm hits
+.Nd count web traffic
+.Sh SYNOPSIS
+.Nm
+.Op Ar
+.Sh DESCRIPTION
+.Nm
+counts HTTP requests from web server request log files
+and reports the number of requests per path.
+If no files are specified,
+.Nm
+reads from the standard input.
+.Pp
+The log must be in the default format produced by
+OpenBSD's
+.Xr httpd 8
+and
+.Xr nginx 8 .
+Here is an example line:
+.Dl default 192.0.2.1 - - [19/Dec/2022:23:12:34 +1100] "GET /some/file.txt HTTP/1.1" 200 256
+.Sh EXIT STATUS
+.Ex
+.Sh EXAMPLES
+Print the most-requested paths
+from the latest access log:
+.Bd -literal -offset indent
+hits /var/www/logs/access.log | sort | tail
+.Ed
+.Pp
+Print the least-requested blog entries from 2021:
+.Bd -literal -offset indent
+grep 'blog/2021/' /var/www/logs/access.log | hits | sort | sed 10q
+.Ed
+.Pp
+Print the 20 most-requested paths
+from all access logs:
+.Bd -literal -offset indent
+cd /var/www/logs
+gunzip -c access*.gz | cat access.log | hits | sort -r | sed 20q
+.Ed
+.Sh SEE ALSO
+.Xr awk 1