Rack of Ethernet switches.

Visualizing Log Patterns with Color

Nginx and Apache Logs in Color

Web server logs reveal patterns of activity by web crawlers. Some are indexing crawlers operated by search engines, some are mysterious. Another pattern is systematic blind searches for vulnerable server-side executables or other configuration problems. The pattern you want to see is the interested user who follows some path through the hyperlinks on your site, taking time to read the pages.

Maybe we could use color to help spot these patterns?

Maybe...

First, let's look at the result, then the explanation comes later. Here are the most recent client requests, starting most recent first. Your request for this page won't appear there as it isn't complete by the time this page was automatically generated with PHP. But if you reload the page you should see your initial request near the top.

3.147.82.108 US, United States 08/Jan/2025:12:16:30 /open-source/compiling-wireshark-on-openbsd.html
51.222.253.5 FR, France 08/Jan/2025:12:16:29 /fun/requests-for-quotes/tongan-misdirection/
40.77.167.144 US, United States 08/Jan/2025:12:16:21 /travel/turkey/halicarnassus/
35.187.60.34 US, United States 08/Jan/2025:12:15:38 /travel/iceland/golden-circle/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:38 /travel/japan/kagoshima/sakurajima/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:38 /travel/iceland/golden-circle/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:38 /travel/japan/kagoshima/sakurajima/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:38 /cybersecurity/isc2-cissp/domain-2-asset-security.html
35.187.60.34 US, United States 08/Jan/2025:12:15:38 /cybersecurity/isc2-cissp/domain-2-asset-security.html
35.187.60.34 US, United States 08/Jan/2025:12:15:38 /cybersecurity/cyberwar/estonia.html
35.187.60.34 US, United States 08/Jan/2025:12:15:38 /travel/rapa-nui/eclipse/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /cybersecurity/cyberwar/estonia.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /open-source/multiboot-windows-openbsd/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /open-source/rhel-oracle-centos-6-7-8-9/packages-and-software.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /open-source/multiboot-windows-openbsd/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/france/boat/boat-handling-and-locks.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/france/boat/boat-handling-and-locks.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/france/canal-du-midi/beziers-to-colombiers.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/france/canal-du-midi/beziers-to-colombiers.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/japan/sapporo/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/japan/sapporo/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /technical/hdmi.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/japan/tokyo-asakusa/senso-ji.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/athens-to-paris/budapest-prague.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/athens-to-paris/budapest-prague.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/greece/crete/eastern-crete/agia-fotia.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/usa/new-york-sro-flophouses/bowery-history.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/greece/crete/eastern-crete/agia-fotia.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/trinidad/port-of-spain.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /cybersecurity/isc2-cissp/domain-7-security-operations.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/turkey/trains/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/turkey/trains/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /cybersecurity/isc2-ccsp/cloud-data-security.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/japan/tokyo-asakusa/senso-ji.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /cybersecurity/history/uss-chaumont/history.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /technical/hdmi.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /cybersecurity/history/uss-chaumont/history.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/france/boat-trip-canal-lateral-a-la-loire/cours-les-barres-to-nevers.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/france/boat-trip-canal-lateral-a-la-loire/cours-les-barres-to-nevers.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/usa/new-york-sro-flophouses/bowery-history.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /cybersecurity/isc2-ccsp/cloud-data-security.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/trinidad/port-of-spain.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /fun/teaching/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /fun/teaching/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/uk/glastonbury/town.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/uk/glastonbury/town.html
35.187.60.34 US, United States 08/Jan/2025:12:15:37 /travel/iceland/golden-circle/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/japan/kagoshima/sakurajima/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /cybersecurity/isc2-cissp/domain-2-asset-security.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /cybersecurity/cyberwar/estonia.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/rapa-nui/eclipse/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /open-source/multiboot-windows-openbsd/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /open-source/rhel-oracle-centos-6-7-8-9/packages-and-software.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/france/boat/boat-handling-and-locks.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/france/canal-du-midi/beziers-to-colombiers.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/japan/sapporo/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/turkey/trains/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /cybersecurity/isc2-ccsp/cloud-data-security.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/japan/tokyo-asakusa/senso-ji.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /cybersecurity/history/uss-chaumont/history.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/athens-to-paris/budapest-prague.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /technical/hdmi.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/france/boat-trip-canal-lateral-a-la-loire/cours-les-barres-to-nevers.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/greece/crete/eastern-crete/agia-fotia.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/usa/new-york-sro-flophouses/bowery-history.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/trinidad/port-of-spain.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /fun/teaching/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /cybersecurity/isc2-cissp/domain-7-security-operations.html
35.187.60.34 US, United States 08/Jan/2025:12:15:36 /travel/uk/glastonbury/town.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /3d/archival.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /3d/archival.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /travel/greece/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/basics/13-going-further.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /radio/9-1-unun/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /travel/japan/takamatsu/ferry.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /radio/9-1-unun/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/comptia/domain-5-answers.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/mobile-phone-security/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /travel/greece/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/isc2-cissp/domain-8-software-development-security.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/isc2-ccsp/drawings.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /travel/greece/greek/active-participles.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /travel/greece/greek/active-participles.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/basics/13-going-further.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /travel/japan/takamatsu/ferry.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/mobile-phone-security/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/comptia/domain-5-answers.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /travel/greece/greek/adverbs.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /travel/greece/greek/adverbs.html
35.187.60.34 US, United States 08/Jan/2025:12:15:27 /cybersecurity/isc2-cissp/domain-8-software-development-security.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /cybersecurity/isc2-ccsp/drawings.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/usa/new-york-sro-flophouses/bowery-house.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/greece/crete/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/japan/takamatsu/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /cybersecurity/crypto/hash.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/usa/new-york-sro-flophouses/bowery-house.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/japan/takamatsu/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /cybersecurity/crypto/hash.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/uk/orkney-sousterrain/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/uk/orkney-sousterrain/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/greece/crete/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /cybersecurity/crypto/reading.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/greece/milos/trypiti.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/usa/detroit/detroit-part2.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /cybersecurity/crypto/reading.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /open-source/samba-active-directory/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/greece/milos/trypiti.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /open-source/samba-active-directory/Index.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/usa/detroit/detroit-part2.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /open-source/letsencrypt-tls-cert-godaddy.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /fun/how-it-connects.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /fun/how-it-connects.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /open-source/letsencrypt-tls-cert-godaddy.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /cybersecurity/comptia/network-commands.html
35.187.60.34 US, United States 08/Jan/2025:12:15:26 /travel/china/hong-kong.html

