x

Programs, configuration and documentation that don't fit anywhere else
Log | Files | Refs | README | LICENSE

commit 0b40c15e266f55c907b0ccba7e58046c91a475fc
parent 48138d0986aa809d5a0255d6f4722bbc6183caaa
Author: Oliver Lowe <o@olowe.co>
Date:   Thu, 15 Jun 2023 12:12:38 +1000

Add HTTP request counter

Diffstat:
Abin/hits | 18++++++++++++++++++
Aman/hits.1 | 45+++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/bin/hits b/bin/hits @@ -0,0 +1,18 @@ +#!/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 + } +} diff --git a/man/hits.1 b/man/hits.1 @@ -0,0 +1,45 @@ +.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