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 21/Aug/2019:02:32:21 /travel/usa/new-york-roosevelts/Index.html US, United States 21/Aug/2019:02:32:15 /cybersecurity/cloud-survey.html US, United States 21/Aug/2019:02:32:15 /robots.txt US, United States 21/Aug/2019:02:32:02 /radio/j-poles.html?s=tweetbot US, United States 21/Aug/2019:02:31:52 /open-source/raspberry-pi/sdr-ads-b-flight-tracking.html US, United States 21/Aug/2019:02:31:28 /travel/syria/damascus.html?s=tweetbot US, United States 21/Aug/2019:02:31:18 /travel/italy/umbria/?s=tweetbot US, United States 21/Aug/2019:02:30:37 /travel/usa/new-york-sro-flophouses/ US, United States 21/Aug/2019:02:30:36 /robots.txt US, United States 21/Aug/2019:02:30:24 /robots.txt FR, France 21/Aug/2019:02:29:52 /travel/italy/cinque-terre/ FR, France 21/Aug/2019:02:29:28 /travel/estonia/?s=tb US, United States 21/Aug/2019:02:29:24 /travel/belgium/bastogne-ardennes/ CA, Canada 21/Aug/2019:02:29:14 /radio/j-poles.html US, United States 21/Aug/2019:02:29:10 /travel/usa/new-york-internet/ IN, India 21/Aug/2019:02:28:40 /travel/estonia/?s=tb IN, India 21/Aug/2019:02:28:40 /robots.txt US, United States 21/Aug/2019:02:28:34 /travel/estonia/?s=tb EG, Egypt 21/Aug/2019:02:28:33 /turkish/verbs.html US, United States 21/Aug/2019:02:28:32 /radio/tv-antenna.html US, United States 21/Aug/2019:02:28:30 /radio/tv-antenna.html EG, Egypt 21/Aug/2019:02:28:24 /turkish/verbs.html DE, Germany 21/Aug/2019:02:28:19 /travel/estonia/?s=tb US, United States 21/Aug/2019:02:28:16 /travel/estonia/?s=tb US, United States 21/Aug/2019:02:28:06 /travel/estonia/?s=tb US, United States 21/Aug/2019:02:28:01 /travel/estonia/?s=tb US, United States 21/Aug/2019:02:27:44 /travel/turkey/nemrut-dagi/ US, United States 21/Aug/2019:02:27:26 /travel/belgium/bastogne-ardennes/ KR, Korea, Republic of 21/Aug/2019:02:27:15 /travel/japan/kofun/ishibutai.html AU, Australia 21/Aug/2019:02:26:47 /open-source/pdf-not-authorized.html US, United States 21/Aug/2019:02:26:44 /travel/usa/detroit/ US, United States 21/Aug/2019:02:26:41 /travel/japan/kofun/ishibutai.html US, United States 21/Aug/2019:02:26:38 /robots.txt KR, Korea, Republic of 21/Aug/2019:02:26:32 /travel/japan/kofun/ishibutai.html US, United States 21/Aug/2019:02:26:18 /travel/france/marseille/ US, United States 21/Aug/2019:02:26:00 /turkish/word-order.html US, United States 21/Aug/2019:02:25:59 /robots.txt EG, Egypt 21/Aug/2019:02:25:57 /turkish/word-order.html US, United States 21/Aug/2019:02:25:50 /robots.txt FR, France 21/Aug/2019:02:25:50 /travel/uk/orkney-neolithic/?s=tb EG, Egypt 21/Aug/2019:02:25:27 /turkish/verbs.html CZ, Czech Republic 21/Aug/2019:02:25:20 /robots.txt CO, Colombia 21/Aug/2019:02:25:06 /radio/ic-3220.html US, United States 21/Aug/2019:02:24:52 /open-source/raspberry-pi/ads-b-antenna.html US, United States 21/Aug/2019:02:24:20 /travel/japan/kyoto/nishiki-koji-dori/?s=tweetbot US, United States 21/Aug/2019:02:24:09 /networking/ US, United States 21/Aug/2019:02:23:26 /travel/gsm-sim-card/ US, United States 21/Aug/2019:02:23:02 /travel/greece/greek/?s=tweetbot US, United States 21/Aug/2019:02:22:32 /fun/brilliant-movie-ideas/unholy-unions.html US, United States 21/Aug/2019:02:22:24 /open-source/google-freebsd-tls/apache-log-cache.html US, United States 21/Aug/2019:02:22:00 /radio/ic2sat-part-2.html ZA, South Africa 21/Aug/2019:02:21:52 /open-source/openbsd-qemu-windows-howto.html US, United States 21/Aug/2019:02:21:36 /open-source/performance-tuning/ethernet.html US, United States 21/Aug/2019:02:21:35 /travel/uk/edinburgh/?s=tweetbot CN, China 21/Aug/2019:02:21:15 /open-source/performance-tuning/ethernet.html RU, Russian Federation 21/Aug/2019:02:20:59 /technical/pal-to-ntsc.html US, United States 21/Aug/2019:02:20:34 /travel/belgium/bastogne-ardennes/background.html US, United States 21/Aug/2019:02:20:09 /cybersecurity/hostile/bagel.html US, United States 21/Aug/2019:02:19:47 /turkish/turkish-verbs.pdf US, United States 21/Aug/2019:02:19:10 /travel/france/thomas-jefferson/ US, United States 21/Aug/2019:02:19:08 /radio/tek2445a.html US, United States 21/Aug/2019:02:18:47 /travel/france/thomas-jefferson/ EG, Egypt 21/Aug/2019:02:18:40 /turkish/verbs.html GB, United Kingdom 21/Aug/2019:02:18:18 /travel/uk/the-road-to-the-isles/creaguaineach-staoineag.html US, United States 21/Aug/2019:02:18:03 /networking/nat.html US, United States 21/Aug/2019:02:18:03 /networking/ US, United States 21/Aug/2019:02:17:42 /technical/wma-or-flac-to-mp3.html HK, Hong Kong 21/Aug/2019:02:17:40 /open-source/performance-tuning/tcp.html US, United States 21/Aug/2019:02:17:31 /open-source/crashdumps.html GB, United Kingdom 21/Aug/2019:02:17:23 /travel/turkey/ephesus/ US, United States 21/Aug/2019:02:17:09 /travel/usa/new-york-mcgees/ US, United States 21/Aug/2019:02:17:00 /networking/commands.html AU, Australia 21/Aug/2019:02:16:46 /open-source/performance-tuning/ethernet.html FR, France 21/Aug/2019:02:16:16 /travel/france/avignon/chateauneuf-du-pape.html US, United States 21/Aug/2019:02:16:16 /travel/turkey/ US, United States 21/Aug/2019:02:15:58 /open-source/performance-tuning/ethernet.html US, United States 21/Aug/2019:02:15:57 /travel/uk/dover/ US, United States 21/Aug/2019:02:15:32 /cybersecurity/isc2-ccsp/ US, United States 21/Aug/2019:02:14:50 /travel/japan/tokyo-ameya-yokocho/ US, United States 21/Aug/2019:02:14:47 /turkish/turkish-nouns.tex US, United States 21/Aug/2019:02:14:20 /open-source/tar-and-ssh.html FR, France 21/Aug/2019:02:14:17 /3d/histogram/Index.html US, United States 21/Aug/2019:02:13:31 /open-source/performance-tuning/applications.html US, United States 21/Aug/2019:02:13:27 /travel/belgium/namur-dinant-ardennes/ US, United States 21/Aug/2019:02:13:24 /travel/greece/thessaloniki.html US, United States 21/Aug/2019:02:12:47 /

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