Here's what's going on.

Each line above is a request from a client, extracted from Nginx's /var/www/logs/httpd-access.log file. The client IP address, timestamp, and requested path were selected with awk and the client IP address converted to a country if possible with geoiplookup.

Geolocate IP

You can use a service such as Abstract's IP geolocation to check if the conversion was successful, or if the client IP address is the exit portal of a VPN.

The first 3 octets or first 24 bits of the IP address are used to specify the hue, with chroma at 75% and intensity at 100%. The resulting red, green, and blue values are scaled to the range of 0-255 and printed as two-character hexadecimal in an HTML style string.

Low-numbered /8 networks appear as red, 20.0.0.0/8 through 40.0.0.0/8 are orange shifting to yellow, 50.0.0.0/8 through 110.0.0.0/8 are shades of green, the /16 networks 130.0.0.0/16 through about 180.0.0.0/16 are shades of blue, then it's shades of purple into magenta for the /24 networks 192.0.0.0/24 and up through 223.255.255.0/24.

The HTML file on the server has a line where PHP uses passthru() to call the following shell script:

#!/bin/sh

# Initial pipeline:
# tail		Just the last 200 (or slightly less after the grep)
# grep		... just the requests out of that
# cat | sort	... put into reverse order
# sed		... remove the quotes and square brackets
# awk		... print the IP address twice, timestamp, and requested path
# sed		... remove the first 3 dots to split first version of IP
#			address into octets, and remove any characters that
#			could cause trouble when inserted into this page
# I need to use the client IP address, field #5 at that point, to call
# geoiplookup.  So, send the initial pipeline into a while loop that
# assigns variables, sets a new variable, and then echoes the resulting
# collection into awk.
tail -200 /var/www/logs/access_log |
	grep 'GET.*200' |
	cat -n | sort -nr |
	sed -e 's/"/ /g' -e 's/\[//g' -e 's/\]//g' |
	awk '{print $2, $2, $5, $8}' |
	sed -e 's/\./ /' -e 's/\./ /' -e 's/\./ /' -e 's/[<>]//g' |
	while read IP1 IP2 IP3 IP4 CLIENTIP TIMESTAMP URL
	do
		COUNTRY=$( geoiplookup $CLIENTIP |
				sed 's/.*Edition: //' |
				sed 's/IP Address not found/Unknown/' )
		echo $IP1 $IP2 $IP3 $IP4 $CLIENTIP $COUNTRY $TIMESTAMP $URL |
		awk '{
			ip1 = $1;
			ip2 = $2;
			ip3 = $3;
			chroma = 0.75;
			hue = 6*(ip1*255*255 + ip2*255 + ip3)/(255*255*255);
			if (hue%2 > 1) {
				x = chroma*(1.0 - (hue%2 - 1));
			} else {
				x = chroma*(1.0 - (1 - hue%2));
			}
			if (hue < 1.0) {
				r = chroma;
				g = x;
				b = 0;
			} else if (hue < 2.0) {
				r = x;
				g = chroma;
				b = 0;
			} else if (hue < 3.0) {
				r = 0;
				g = chroma;
				b = x;
			} else if (hue < 4.0) {
				r = 0;
				g = x;
				b = chroma;
			} else if (hue < 5.0) {
				r = x;
				g = 0;
				b = chroma;
			} else {
				r = chroma;
				g = 0;
				b = x;
			}
			r = (r + 0.25)*255;
			g = (g + 0.25)*255;
			b = (b + 0.25)*255;

			printf("<div class=\"col-12 textleft\" ");
			printf("style=\"color:#000; background:#%02x%02x%02x;\"> ", r, g, b);
			for (i = 5; i <= NF; i++) {
				printf("%s ", $i);
			}
			printf("</div>\n");
		}'
	done 

Other Pages