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.242.83.7 US, United States 27/Sep/2016:14:11:43 /technical/Index.html
92.81.43.202 RO, Romania 27/Sep/2016:14:11:42 /radio/nc2030-qrp-transceiver/
85.109.136.232 TR, Turkey 27/Sep/2016:14:11:36 /turkish/turkish-verbs.pdf
162.221.246.240 Unknown 27/Sep/2016:14:11:28 /linux/sendmail-ssl.html
92.81.43.202 RO, Romania 27/Sep/2016:14:11:22 /radio/hfqrp.html
80.237.119.109 RU, Russian Federation 27/Sep/2016:14:11:10 /
80.237.119.109 RU, Russian Federation 27/Sep/2016:14:11:10 /
80.237.119.109 RU, Russian Federation 27/Sep/2016:14:11:09 /
54.242.83.7 US, United States 27/Sep/2016:14:11:07 /travel/usa/new-york-fictional-architecture/greenwich-village.html
77.234.75.220 HU, Hungary 27/Sep/2016:14:10:26 /technical/samsung-galaxy/linux.html
86.173.176.135 GB, United Kingdom 27/Sep/2016:14:10:19 /
176.40.235.52 Unknown 27/Sep/2016:14:09:46 /turkish/verbs.html
64.134.185.194 US, United States 27/Sep/2016:14:08:39 /linux/openbsd-qemu-windows-howto.html
54.242.83.7 US, United States 27/Sep/2016:14:08:31 /travel/uk/ben-nevis/Index.html
54.242.83.7 US, United States 27/Sep/2016:14:08:30 /robots.txt
68.180.229.163 US, United States 27/Sep/2016:14:08:24 /travel/uk/the-road-to-the-isles/luibeilt-steall.html
81.31.95.254 DK, Denmark 27/Sep/2016:14:08:13 /travel/usa/new-york-mcgees/
66.249.69.131 US, United States 27/Sep/2016:14:08:10 /travel/usa/new-york-mcgees/Index.html
66.249.69.229 US, United States 27/Sep/2016:14:07:56 /travel/egypt/
52.3.105.23 US, United States 27/Sep/2016:14:07:54 /robots.txt
69.63.188.108 US, United States 27/Sep/2016:14:07:12 /travel/belgium/belgian-beers/
54.163.152.30 US, United States 27/Sep/2016:14:06:59 /travel/uk/dover/
64.134.185.194 US, United States 27/Sep/2016:14:06:59 /linux/openbsd-qemu-windows-howto.html
71.120.182.234 US, United States 27/Sep/2016:14:06:45 /technical/html4-or-xhtml-to-html5.html
69.70.157.190 CA, Canada 27/Sep/2016:14:06:37 /technical/samsung-galaxy/linux.html
5.178.99.12 Unknown 27/Sep/2016:14:06:36 /
190.14.56.98 Unknown 27/Sep/2016:14:06:04 /linux/performance-tuning/nfs.html
129.237.78.130 US, United States 27/Sep/2016:14:05:32 /turkish/nouns.html
72.21.217.130 US, United States 27/Sep/2016:14:04:43 /travel/greece/tiryns.html
172.56.11.114 Unknown 27/Sep/2016:14:04:40 /turkish/verbs.html
66.249.69.237 US, United States 27/Sep/2016:14:04:32 /oliver-cromwell/
76.250.30.118 US, United States 27/Sep/2016:14:04:02 /linux/performance-tuning/disks.html
66.249.84.23 US, United States 27/Sep/2016:14:03:56 /technical/dsl/
72.21.217.96 US, United States 27/Sep/2016:14:03:44 /travel/france/seine-river-art-history-monet/haute-isle.html
54.173.179.252 US, United States 27/Sep/2016:14:03:37 /travel/france/seine-river-art-history-monet/haute-isle.html
180.76.15.148 Unknown 27/Sep/2016:14:03:35 /linux/crashdumps.html
82.234.174.206 FR, France 27/Sep/2016:14:03:34 /travel/france/seine-river-art-history-monet/haute-isle.html
66.249.69.237 US, United States 27/Sep/2016:14:03:28 /wshta/
72.21.217.106 US, United States 27/Sep/2016:14:03:16 /travel/italy/napoli/
66.249.69.233 US, United States 27/Sep/2016:14:03:10 /travel/italy/napoli/
75.98.9.249 Unknown 27/Sep/2016:14:03:05 /travel/greece/meteora.html
81.94.192.226 BH, Bahrain 27/Sep/2016:14:02:11 /
72.21.217.70 US, United States 27/Sep/2016:14:02:07 /cybersecurity/cloud-exploit.html
183.83.157.190 Unknown 27/Sep/2016:14:02:02 /cybersecurity/cloud-exploit.html
5.255.250.33 Unknown 27/Sep/2016:14:01:41 /robots.txt
217.69.133.68 DE, Germany 27/Sep/2016:14:01:34 /cybersecurity/hostile/downloader-tibs.html
217.69.133.221 DE, Germany 27/Sep/2016:14:01:15 /brewing/
217.69.133.222 DE, Germany 27/Sep/2016:14:01:06 /cybersecurity/history/uss-chaumont/logs.html
217.69.133.225 DE, Germany 27/Sep/2016:14:00:58 /linux/biblical-unix.html
217.69.133.220 DE, Germany 27/Sep/2016:14:00:49 /travel/greece/greek-mainland.html
90.20.108.104 FR, France 27/Sep/2016:14:00:44 /travel/france/saumur-megaliths/
217.69.133.223 DE, Germany 27/Sep/2016:14:00:42 /cybersecurity/crypto/reading.html
90.20.108.104 FR, France 27/Sep/2016:14:00:34 /travel/france/saumur-megaliths/
217.69.133.226 DE, Germany 27/Sep/2016:14:00:34 /travel/belgium/art-nouveau-architecture/
217.69.133.68 DE, Germany 27/Sep/2016:14:00:25 /linux/linux-kernel.html
217.69.133.221 DE, Germany 27/Sep/2016:14:00:17 /travel/athens-to-paris/veliko-tarnovo-bucharest.html
66.249.69.229 US, United States 27/Sep/2016:14:00:10 /networking/cisco-switch-repair/
217.69.133.225 DE, Germany 27/Sep/2016:14:00:09 /robots.txt
217.69.133.68 DE, Germany 27/Sep/2016:14:00:02 /robots.txt
71.52.74.34 US, United States 27/Sep/2016:14:00:00 /linux/openbsd-qemu-windows-howto.html
64.246.139.148 US, United States 27/Sep/2016:13:59:46 /technical/dsl/
170.167.193.162 US, United States 27/Sep/2016:13:58:49 /linux/raspberry-pi/openvas.html
66.249.69.237 US, United States 27/Sep/2016:13:58:32 /fun/
208.185.32.26 US, United States 27/Sep/2016:13:58:06 /linux/openbsd-qemu-windows-howto.html
188.130.108.43 Unknown 27/Sep/2016:13:57:21 /travel/france/normandy/omaha-beach.html
78.15.109.125 IT, Italy 27/Sep/2016:13:57:13 /linux/raspberry-pi/openvas.html
198.148.27.25 US, United States 27/Sep/2016:13:57:02 /
166.181.80.66 US, United States 27/Sep/2016:13:56:57 /technical/dsl/
74.109.42.80 Unknown 27/Sep/2016:13:56:44 /turkish/
180.76.15.159 Unknown 27/Sep/2016:13:56:41 /cybersecurity/hacker-passwords.html
72.21.217.113 US, United States 27/Sep/2016:13:56:32 /fun/fingerbox/
83.217.134.19 BE, Belgium 27/Sep/2016:13:56:30 /fun/fingerbox/
68.180.229.163 US, United States 27/Sep/2016:13:56:21 /cybersecurity/netusers/Index/kz
192.55.54.45 US, United States 27/Sep/2016:13:56:12 /linux/linux-boot.html
172.1.196.59 Unknown 27/Sep/2016:13:56:02 /travel/usa/us-wash-masonic.html
92.190.78.161 FR, France 27/Sep/2016:13:55:56 /
92.190.78.161 FR, France 27/Sep/2016:13:55:56 /radio/probes.html
172.1.196.59 Unknown 27/Sep/2016:13:55:43 /travel/usa/us-wash-masonic.html
69.24.144.22 US, United States 27/Sep/2016:13:55:27 /linux/raspberry-pi/openvas.html
180.76.15.26 Unknown 27/Sep/2016:13:55:21 /travel/france/seine-river-art-history-monet/rolleboise-lavacourt-vetheuil.html
172.1.196.59 Unknown 27/Sep/2016:13:54:51 /travel/usa/us-wash-masonic.html
24.139.218.197 PR, Puerto Rico 27/Sep/2016:13:54:42 /3d/xray/scanner.html
72.21.217.87 US, United States 27/Sep/2016:13:54:26 /3d/xray/
24.139.218.197 PR, Puerto Rico 27/Sep/2016:13:54:24 /3d/xray/
72.21.217.119 US, United States 27/Sep/2016:13:54:20 /travel/france/pierre-tourneresse/
172.1.196.59 Unknown 27/Sep/2016:13:54:04 /travel/usa/us-wash-masonic.html
72.21.217.131 US, United States 27/Sep/2016:13:54:01 /technical/google-adsense-and-xhtml.html
72.21.217.65 US, United States 27/Sep/2016:13:53:43 /travel/usa/
96.242.84.109 US, United States 27/Sep/2016:13:53:43 /travel/usa/
54.173.25.49 US, United States 27/Sep/2016:13:53:40 /robots.txt
128.135.51.96 US, United States 27/Sep/2016:13:53:17 /russian/grammar.html
174.194.137.221 US, United States 27/Sep/2016:13:52:56 /technical/dsl/
157.55.39.155 US, United States 27/Sep/2016:13:52:30 /wshta/2011-10-08/
52.207.246.104 US, United States 27/Sep/2016:13:52:27 /3d/data-collection.html
66.249.69.237 US, United States 27/Sep/2016:13:52:15 /
89.145.95.42 GB, United Kingdom 27/Sep/2016:13:52:12 /linux/openbsd-kernel.html
85.245.226.225 PT, Portugal 27/Sep/2016:13:51:58 /linux/rhel-centos-5-6-7/
72.21.217.116 US, United States 27/Sep/2016:13:51:08 /fun/fingerbox/
176.92.93.223 Unknown 27/Sep/2016:13:51:06 /travel/greece/ferries.html
72.21.217.153 US, United States 27/Sep/2016:13:50:44 /travel/uk/orkney-west-coast-walk/
72.21.217.116 US, United States 27/Sep/2016:13:50:26 /fun/fingerbox/
174.130.96.162 US, United States 27/Sep/2016:13:50:20 /technical/dsl/
5.255.250.33 Unknown 27/Sep/2016:13:50:18 /cybersecurity/netusers/Index/ci
123.126.113.167 CN, China 27/Sep/2016:13:50:01 /robots.txt
72.21.217.75 US, United States 27/Sep/2016:13:49:59 /robots.txt
64.246.139.148 US, United States 27/Sep/2016:13:49:44 /technical/dsl/
93.115.87.78 RO, Romania 27/Sep/2016:13:49:35 /fun/fingerbox/
76.3.177.118 US, United States 27/Sep/2016:13:49:29 /travel/uk/oxford-lewis-tolkien/
94.215.78.173 NL, Netherlands 27/Sep/2016:13:48:50 /technical/samsung-galaxy/linux.html
72.21.217.130 US, United States 27/Sep/2016:13:48:15 /travel/belgium/bastogne-ardennes/background.html
46.193.173.183 Unknown 27/Sep/2016:13:48:13 /travel/france/normandy/pegasus-bridge.html
73.132.101.19 US, United States 27/Sep/2016:13:48:04 /linux/raspberry-pi/openvas.html
72.21.217.130 US, United States 27/Sep/2016:13:48:04 /travel/uk/orkney-neolithic/ring-of-brodgar.html
66.249.69.128 US, United States 27/Sep/2016:13:47:54 /travel/uk/orkney-neolithic/ring-of-brodgar.html
46.1.50.19 Unknown 27/Sep/2016:13:47:52 /turkish/turkish-verbs.pdf
72.21.217.179 US, United States 27/Sep/2016:13:47:41 /technical/how-to-copy-dvds.html
66.249.69.134 US, United States 27/Sep/2016:13:46:29 /turkish/verbs.html
93.147.207.42 IT, Italy 27/Sep/2016:13:45:41 /radio/probes.html
54.162.238.211 US, United States 27/Sep/2016:13:45:21 /travel/uk/glastonbury/chalice-spring-tor.html
50.194.10.158 Unknown 27/Sep/2016:13:45:09 /cybersecurity/root-password.html
132.203.131.41 CA, Canada 27/Sep/2016:13:44:48 /linux/openbsd-kernel.html
132.203.131.41 CA, Canada 27/Sep/2016:13:44:33 /linux/openbsd-kernel.html
54.162.238.211 US, United States 27/Sep/2016:13:43:25 /travel/usa/us-wash-masonic.html
216.244.66.244 US, United States 27/Sep/2016:13:43:09 /linux/ssh-3-user.html
66.249.93.149 US, United States 27/Sep/2016:13:43:04 /technical/samsung-galaxy/block-calls.html
72.21.217.100 US, United States 27/Sep/2016:13:42:40 /robots.txt
59.185.105.109 IN, India 27/Sep/2016:13:40:18 /linux/sendmail-ssl.html
82.15.251.220 GB, United Kingdom 27/Sep/2016:13:38:52 /
184.99.234.100 Unknown 27/Sep/2016:13:38:39 /linux/rhel-centos-5-6-7/users-groups.html
62.117.10.218 DE, Germany 27/Sep/2016:13:38:32 /travel/uk/scotland-pitlochry/
216.244.66.244 US, United States 27/Sep/2016:13:37:54 /travel/turkey/mountain-trek/
216.244.66.244 US, United States 27/Sep/2016:13:37:52 /travel/trinidad/background.html
66.249.69.131 US, United States 27/Sep/2016:13:37:43 /travel/uk/harwell-glider-base/
87.219.195.137 ES, Spain 27/Sep/2016:13:37:22 /linux/cluster.html
216.244.66.244 US, United States 27/Sep/2016:13:37:16 /linux/openbsd-kernel.html
66.249.69.131 US, United States 27/Sep/2016:13:36:06 /radio/power-meter.html
46.177.144.120 Unknown 27/Sep/2016:13:35:27 /technical/ata-ide-sata-usb-cable-pinouts.html
46.177.144.120 Unknown 27/Sep/2016:13:35:22 /technical/ata-ide-sata-usb-cable-pinouts.html
66.249.69.233 US, United States 27/Sep/2016:13:34:54 /radio/power-meter.html
216.244.66.244 US, United States 27/Sep/2016:13:34:49 /networking/logs-in-color.html
23.250.105.77 Unknown 27/Sep/2016:13:34:36 /linux/apache-https-x509v3.html
64.89.234.161 US, United States 27/Sep/2016:13:34:07 /
181.225.240.230 Unknown 27/Sep/2016:13:33:44 /technical/ata-ide-sata-usb-cable-pinouts.html
54.209.239.172 US, United States 27/Sep/2016:13:33:34 /travel/france/normandy/pegasus-bridge.html
64.236.208.26 US, United States 27/Sep/2016:13:33:22 /linux/performance-tuning/disks.html
35.16.21.34 US, United States 27/Sep/2016:13:32:02 /russian/grammar.html
198.148.15.20 US, United States 27/Sep/2016:13:31:55 /travel/belgium/bastogne-ardennes/ardennes-forest.html
106.37.236.159 Unknown 27/Sep/2016:13:31:37 /cybersecurity/hacker-passwords.html
216.244.66.244 US, United States 27/Sep/2016:13:31:32 /cybersecurity/netusers/Index/pe
86.173.176.135 GB, United Kingdom 27/Sep/2016:13:31:07 /
213.233.203.104 NL, Netherlands 27/Sep/2016:13:30:43 /linux/multiboot-windows-openbsd/
66.249.69.134 US, United States 27/Sep/2016:13:30:29 /travel/france/mont-saint-michel-saint-malo/
66.249.69.134 US, United States 27/Sep/2016:13:30:28 /robots.txt
216.249.236.29 US, United States 27/Sep/2016:13:30:20 /linux/linux-break-in-howto.html
1.82.216.134 Unknown 27/Sep/2016:13:29:28 /technical/html-greyscale-test.html
51.255.194.29 GB, United Kingdom 27/Sep/2016:13:28:40 /cybersecurity/software.html
51.255.194.29 GB, United Kingdom 27/Sep/2016:13:28:38 /robots.txt
72.21.217.66 US, United States 27/Sep/2016:13:27:51 /travel/uk/glastonbury/town.html
94.140.33.203 Unknown 27/Sep/2016:13:27:49 /travel/uk/glastonbury/town.html
66.249.83.139 US, United States 27/Sep/2016:13:27:40 /travel/uk/oxford-lewis-tolkien/
58.60.160.11 CN, China 27/Sep/2016:13:27:38 /linux/linux-commands.html
58.60.160.11 CN, China 27/Sep/2016:13:27:37 /linux/getting-started.html
58.60.160.11 CN, China 27/Sep/2016:13:27:37 /cybersecurity/ec2-secure-storage.html
58.60.160.11 CN, China 27/Sep/2016:13:27:37 /linux/linux-blog.html
58.60.160.11 CN, China 27/Sep/2016:13:27:37 /linux/ssh.html
58.60.160.11 CN, China 27/Sep/2016:13:27:37 /linux/kerberos.html
58.60.160.11 CN, China 27/Sep/2016:13:27:37 /linux/linux-break-in-howto.html
58.60.160.11 CN, China 27/Sep/2016:13:27:37 /linux/sendmail-ssl.html
58.60.160.11 CN, China 27/Sep/2016:13:27:36 /linux/system-administration.html
58.60.160.11 CN, China 27/Sep/2016:13:27:33 /cybersecurity/linux-hardening.html
58.60.160.11 CN, China 27/Sep/2016:13:27:33 /linux/qemu-unix.html
58.60.160.11 CN, China 27/Sep/2016:13:27:32 /steampunk/gsm-soviet-telephone.html
58.60.160.11 CN, China 27/Sep/2016:13:27:32 /radio/internet-radio.html
58.60.160.11 CN, China 27/Sep/2016:13:27:32 /cybersecurity/surveillance.html
58.60.160.11 CN, China 27/Sep/2016:13:27:30 /pubs.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 blue, 60.0.0.0/8 through 90.0.0.0/8 are shades of green, the /16 networks 130.0.0.0/16 through about 170.255.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