Rack of Ethernet switches.

Visualizing Log Patterns with Color

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. US, United States 25/Apr/2019:01:47:40 /robots.txt RU, Russian Federation 25/Apr/2019:01:47:38 /travel/japan/ise/ US, United States 25/Apr/2019:01:46:46 / IN, India 25/Apr/2019:01:46:40 / US, United States 25/Apr/2019:01:46:39 /cybersecurity/comptia/ US, United States 25/Apr/2019:01:46:09 /travel/france/normandy/arromanches.html US, United States 25/Apr/2019:01:46:07 /robots.txt US, United States 25/Apr/2019:01:45:55 /cybersecurity/cyberwar/ US, United States 25/Apr/2019:01:45:54 /travel/france/normandy/arromanches.html CA, Canada 25/Apr/2019:01:45:12 /travel/france/normandy/pegasus-bridge.html US, United States 25/Apr/2019:01:45:06 /open-source/performance-tuning/tcp.html US, United States 25/Apr/2019:01:45:05 /open-source/performance-tuning/tcp.html CN, China 25/Apr/2019:01:45:05 /open-source/performance-tuning/disks.html GB, United Kingdom 25/Apr/2019:01:44:43 /turkish/nouns.html AU, Australia 25/Apr/2019:01:44:29 /travel/belgium/bastogne-ardennes/ GB, United Kingdom 25/Apr/2019:01:44:02 /travel/usa/new-york-revolutionary/catholic-worker.html US, United States 25/Apr/2019:01:43:49 /technical/dsl/ US, United States 25/Apr/2019:01:43:42 /technical/dsl/ US, United States 25/Apr/2019:01:42:39 /radio/tv-antenna.html MY, Malaysia 25/Apr/2019:01:42:00 /travel/turkey/buses/ US, United States 25/Apr/2019:01:41:44 /travel/usa/new-york-jewish-les/?s=tweetbot GB, United Kingdom 25/Apr/2019:01:41:40 /travel/usa/new-york-jewish-les/stanton-rivington.html GB, United Kingdom 25/Apr/2019:01:41:15 /travel/france/jim-morrison-paris.html FR, France 25/Apr/2019:01:40:58 /radio/probes.html US, United States 25/Apr/2019:01:40:42 /travel/france/normandy/brecourt-manor.html US, United States 25/Apr/2019:01:40:34 /travel/france/normandy/arromanches.html US, United States 25/Apr/2019:01:40:33 /robots.txt US, United States 25/Apr/2019:01:40:09 /travel/usa/new-york-jewish-les/food-along-houston.html?s=tweetbot US, United States 25/Apr/2019:01:39:52 /radio/tv-antenna.html US, United States 25/Apr/2019:01:39:42 /cybersecurity/cyberwar/israel.html MD, Moldova, Republic of 25/Apr/2019:01:39:38 /technical/samsung-galaxy/linux.html FR, France 25/Apr/2019:01:39:29 /text/reports/3alice.1.txt CN, China 25/Apr/2019:01:38:14 /technical/ NL, Netherlands 25/Apr/2019:01:37:27 /ads.txt US, United States 25/Apr/2019:01:37:24 /travel/usa/new-york-jewish-les/stanton-rivington.html US, United States 25/Apr/2019:01:37:14 /cybersecurity/cyberwar/history.html US, United States 25/Apr/2019:01:37:13 /technical/hp-printer-ready-message.html US, United States 25/Apr/2019:01:36:34 /cybersecurity/cyberwar/ CN, China 25/Apr/2019:01:36:15 /open-source/letsencrypt-tls-cert-godaddy.html US, United States 25/Apr/2019:01:34:57 /turkish/verbs.html US, United States 25/Apr/2019:01:33:43 /ads.txt CA, Canada 25/Apr/2019:01:33:23 /travel/france/normandy/omaha-beach.html US, United States 25/Apr/2019:01:33:08 /technical/dsl/ US, United States 25/Apr/2019:01:32:24 /travel/usa/us-wash-masonic.html US, United States 25/Apr/2019:01:30:52 /cybersecurity/root-password.html US, United States 25/Apr/2019:01:30:49 /open-source/performance-tuning/tcp.html US, United States 25/Apr/2019:01:30:46 /turkish/background.html US, United States 25/Apr/2019:01:30:28 / US, United States 25/Apr/2019:01:30:26 /turkish/nouns.html?ref=SeksDE.Com US, United States 25/Apr/2019:01:30:25 /cybersecurity/crypto/digital-signatures-and-certificates.html US, United States 25/Apr/2019:01:30:19 /turkish/ US, United States 25/Apr/2019:01:29:45 /cybersecurity/isc2-ccsp/operations.html US, United States 25/Apr/2019:01:29:10 /travel/uk/ben-nevis/ JP, Japan 25/Apr/2019:01:29:08 /technical/samsung-galaxy/secret-code.html JP, Japan 25/Apr/2019:01:29:07 /robots.txt US, United States 25/Apr/2019:01:29:02 /open-source/multiboot-windows-openbsd/ US, United States 25/Apr/2019:01:28:50 /cybersecurity/isc2-ccsp/ JP, Japan 25/Apr/2019:01:28:19 /networking/netstat-s.html US, United States 25/Apr/2019:01:28:17 /cybersecurity/root-password.html US, United States 25/Apr/2019:01:27:30 /fun/teaching/nsa-vs-spyware.html US, United States 25/Apr/2019:01:27:25 /oliver-cromwell/ US, United States 25/Apr/2019:01:26:44 /cybersecurity/monitoring.html GB, United Kingdom 25/Apr/2019:01:26:13 /travel/usa/us-wash-ah.html US, United States 25/Apr/2019:01:26:12 /travel/japan/kamakura/path-yagura.html US, United States 25/Apr/2019:01:26:01 /travel/usa/new-york-revolutionary/catholic-worker.html DE, Germany 25/Apr/2019:01:25:59 /fun/strange-signs.html DE, Germany 25/Apr/2019:01:25:50 / US, United States 25/Apr/2019:01:25:32 /cybersecurity/isc2-ccsp/ US, United States 25/Apr/2019:01:25:11 /cybersecurity/cyberwar/ CA, Canada 25/Apr/2019:01:25:06 /travel/france/normandy/utah-beach.html US, United States 25/Apr/2019:01:25:05 /travel/uk/the-road-to-the-isles/steall-glen-nevis.html US, United States 25/Apr/2019:01:24:53 /travel/usa/new-york-revolutionary/anarchists.html CA, Canada 25/Apr/2019:01:24:51 /travel/france/normandy/ CA, Canada 25/Apr/2019:01:24:35 /travel/france/normandy/ CA, Canada 25/Apr/2019:01:23:57 /technical/dsl/ US, United States 25/Apr/2019:01:23:28 /networking/terminology.html US, United States 25/Apr/2019:01:23:18 /open-source/sendmail-ssl.html US, United States 25/Apr/2019:01:23:07 /networking/switch-programming.html US, United States 25/Apr/2019:01:22:48 /travel/uk/lee-ho-fook/ US, United States 25/Apr/2019:01:22:08 /technical/samsung-galaxy/memory-upgrade.html US, United States 25/Apr/2019:01:21:45 /travel/france/mont-saint-michel-saint-malo/mont-saint-michel.html US, United States 25/Apr/2019:01:21:33 /technical/samsung-galaxy/linux.html JP, Japan 25/Apr/2019:01:21:32 /travel/france/mont-saint-michel-saint-malo/mont-saint-michel.html US, United States 25/Apr/2019:01:20:35 /technical/dsl/ US, United States 25/Apr/2019:01:20:20 /travel/russia/hospital.html US, United States 25/Apr/2019:01:19:59 /turkish/ CN, China 25/Apr/2019:01:19:14 / CN, China 25/Apr/2019:01:19:07 / CN, China 25/Apr/2019:01:19:03 / CA, Canada 25/Apr/2019:01:18:54 /travel/france/normandy/ US, United States 25/Apr/2019:01:18:19 /travel/china/guangzhou-2.html US, United States 25/Apr/2019:01:18:12 /technical/samsung-galaxy/secret-code.html US, United States 25/Apr/2019:01:17:21 /open-source/sendmail-ssl.html US, United States 25/Apr/2019:01:16:36 /travel/france/jim-morrison-paris.html GB, United Kingdom 25/Apr/2019:01:16:00 /technical/current-box.html US, United States 25/Apr/2019:01:14:40 /travel/usa/new-york-skate-manhattan/ CA, Canada 25/Apr/2019:01:14:39 /travel/belgium/bastogne-ardennes/ardennes-forest.html US, United States 25/Apr/2019:01:14:32 /travel/usa/new-york-mcgees/ DE, Germany 25/Apr/2019:01:13:39 / FR, France 25/Apr/2019:01:13:09 /travel/france/loire-valley/val-de-loire.html US, United States 25/Apr/2019:01:12:41 /radio/ US, United States 25/Apr/2019:01:12:39 /travel/usa/us-wash-ah.html

Here's what's going on.

Each line above is a request from a client, extracted from Apache's /var/www/logs/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