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?


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. HU, Hungary 06/May/2021:17:56:06 /travel/usa/new-york-phone-booths/ RU, Russian Federation 06/May/2021:17:56:04 /travel/usa/new-york-marvel/ IT, Italy 06/May/2021:17:55:36 /networking/vlan.html US, United States 06/May/2021:17:54:59 /open-source/performance-tuning/nfs.html CN, China 06/May/2021:17:54:13 /open-source/samba-active-directory/samba.html US, United States 06/May/2021:17:54:09 /travel/latvia/ US, United States 06/May/2021:17:54:09 /robots.txt FR, France 06/May/2021:17:54:01 /oliver-cromwell/crom-fu-fighting.html US, United States 06/May/2021:17:53:22 /travel/uk/scapa-flow/Index.html US, United States 06/May/2021:17:53:11 /ads.txt NO, Norway 06/May/2021:17:52:55 /open-source/google-freebsd-tls/tls-certificate.html VN, Vietnam 06/May/2021:17:52:38 /technical/convert-youtube-to-xvid.html US, United States 06/May/2021:17:52:36 /open-source/migrate-rhel-to-centos.html CA, Canada 06/May/2021:17:52:07 /open-source/performance-tuning/ethernet.html Unknown 06/May/2021:17:52:00 /technical/hdmi.html US, United States 06/May/2021:17:51:45 /cybersecurity/how-rsa-works.html?infolinks=no IE, Ireland 06/May/2021:17:51:12 /technical/dsl/ FR, France 06/May/2021:17:51:09 /cybersecurity/scam-analysis.html US, United States 06/May/2021:17:51:03 /travel/usa/new-york-revolutionary/catholic-worker.html US, United States 06/May/2021:17:51:02 /travel/italy/amalfi/02-the-sights-in-amalfi-and-atrani.html US, United States 06/May/2021:17:51:02 /travel/france/budget-hotels/ US, United States 06/May/2021:17:51:01 /travel/uk/edinburgh/ US, United States 06/May/2021:17:50:52 /open-source/migrate-rhel-to-centos.html IT, Italy 06/May/2021:17:50:50 /cybersecurity/crypto/cipher-strength.html?s=tb PL, Poland 06/May/2021:17:50:40 /travel/france/ronin/ RU, Russian Federation 06/May/2021:17:50:37 /site-map.html RU, Russian Federation 06/May/2021:17:50:34 /robots.txt IE, Ireland 06/May/2021:17:50:34 /technical/dsl/ US, United States 06/May/2021:17:50:18 /travel/usa/new-york-marvel/ US, United States 06/May/2021:17:50:12 /travel/usa/new-york-hp-lovecraft/ CN, China 06/May/2021:17:50:10 /travel/usa/new-york-jewish-les/stanton-rivington.html US, United States 06/May/2021:17:50:10 /open-source/performance-tuning/disks.html US, United States 06/May/2021:17:50:08 /open-source/raspberry-pi/sdr-ads-b-flight-tracking.html TN, Tunisia 06/May/2021:17:50:06 /3d/histogram/ US, United States 06/May/2021:17:50:04 /open-source/performance-tuning/disks.html BR, Brazil 06/May/2021:17:49:57 /open-source/performance-tuning/disks.html Unknown 06/May/2021:17:49:37 /travel/usa/new-york-phone-booths/ US, United States 06/May/2021:17:49:26 /open-source/package-management.html AR, Argentina 06/May/2021:17:49:19 /open-source/package-management.html US, United States 06/May/2021:17:49:16 /open-source/raspberry-pi/sdr-ads-b-flight-tracking.html US, United States 06/May/2021:17:49:16 /cybersecurity/how-rsa-works.html?infolinks=no US, United States 06/May/2021:17:49:15 /open-source/raspberry-pi/sdr-ads-b-flight-tracking.html US, United States 06/May/2021:17:49:13 /open-source/raspberry-pi/sdr-ads-b-flight-tracking.html US, United States 06/May/2021:17:49:09 /travel/usa/new-york-internet/ US, United States 06/May/2021:17:49:07 /open-source/dev-random.html CA, Canada 06/May/2021:17:48:59 /cybersecurity/comptia/domain-2.html FR, France 06/May/2021:17:48:57 /open-source/performance-tuning/tcp.html CA, Canada 06/May/2021:17:48:56 /cybersecurity/comptia/domain-1.html US, United States 06/May/2021:17:48:41 /cybersecurity/ US, United States 06/May/2021:17:48:41 /turkish/ US, United States 06/May/2021:17:48:41 /radio/ US, United States 06/May/2021:17:48:41 /open-source/ US, United States 06/May/2021:17:48:41 /networking/ US, United States 06/May/2021:17:48:41 /fun/ US, United States 06/May/2021:17:48:40 /russian/ US, United States 06/May/2021:17:48:40 /3d/ US, United States 06/May/2021:17:48:40 /travel/ US, United States 06/May/2021:17:48:40 /technical/ US, United States 06/May/2021:17:48:40 / US, United States 06/May/2021:17:48:39 / US, United States 06/May/2021:17:48:26 /travel/usa/new-york-internet/ US, United States 06/May/2021:17:48:09 /open-source/openbsd-qemu-windows-howto.html DE, Germany 06/May/2021:17:47:53 /cybersecurity/crypto/cipher-strength.html?s=tb JP, Japan 06/May/2021:17:47:43 /fun/foxnews.html US, United States 06/May/2021:17:47:32 /technical/hdmi.html US, United States 06/May/2021:17:47:32 /cybersecurity/how-rsa-works.html?infolinks=no FR, France 06/May/2021:17:47:32 /travel/italy/cinque-terre/?s=tb US, United States 06/May/2021:17:47:15 /technical/hdmi.html US, United States 06/May/2021:17:47:13 /technical/hdmi.html US, United States 06/May/2021:17:46:39 / US, United States 06/May/2021:17:46:38 /travel/usa/new-york-phone-booths/ US, United States 06/May/2021:17:45:03 /travel/usa/new-york-phone-booths/ US, United States 06/May/2021:17:45:00 /travel/uk/ben-nevis/ AR, Argentina 06/May/2021:17:44:39 /technical/samsung-galaxy/linux.html US, United States 06/May/2021:17:44:38 /cybersecurity/how-rsa-works.html?infolinks=no US, United States 06/May/2021:17:44:17 /cybersecurity/how-rsa-works.html?infolinks=no US, United States 06/May/2021:17:44:10 /travel/usa/new-york-phone-booths/ FR, France 06/May/2021:17:43:54 /travel/italy/trains/ PL, Poland 06/May/2021:17:43:50 /open-source/performance-tuning/ethernet.html MX, Mexico 06/May/2021:17:43:41 /turkish/orthography.html US, United States 06/May/2021:17:43:34 /open-source/performance-tuning/tcp.html GB, United Kingdom 06/May/2021:17:43:23 /cybersecurity/pki-failures.html SK, Slovakia 06/May/2021:17:43:18 /travel/turkey/temple-of-artemis/ CN, China 06/May/2021:17:43:11 /travel/china/hong-kong.html US, United States 06/May/2021:17:43:02 /radio/tv-antenna.html US, United States 06/May/2021:17:42:58 /cybersecurity/how-rsa-works.html US, United States 06/May/2021:17:42:56 /travel/usa/new-york-phone-booths/ US, United States 06/May/2021:17:42:56 /open-source/ US, United States 06/May/2021:17:42:47 /travel/uk/dover/ US, United States 06/May/2021:17:42:42 /travel/uk/dover/ US, United States 06/May/2021:17:42:21 /cybersecurity/how-rsa-works.html?infolinks=no FR, France 06/May/2021:17:41:53 /open-source/performance-tuning/file-systems.html KR, Korea, Republic of 06/May/2021:17:41:49 /open-source/torrent-magnet-links.html US, United States 06/May/2021:17:41:35 /travel/japan/kofun/empress-hibasuhime.html?s=tb US, United States 06/May/2021:17:41:25 /cybersecurity/crypto/diffie-hellman.html?s=tb US, United States 06/May/2021:17:41:17 /open-source/google-freebsd-tls/apache-http2-php.html CA, Canada 06/May/2021:17:41:15 /travel/japan/kofun/empress-hibasuhime.html?s=tb US, United States 06/May/2021:17:40:47 /networking/netstat-s.html ES, Spain 06/May/2021:17:40:47 /travel/france/jim-morrison-paris.html US, United States 06/May/2021:17:40:41 /open-source/samba-active-directory/samba.html FR, France 06/May/2021:17:40:19 /travel/france/mont-saint-michel-saint-malo/pontorson.html US, United States 06/May/2021:17:40:07 /cybersecurity/crypto/diffie-hellman.html US, United States 06/May/2021:17:40:06 /cybersecurity/crypto/diffie-hellman.html?s=tb US, United States 06/May/2021:17:40:00 /robots.txt US, United States 06/May/2021:17:39:32 /travel/usa/new-york-mcgees/ CA, Canada 06/May/2021:17:39:27 /travel/usa/new-york-mcgees/ US, United States 06/May/2021:17:39:22 /travel/japan/kofun/empress-hibasuhime.html?s=tb DE, Germany 06/May/2021:17:39:20 /travel/japan/kofun/empress-hibasuhime.html?s=tb US, United States 06/May/2021:17:39:16 /travel/japan/kofun/empress-hibasuhime.html?s=tb US, United States 06/May/2021:17:39:07 /travel/japan/kofun/empress-hibasuhime.html?s=tb US, United States 06/May/2021:17:39:03 /cybersecurity/crypto/diffie-hellman.html US, United States 06/May/2021:17:39:02 /cybersecurity/crypto/diffie-hellman.html?s=tb FR, France 06/May/2021:17:39:02 /travel/japan/kofun/empress-hibasuhime.html?s=tb CA, Canada 06/May/2021:17:39:02 /travel/japan/kofun/empress-hibasuhime.html?s=tb US, United States 06/May/2021:17:39:01 /travel/france/budget-hotels/ US, United States 06/May/2021:17:39:01 /travel/japan/kofun/empress-hibasuhime.html?s=tb GB, United Kingdom 06/May/2021:17:38:46 /travel/usa/washington-lee-mansion/?s=tb IN, India 06/May/2021:17:38:06 /travel/france/avignon/avignon-papacy.html?s=tb US, United States 06/May/2021:17:37:46 /open-source/raspberry-pi/openvas.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.

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, through are orange shifting to yellow, through are shades of green, the /16 networks through about are shades of blue, then it's shades of purple into magenta for the /24 networks and up through

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


# 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' |
		COUNTRY=$( geoiplookup $CLIENTIP |
				sed 's/.*Edition: //' |
				sed 's/IP Address not found/Unknown/' )
		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);

Other Pages