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?

Maybe...

First, let's look at the result, then the explanation comes later. Here are the 200 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.

46.41.0.186 Unknown 23/Feb/2017:12:32:49 /linux/samba-active-directory/dns.html
82.8.131.248 GB, United Kingdom 23/Feb/2017:12:32:49 /travel/uk/scotland-isle-of-iona/
209.58.135.66 US, United States 23/Feb/2017:12:32:48 /technical/ata-ide-sata-usb-cable-pinouts.html
174.218.11.78 US, United States 23/Feb/2017:12:32:45 /technical/ata-ide-sata-usb-cable-pinouts.html
54.159.242.217 US, United States 23/Feb/2017:12:32:43 /fun/sarah-palin-baby-name-generator.html
173.26.58.151 US, United States 23/Feb/2017:12:32:42 /travel/france/school-lunch-menus/
66.102.8.21 US, United States 23/Feb/2017:12:32:41 /linux/performance-tuning/disks.html
54.159.242.217 US, United States 23/Feb/2017:12:32:37 /travel/belgium/bastogne-ardennes/houffalize-malmedy-st-hubert.html
208.87.237.201 US, United States 23/Feb/2017:12:32:37 /travel/france/school-lunch-menus/
54.159.242.217 US, United States 23/Feb/2017:12:32:30 /fun/brilliant-movie-ideas/news.html
54.159.242.217 US, United States 23/Feb/2017:12:32:23 /cybersecurity/availability.html
209.58.135.66 US, United States 23/Feb/2017:12:32:23 /fun/requests-for-quotes/tongan-misdirection/
54.159.242.217 US, United States 23/Feb/2017:12:32:15 /travel/france/provence-megaliths/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:32:10 /cybersecurity/html-email.html
66.39.169.114 US, United States 23/Feb/2017:12:32:06 /fun/requests-for-quotes/tongan-misdirection/
54.159.242.217 US, United States 23/Feb/2017:12:32:05 /travel/athens-to-paris/budapest-prague.html
66.249.69.139 US, United States 23/Feb/2017:12:32:03 /linux/crashdumps.html
54.159.242.217 US, United States 23/Feb/2017:12:31:59 /travel/trinidad/Index.html
46.235.156.18 Unknown 23/Feb/2017:12:31:59 /linux/performance-tuning/disks.html
54.159.242.217 US, United States 23/Feb/2017:12:31:53 /travel/turkey/olimpos/Index.html
162.247.71.250 Unknown 23/Feb/2017:12:31:49 /3d/xray/
54.159.242.217 US, United States 23/Feb/2017:12:31:47 /linux/raspberry-pi/nas.html
54.159.242.217 US, United States 23/Feb/2017:12:31:41 /cybersecurity/crypto/diffie-hellman.html
54.159.242.217 US, United States 23/Feb/2017:12:31:37 /linux/Index.html
54.209.240.103 US, United States 23/Feb/2017:12:31:35 /linux/samba-active-directory/
54.159.242.217 US, United States 23/Feb/2017:12:31:32 /travel/france/budget-hotels/Index.html
46.41.0.186 Unknown 23/Feb/2017:12:31:27 /linux/samba-active-directory/
54.159.242.217 US, United States 23/Feb/2017:12:31:26 /travel/france/normandy/omaha-beach.html
54.159.242.217 US, United States 23/Feb/2017:12:31:21 /cybersecurity/netusers/Index/kur
54.159.242.217 US, United States 23/Feb/2017:12:31:15 /travel/usa/us-wash-nss.html
54.159.242.217 US, United States 23/Feb/2017:12:31:09 /cybersecurity/netusers/Index/au
54.159.242.217 US, United States 23/Feb/2017:12:31:04 /travel/usa/san-francisco/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:30:59 /cybersecurity/netusers/Index/fr
54.159.242.217 US, United States 23/Feb/2017:12:30:53 /linux/ssh-1-admin.html
54.159.242.217 US, United States 23/Feb/2017:12:30:47 /linux/apache-https-x509v3.html
54.159.242.217 US, United States 23/Feb/2017:12:30:41 /fun/requests-for-quotes/marlow-willard/Index.html
37.203.127.204 Unknown 23/Feb/2017:12:30:37 /technical/google-adsense-and-xhtml.html
54.159.242.217 US, United States 23/Feb/2017:12:30:36 /cybersecurity/extortion.html
54.159.242.217 US, United States 23/Feb/2017:12:30:31 /travel/uk/hadrians-wall/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:30:25 /linux/raspberry-pi/networking.html
54.159.242.217 US, United States 23/Feb/2017:12:30:18 /travel/usa/new-york-les-stanton/Index.html
157.253.167.244 CO, Colombia 23/Feb/2017:12:30:17 /technical/samsung-galaxy/linux.html
66.249.69.229 US, United States 23/Feb/2017:12:30:17 /cybersecurity/infosec-response.html
54.159.242.217 US, United States 23/Feb/2017:12:30:13 /technical/extract-mp3-audio-from-video.html
54.159.242.217 US, United States 23/Feb/2017:12:30:07 /fun/teaching/math-trouble.html
54.159.242.217 US, United States 23/Feb/2017:12:30:00 /travel/mexico/teotihuacan.html
54.159.242.217 US, United States 23/Feb/2017:12:29:54 /travel/uk/glastonbury/king-arthur.html
54.159.242.217 US, United States 23/Feb/2017:12:29:48 /brewing/brewing-references.html
145.129.8.198 NL, Netherlands 23/Feb/2017:12:29:45 /technical/samsung-galaxy/block-calls.html
100.34.229.65 Unknown 23/Feb/2017:12:29:44 /turkish/
54.159.242.217 US, United States 23/Feb/2017:12:29:42 /travel/uk/the-road-to-the-isles/luibeilt-steall.html
54.159.242.217 US, United States 23/Feb/2017:12:29:36 /fun/freudian-seuss.html
54.159.242.217 US, United States 23/Feb/2017:12:29:30 /cybersecurity/netusers/Index/sr
54.159.242.217 US, United States 23/Feb/2017:12:29:24 /travel/greece/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:29:20 /travel/romania/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:29:14 /cybersecurity/netusers/Index/lv
54.159.242.217 US, United States 23/Feb/2017:12:29:09 /travel/megaliths/Index.html
177.129.75.154 Unknown 23/Feb/2017:12:29:04 /linux/performance-tuning/disks.html
54.159.242.217 US, United States 23/Feb/2017:12:29:03 /networking/nat.html
54.159.242.217 US, United States 23/Feb/2017:12:28:56 /linux/rhel-centos-5-6-7/users-groups.html
54.159.242.217 US, United States 23/Feb/2017:12:28:49 /cybersecurity/crypto/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:28:42 /travel/greece/greek-mainland.html
54.159.242.217 US, United States 23/Feb/2017:12:28:37 /travel/latvia/Index.html
54.81.91.137 US, United States 23/Feb/2017:12:28:31 /travel/usa/detroit/
54.159.242.217 US, United States 23/Feb/2017:12:28:31 /travel/russia/goodwill.html
104.129.196.153 Unknown 23/Feb/2017:12:28:25 /travel/usa/detroit/
54.159.242.217 US, United States 23/Feb/2017:12:28:25 /travel/usa/new-york-fictional-architecture/midtown.html
54.159.242.217 US, United States 23/Feb/2017:12:28:19 /cybersecurity/netusers/Index/na
54.159.242.217 US, United States 23/Feb/2017:12:28:13 /cybersecurity/descrambler.html
54.159.242.217 US, United States 23/Feb/2017:12:28:07 /travel/turkey/maryemana/koran-sura-19.html
24.42.234.50 US, United States 23/Feb/2017:12:28:04 /turkish/
95.10.21.196 Unknown 23/Feb/2017:12:28:03 /
95.10.21.196 Unknown 23/Feb/2017:12:28:02 /radio/probes.html
54.159.242.217 US, United States 23/Feb/2017:12:28:01 /cybersecurity/ssh-attack-study.html
54.159.242.217 US, United States 23/Feb/2017:12:27:55 /wshta/2011-10-08/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:27:48 /travel/turkey/konya/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:27:42 /travel/usa/new-york-st-marks-place/2nd-1st-south.html
54.159.242.217 US, United States 23/Feb/2017:12:27:36 /technical/how-to-copy-dvds.html
54.159.242.217 US, United States 23/Feb/2017:12:27:30 /linux/linux-blog.html
54.159.242.217 US, United States 23/Feb/2017:12:27:23 /linux/raspberry-pi/hardware.html
45.251.232.72 US, United States 23/Feb/2017:12:27:20 /
45.251.232.72 US, United States 23/Feb/2017:12:27:20 /radio/probes.html
54.159.242.217 US, United States 23/Feb/2017:12:27:17 /linux/apache-referer-log-analysis.html
129.21.176.115 US, United States 23/Feb/2017:12:27:12 /cybersecurity/virtualization.html
54.159.242.217 US, United States 23/Feb/2017:12:27:10 /linux/compiling-opencv-on-openbsd.html
54.159.242.217 US, United States 23/Feb/2017:12:27:03 /cybersecurity/history/uss-chaumont/photos-other.html
151.40.115.130 IT, Italy 23/Feb/2017:12:26:57 /linux/rhel-centos-5-6-7/
54.159.242.217 US, United States 23/Feb/2017:12:26:55 /travel/japan/tokyo-rinno-ji.html
68.180.230.58 US, United States 23/Feb/2017:12:26:54 /3d/3d-registration.html
54.159.242.217 US, United States 23/Feb/2017:12:26:48 /travel/bulgaria/Index.html
54.197.142.25 US, United States 23/Feb/2017:12:26:42 /travel/usa/new-york-black-chamber/
193.201.224.205 UA, Ukraine 23/Feb/2017:12:26:42 /radio/probes.html?action=upload_image&gallery_id=0&gallery_name=../../../../wp-config.php
54.159.242.217 US, United States 23/Feb/2017:12:26:42 /cybersecurity/hoax.html
54.159.242.217 US, United States 23/Feb/2017:12:26:36 /travel/uk/orkney-neolithic/stones-of-stenness.html
193.201.224.205 UA, Ukraine 23/Feb/2017:12:26:35 /radio/probes.html?mdocs-img-preview=../../../wp-config.php
72.21.217.140 US, United States 23/Feb/2017:12:26:31 /travel/usa/new-york-black-chamber/
198.51.243.19 US, United States 23/Feb/2017:12:26:29 /travel/usa/new-york-black-chamber/
54.159.242.217 US, United States 23/Feb/2017:12:26:29 /cybersecurity/hostile/trojan-exchanger.html
54.159.242.217 US, United States 23/Feb/2017:12:26:23 /cybersecurity/netusers/Index/gg
38.130.175.51 US, United States 23/Feb/2017:12:26:17 /linux/linux-kernel.html
54.159.242.217 US, United States 23/Feb/2017:12:26:17 /linux/ssh.html
54.159.242.217 US, United States 23/Feb/2017:12:26:10 /radio/mwdx.html
84.180.170.63 DE, Germany 23/Feb/2017:12:26:06 /technical/samsung-galaxy/linux.html
54.159.242.217 US, United States 23/Feb/2017:12:26:04 /steampunk/power-and-light.html
193.201.224.205 UA, Ukraine 23/Feb/2017:12:26:03 /
207.46.13.125 US, United States 23/Feb/2017:12:26:02 /technical/ata-ide-sata-usb-cable-pinouts.html
54.159.242.217 US, United States 23/Feb/2017:12:25:58 /cybersecurity/netusers/Index/su
66.249.91.65 US, United States 23/Feb/2017:12:25:55 /turkish/verbs.html
54.159.242.217 US, United States 23/Feb/2017:12:25:50 /travel/italy/amalfi/02-the-sights-in-amalfi-and-atrani.html
35.157.149.219 US, United States 23/Feb/2017:12:25:49 /linux/openbsd-wireless-wpa2.html
35.157.149.219 US, United States 23/Feb/2017:12:25:46 /robots.txt
141.0.15.35 DE, Germany 23/Feb/2017:12:25:46 /turkish/turkish-verbs.tex
54.159.242.217 US, United States 23/Feb/2017:12:25:43 /travel/france/boat/tying-up-and-weather.html
54.159.242.217 US, United States 23/Feb/2017:12:25:36 /3d/extrema/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:25:29 /travel/belgium/namur-dinant-ardennes/Index.html
54.159.242.217 US, United States 23/Feb/2017:12:25:22 /travel/greece/thessaloniki.html
54.159.242.217 US, United States 23/Feb/2017:12:25:16 /cybersecurity/netusers/Index/id

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, 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-xs-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