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.

54.205.153.192 US, United States 30/Mar/2017:03:56:11 /cybersecurity/authentication.html
54.205.153.192 US, United States 30/Mar/2017:03:56:10 /networking/vlan.html
54.205.153.192 US, United States 30/Mar/2017:03:56:09 /networking/netstat-a.html
54.205.153.192 US, United States 30/Mar/2017:03:56:07 /travel/uk/the-road-to-the-isles/glen-nevis-fort-william.html
54.205.153.192 US, United States 30/Mar/2017:03:56:06 /fun/teaching/ostrich.html
54.205.153.192 US, United States 30/Mar/2017:03:56:04 /cybersecurity/history/uss-chaumont/photos-navsourceorg.html
54.205.153.192 US, United States 30/Mar/2017:03:56:03 /linux/rpm-patch.html
54.205.153.192 US, United States 30/Mar/2017:03:56:02 /travel/usa/venice-california/Index.html
54.205.153.192 US, United States 30/Mar/2017:03:56:00 /cybersecurity/hostile/Index.html
54.205.153.192 US, United States 30/Mar/2017:03:55:59 /fun/brilliant-movie-ideas/no-worse.html
54.205.153.192 US, United States 30/Mar/2017:03:55:58 /linux/file-system.html
54.205.153.192 US, United States 30/Mar/2017:03:55:56 /travel/greece/paros.html
54.205.153.192 US, United States 30/Mar/2017:03:55:55 /technical/ata-ide-sata-usb-cable-pinouts.html
54.205.153.192 US, United States 30/Mar/2017:03:55:54 /linux/performance-tuning/ethernet.html
54.205.153.192 US, United States 30/Mar/2017:03:55:53 /travel/usa/new-york-roosevelts/Index.html
54.205.153.192 US, United States 30/Mar/2017:03:55:51 /travel/france/boat/maintenance.html
54.205.153.192 US, United States 30/Mar/2017:03:55:50 /cybersecurity/netusers/Index/it
54.205.153.192 US, United States 30/Mar/2017:03:55:49 /cybersecurity/sysaudit.html
54.205.153.192 US, United States 30/Mar/2017:03:55:47 /digsig/Index.html
54.205.153.192 US, United States 30/Mar/2017:03:55:46 /travel/uk/scotland-isle-of-iona/iona.html
54.205.153.192 US, United States 30/Mar/2017:03:55:45 /travel/italy/amalfi/Index.html
54.205.153.192 US, United States 30/Mar/2017:03:55:43 /fun/brilliant-movie-ideas/unholy-unions.html
54.205.153.192 US, United States 30/Mar/2017:03:55:42 /cybersecurity/netusers/Index/ca
54.205.153.192 US, United States 30/Mar/2017:03:55:40 /linux/crashdumps.html
54.205.153.192 US, United States 30/Mar/2017:03:55:39 /travel/france/boat-trip-canal-lateral-a-la-loire/briare-to-beaulieu-sur-loire.html
54.205.153.192 US, United States 30/Mar/2017:03:55:38 /linux/ftp-howto.html
54.205.153.192 US, United States 30/Mar/2017:03:55:36 /travel/uk/swingate-chain-home/Index.html
54.205.153.192 US, United States 30/Mar/2017:03:55:35 /radio/ic2sat-part-2.html
54.205.153.192 US, United States 30/Mar/2017:03:55:34 /cybersecurity/history/uss-chaumont/crewmen.html
2.14.95.132 Unknown 30/Mar/2017:03:55:33 /radio/hf-short-dipoles.html
54.205.153.192 US, United States 30/Mar/2017:03:55:32 /linux/raspberry-pi/sdr-ads-b-flight-tracking.html
54.205.153.192 US, United States 30/Mar/2017:03:55:31 /travel/russia/getting-there.html
54.205.153.192 US, United States 30/Mar/2017:03:55:30 /fun/teaching/us-vs-britain-vs-france.html
54.205.153.192 US, United States 30/Mar/2017:03:55:28 /linux/performance-tuning/Index.html
54.205.153.192 US, United States 30/Mar/2017:03:55:25 /cybersecurity/history/uk-wwii.html
54.205.153.192 US, United States 30/Mar/2017:03:55:23 /technical/samsung-galaxy/secret-code.html
54.205.153.192 US, United States 30/Mar/2017:03:55:20 /cybersecurity/netusers/Index/sf
185.171.62.39 Unknown 30/Mar/2017:03:55:18 /
145.253.98.194 DE, Germany 30/Mar/2017:03:55:18 /linux/performance-tuning/ethernet.html
185.171.62.39 Unknown 30/Mar/2017:03:55:18 /radio/probes.html
54.205.153.192 US, United States 30/Mar/2017:03:55:17 /travel/greece/orthodox-shrines.html
54.205.153.192 US, United States 30/Mar/2017:03:55:12 /linux/keyboard-mouse.html
54.205.153.192 US, United States 30/Mar/2017:03:55:11 /robots.txt
64.236.138.3 US, United States 30/Mar/2017:03:54:53 /linux/migrate-rhel-to-centos.html
66.249.79.88 US, United States 30/Mar/2017:03:54:52 /travel/italy/trains/
137.189.98.33 HK, Hong Kong 30/Mar/2017:03:54:51 /cybersecurity/
137.189.98.33 HK, Hong Kong 30/Mar/2017:03:53:59 /cybersecurity/crypto/cipher-strength.html
109.95.181.86 Unknown 30/Mar/2017:03:53:40 /
109.95.181.86 Unknown 30/Mar/2017:03:53:40 /radio/probes.html
84.146.202.41 DE, Germany 30/Mar/2017:03:53:24 /linux/vim-word-count.html
193.186.208.234 TR, Turkey 30/Mar/2017:03:53:15 /networking/nat.html
193.186.208.234 TR, Turkey 30/Mar/2017:03:53:14 /networking/routing.html
66.249.88.2 US, United States 30/Mar/2017:03:51:38 /technical/samsung-galaxy/linux.html
188.138.72.148 Unknown 30/Mar/2017:03:51:30 /travel/usa/new-york-lga-arrival/
223.136.54.74 Unknown 30/Mar/2017:03:51:30 /3d/histogram/
158.180.192.10 GB, United Kingdom 30/Mar/2017:03:51:28 /travel/usa/new-york-lga-arrival/
198.148.27.26 US, United States 30/Mar/2017:03:51:27 /
216.244.66.244 US, United States 30/Mar/2017:03:50:57 /travel/latvia/?D=D
64.140.171.210 US, United States 30/Mar/2017:03:50:51 /3d/xray/xsane.html
128.39.46.106 NO, Norway 30/Mar/2017:03:50:16 /linux/lvm-rescue-boot.html
66.249.79.41 US, United States 30/Mar/2017:03:49:43 /technical/google-adsense-and-xhtml.html
31.208.78.7 US, United States 30/Mar/2017:03:49:39 /russian/grammar.html
192.161.172.203 Unknown 30/Mar/2017:03:49:24 /networking/switch-programming.html
5.44.39.95 Unknown 30/Mar/2017:03:49:23 /turkish/verbs.html
68.180.228.61 US, United States 30/Mar/2017:03:49:05 /cybersecurity/crypto/digital-signatures-and-certificates.html
197.88.157.163 Unknown 30/Mar/2017:03:48:52 /
197.88.157.163 Unknown 30/Mar/2017:03:48:51 /radio/probes.html
36.37.90.197 Unknown 30/Mar/2017:03:48:06 /linux/sendmail-ssl.html
216.244.66.244 US, United States 30/Mar/2017:03:47:56 /robots.txt
216.244.66.244 US, United States 30/Mar/2017:03:47:56 /robots.txt
66.249.93.21 US, United States 30/Mar/2017:03:47:48 /turkish/nouns.html
93.46.192.20 IT, Italy 30/Mar/2017:03:47:40 /technical/samsung-galaxy/linux.html
37.124.2.88 Unknown 30/Mar/2017:03:47:30 /networking/commands.html
220.181.108.107 CN, China 30/Mar/2017:03:47:29 /
83.103.196.49 RO, Romania 30/Mar/2017:03:47:29 /
77.75.77.17 CZ, Czech Republic 30/Mar/2017:03:47:23 /travel/turkey/lycia/
77.75.77.17 CZ, Czech Republic 30/Mar/2017:03:47:22 /technical/video-camera-rotate.html
77.75.77.17 CZ, Czech Republic 30/Mar/2017:03:47:17 /robots.txt
212.112.121.104 KG, Kyrgyzstan 30/Mar/2017:03:47:02 /turkish/turkish-verbs.pdf
131.228.32.166 FI, Finland 30/Mar/2017:03:46:50 /linux/performance-tuning/disks.html
5.255.250.33 Unknown 30/Mar/2017:03:46:47 /linux/missing-gtk-modules.html
180.76.15.17 Unknown 30/Mar/2017:03:46:41 /cybersecurity/netusers/Index/cu
206.16.134.18 US, United States 30/Mar/2017:03:46:41 /turkish/
121.75.200.7 NZ, New Zealand 30/Mar/2017:03:46:39 /travel/france/boat/
89.145.95.72 GB, United Kingdom 30/Mar/2017:03:46:30 /travel/uk/glastonbury/king-arthur.html
89.145.95.72 GB, United Kingdom 30/Mar/2017:03:46:20 /robots.txt
46.229.164.98 Unknown 30/Mar/2017:03:46:18 /robots.txt
176.195.102.127 Unknown 30/Mar/2017:03:46:11 /turkish/verbs.html
95.84.151.42 Unknown 30/Mar/2017:03:46:11 /linux/lvm-rescue-boot.html
109.63.240.244 Unknown 30/Mar/2017:03:46:11 /linux/dev-random.html
188.32.232.208 Unknown 30/Mar/2017:03:46:11 /technical/samsung-galaxy/linux.html
78.111.190.161 UA, Ukraine 30/Mar/2017:03:45:35 /technical/ata-ide-sata-usb-cable-pinouts.html
121.75.200.7 NZ, New Zealand 30/Mar/2017:03:45:23 /travel/france/
66.249.79.45 US, United States 30/Mar/2017:03:44:35 /technical/samsung-galaxy/secret-code.html
54.89.153.246 US, United States 30/Mar/2017:03:44:34 /cybersecurity/os-specific.html
193.186.208.234 TR, Turkey 30/Mar/2017:03:44:31 /networking/protocols.html
188.138.75.141 Unknown 30/Mar/2017:03:44:30 /linux/unix-tips.html
194.62.210.160 GB, United Kingdom 30/Mar/2017:03:44:27 /linux/unix-tips.html
5.172.255.94 Unknown 30/Mar/2017:03:44:27 /cybersecurity/os-specific.html
42.120.160.22 Unknown 30/Mar/2017:03:43:55 /linux/linux-kernel.html
42.156.139.22 Unknown 30/Mar/2017:03:43:54 /linux/linux-kernel.html
58.49.207.38 CN, China 30/Mar/2017:03:43:48 /turkish/background.html
125.209.235.170 Unknown 30/Mar/2017:03:43:43 /technical/samsung-galaxy/linux.html
116.15.77.217 SG, Singapore 30/Mar/2017:03:43:21 /travel/japan/tokyo-ueno-koen.html
88.235.181.205 TR, Turkey 30/Mar/2017:03:43:08 /turkish/
180.76.15.16 Unknown 30/Mar/2017:03:43:06 /3d/xray/
116.15.77.217 SG, Singapore 30/Mar/2017:03:43:06 /travel/japan/tokyo-ueno-koen.html
193.186.208.234 TR, Turkey 30/Mar/2017:03:42:50 /networking/nat.html
193.186.208.234 TR, Turkey 30/Mar/2017:03:42:49 /networking/
193.186.208.234 TR, Turkey 30/Mar/2017:03:42:48 /networking/routing.html
72.21.217.113 US, United States 30/Mar/2017:03:42:24 /travel/france/boat/
121.75.200.7 NZ, New Zealand 30/Mar/2017:03:42:22 /travel/france/boat/
212.121.200.1 GB, United Kingdom 30/Mar/2017:03:42:10 /travel/uk/stonehenge/
209.126.103.239 US, United States 30/Mar/2017:03:42:04 /
157.55.39.142 US, United States 30/Mar/2017:03:41:55 /3d/data-collection.html
157.55.39.149 US, United States 30/Mar/2017:03:41:47 /robots.txt
85.25.74.158 DE, Germany 30/Mar/2017:03:41:16 /travel/usa/new-york-mcgees/
158.180.192.10 GB, United Kingdom 30/Mar/2017:03:41:13 /travel/usa/new-york-mcgees/
206.16.134.17 US, United States 30/Mar/2017:03:40:50 /3d/xray/
5.172.255.94 Unknown 30/Mar/2017:03:40:04 /cybersecurity/password.html
184.173.238.177 Unknown 30/Mar/2017:03:39:58 /travel/turkey/
123.126.113.167 CN, China 30/Mar/2017:03:39:52 /travel/china/guangzhou-1.html
193.186.208.234 TR, Turkey 30/Mar/2017:03:39:51 /cybersecurity/verify-digital-signature.html
193.186.208.234 TR, Turkey 30/Mar/2017:03:39:40 /cybersecurity/
66.249.79.41 US, United States 30/Mar/2017:03:39:26 /travel/turkey/nemrut-dagi/
90.187.8.217 DE, Germany 30/Mar/2017:03:38:36 /linux/performance-tuning/ethernet.html
46.218.69.162 Unknown 30/Mar/2017:03:38:17 /technical/samsung-galaxy/linux.html
65.55.212.78 US, United States 30/Mar/2017:03:37:46 /travel/turkey/temple-of-artemis/
66.249.79.45 US, United States 30/Mar/2017:03:37:38 /travel/usa/new-york-fictional-architecture/
69.169.236.83 Unknown 30/Mar/2017:03:37:31 /
104.154.227.134 Unknown 30/Mar/2017:03:36:17 /
90.65.207.214 FR, France 30/Mar/2017:03:36:14 /turkish/turkish-suffixes.html
51.255.65.88 GB, United Kingdom 30/Mar/2017:03:35:38 /linux/linux-kernel.html
99.237.25.119 CA, Canada 30/Mar/2017:03:35:06 /
99.237.25.119 CA, Canada 30/Mar/2017:03:35:06 /radio/probes.html
72.173.51.40 US, United States 30/Mar/2017:03:34:57 /technical/samsung-galaxy/cyanogenmod.html
216.37.14.210 US, United States 30/Mar/2017:03:34:56 /3d/xray/
66.249.79.41 US, United States 30/Mar/2017:03:34:18 /radio/copper-wire/
194.71.67.28 SE, Sweden 30/Mar/2017:03:33:40 /linux/linux-break-in-howto.html
157.55.39.142 US, United States 30/Mar/2017:03:32:51 /fun/brilliant-movie-ideas/no-worse.html
90.65.207.214 FR, France 30/Mar/2017:03:32:17 /turkish/turkish-verbs.pdf
180.76.15.158 Unknown 30/Mar/2017:03:32:08 /travel/trinidad/Index.html
85.93.91.84 DE, Germany 30/Mar/2017:03:31:23 /3d/extrema.html
212.178.127.210 NL, Netherlands 30/Mar/2017:03:29:54 /radio/power-meter.html
157.55.39.58 US, United States 30/Mar/2017:03:29:38 /linux/kodi/
157.55.39.138 US, United States 30/Mar/2017:03:29:25 /travel/belgium/bastogne-ardennes/
66.249.79.46 US, United States 30/Mar/2017:03:29:21 /
66.249.79.49 US, United States 30/Mar/2017:03:29:09 /travel/usa/new-york-revolutionary/catholic-worker.html
216.244.66.244 US, United States 30/Mar/2017:03:29:06 /linux/qemu-unix.html
117.211.28.72 IN, India 30/Mar/2017:03:28:51 /networking/commands.html
216.244.66.244 US, United States 30/Mar/2017:03:28:42 /travel/greece/greek/lessons-001-005.html
193.186.208.234 TR, Turkey 30/Mar/2017:03:28:13 /networking/
66.249.79.45 US, United States 30/Mar/2017:03:28:00 /travel/turkey/halicarnassus/
72.21.217.80 US, United States 30/Mar/2017:03:27:59 /robots.txt
39.52.163.81 Unknown 30/Mar/2017:03:27:03 /
39.52.163.81 Unknown 30/Mar/2017:03:27:03 /radio/probes.html
163.172.65.250 GB, United Kingdom 30/Mar/2017:03:25:42 /travel/usa/new-york-jewish-les/grand-street.html
85.93.91.84 DE, Germany 30/Mar/2017:03:25:28 /travel/usa/baltimore/
163.172.137.200 GB, United Kingdom 30/Mar/2017:03:24:50 /technical/samsung-galaxy/block-calls.html
64.207.107.42 US, United States 30/Mar/2017:03:24:06 /
66.249.79.49 US, United States 30/Mar/2017:03:24:01 /linux/performance-tuning/ethernet.html
194.83.147.173 GB, United Kingdom 30/Mar/2017:03:23:39 /cybersecurity/password.html
125.209.235.171 Unknown 30/Mar/2017:03:23:34 /technical/
109.163.234.9 Unknown 30/Mar/2017:03:23:08 /linux/linux-break-in-howto.html
216.244.66.244 US, United States 30/Mar/2017:03:22:36 /travel/mexico/teotihuacan.html
111.94.23.58 Unknown 30/Mar/2017:03:22:20 /technical/samsung-galaxy/secret-code.html
206.246.93.34 US, United States 30/Mar/2017:03:22:02 /3d/xray/scanning.html
163.172.66.89 GB, United Kingdom 30/Mar/2017:03:21:38 /travel/france/ronin/
157.55.39.58 US, United States 30/Mar/2017:03:21:22 /travel/uk/hadrians-wall/
72.14.199.117 US, United States 30/Mar/2017:03:20:54 /
216.244.66.244 US, United States 30/Mar/2017:03:20:44 /cybersecurity/netusers/Index/ua
187.160.72.114 Unknown 30/Mar/2017:03:20:32 /
187.160.72.114 Unknown 30/Mar/2017:03:20:32 /radio/probes.html
157.55.39.58 US, United States 30/Mar/2017:03:20:16 /travel/egypt/
66.249.79.163 US, United States 30/Mar/2017:03:18:52 /fun/latin.html
93.46.192.20 IT, Italy 30/Mar/2017:03:18:30 /technical/samsung-galaxy/linux.html
93.152.141.25 BG, Bulgaria 30/Mar/2017:03:18:13 /travel/belgium/bastogne-ardennes/houffalize-malmedy-st-hubert.html
93.152.141.25 BG, Bulgaria 30/Mar/2017:03:18:12 /travel/belgium/bastogne-ardennes/

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