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.162.91.86 US, United States 22/May/2017:18:26:58 /cybersecurity/authentication.html
54.162.91.86 US, United States 22/May/2017:18:26:56 /cybersecurity/sysaudit.html
54.162.91.86 US, United States 22/May/2017:18:26:55 /cybersecurity/ssh-attack-study.html
54.162.91.86 US, United States 22/May/2017:18:26:53 /cybersecurity/crypto/diffie-hellman.html
54.162.91.86 US, United States 22/May/2017:18:26:50 /linux/linux-alpha.html
80.110.70.125 AT, Austria 22/May/2017:18:26:49 /linux/openbsd-kernel.html
54.162.91.86 US, United States 22/May/2017:18:26:48 /linux/keyboard-mouse.html
54.162.91.86 US, United States 22/May/2017:18:26:46 /linux/ssh-1-admin.html
54.162.91.86 US, United States 22/May/2017:18:26:44 /travel/uk/hadrians-wall/Index.html
54.162.91.86 US, United States 22/May/2017:18:26:43 /fun/teaching/us-vs-britain-vs-france.html
54.162.91.86 US, United States 22/May/2017:18:26:40 /travel/belgium/namur-dinant-ardennes/Index.html
54.162.91.86 US, United States 22/May/2017:18:26:38 /fun/requests-for-quotes/Index.html
54.162.91.86 US, United States 22/May/2017:18:26:36 /cybersecurity/hoax.html
54.162.91.86 US, United States 22/May/2017:18:26:33 /cybersecurity/netusers/Index/ca
54.162.91.86 US, United States 22/May/2017:18:26:31 /fun/requests-for-quotes/marlow-willard/Index.html
54.162.91.86 US, United States 22/May/2017:18:26:29 /travel/usa/new-york-roosevelts/Index.html
54.162.91.86 US, United States 22/May/2017:18:26:27 /cybersecurity/hostile/trojan-exchanger.html
54.162.91.86 US, United States 22/May/2017:18:26:25 /cybersecurity/availability.html
54.162.91.86 US, United States 22/May/2017:18:26:22 /travel/france/provence-megaliths/Index.html
54.162.91.86 US, United States 22/May/2017:18:26:20 /linux/raspberry-pi/nas.html
54.162.91.86 US, United States 22/May/2017:18:26:18 /travel/uk/the-road-to-the-isles/glen-nevis-fort-william.html
54.162.91.86 US, United States 22/May/2017:18:26:15 /travel/france/budget-hotels/Index.html
54.162.91.86 US, United States 22/May/2017:18:26:14 /fun/brilliant-movie-ideas/unholy-unions.html
54.162.91.86 US, United States 22/May/2017:18:26:11 /cybersecurity/history/uk-wwii.html
54.162.91.86 US, United States 22/May/2017:18:26:10 /travel/usa/us-wash-nss.html
54.162.91.86 US, United States 22/May/2017:18:26:07 /travel/france/boat-trip-canal-lateral-a-la-loire/briare-to-beaulieu-sur-loire.html
54.162.91.86 US, United States 22/May/2017:18:26:05 /cybersecurity/netusers/Index/sr
54.162.91.86 US, United States 22/May/2017:18:26:02 /linux/compiling-opencv-on-openbsd.html
54.162.91.86 US, United States 22/May/2017:18:26:00 /linux/rpm-patch.html
54.162.91.86 US, United States 22/May/2017:18:25:57 /linux/performance-tuning/ethernet.html
54.162.91.86 US, United States 22/May/2017:18:25:55 /travel/italy/amalfi/02-the-sights-in-amalfi-and-atrani.html
54.162.91.86 US, United States 22/May/2017:18:25:53 /cybersecurity/netusers/Index/fr
54.162.91.86 US, United States 22/May/2017:18:25:50 /fun/freudian-seuss.html
54.162.91.86 US, United States 22/May/2017:18:25:47 /cybersecurity/history/uss-chaumont/photos-navsourceorg.html
54.162.91.86 US, United States 22/May/2017:18:25:44 /radio/mwdx.html
54.162.91.86 US, United States 22/May/2017:18:25:40 /travel/france/boat/tying-up-and-weather.html
54.162.91.86 US, United States 22/May/2017:18:25:34 /linux/performance-tuning/hardware.html
54.162.91.86 US, United States 22/May/2017:18:25:33 /robots.txt
89.145.95.78 GB, United Kingdom 22/May/2017:18:24:33 /cybersecurity/
38.93.192.148 US, United States 22/May/2017:18:24:29 /linux/openbsd-kernel.html
217.73.208.156 IT, Italy 22/May/2017:18:24:21 /cybersecurity/hostile/stration.html
181.111.64.251 Unknown 22/May/2017:18:24:13 /
181.111.64.251 Unknown 22/May/2017:18:24:13 /radio/probes.html
52.23.243.253 US, United States 22/May/2017:18:23:58 /linux/flash-on-non-sse2-cpu.html
78.140.198.50 RU, Russian Federation 22/May/2017:18:23:57 /linux/performance-tuning/disks.html
207.241.225.226 US, United States 22/May/2017:18:23:33 /robots.txt
207.241.225.235 US, United States 22/May/2017:18:23:33 /robots.txt
66.249.69.14 US, United States 22/May/2017:18:23:30 /
187.190.153.182 Unknown 22/May/2017:18:23:13 /travel/usa/us-wash-masonic.html
184.89.8.177 Unknown 22/May/2017:18:22:14 /radio/frequencies.html
54.89.98.138 US, United States 22/May/2017:18:22:02 /cybersecurity/
54.89.98.138 US, United States 22/May/2017:18:22:01 /robots.txt
184.145.189.170 Unknown 22/May/2017:18:21:52 /technical/dsl/
93.74.165.121 UA, Ukraine 22/May/2017:18:21:27 /turkish/
189.175.252.131 MX, Mexico 22/May/2017:18:21:21 /technical/dsl/
216.244.66.249 US, United States 22/May/2017:18:21:12 /travel/usa/new-york-st-marks-place/3rd-2nd-north.html
68.180.228.169 US, United States 22/May/2017:18:20:48 /travel/usa/montgomery-alabama/Index.html
66.249.75.62 US, United States 22/May/2017:18:19:00 /
66.249.75.62 US, United States 22/May/2017:18:19:00 /robots.txt
209.126.103.233 US, United States 22/May/2017:18:18:55 /3d/xray/
220.181.108.116 CN, China 22/May/2017:18:18:45 /travel/france/jim-morrison-paris.html
216.240.19.104 US, United States 22/May/2017:18:18:24 /linux/performance-tuning/disks.html
95.241.46.91 Unknown 22/May/2017:18:18:13 /linux/rhel-centos-5-6-7/
69.169.228.133 Unknown 22/May/2017:18:16:31 /cybersecurity/root-password.html
180.76.15.8 Unknown 22/May/2017:18:16:11 /cybersecurity/syslog-tls-cloud.html
69.169.224.169 Unknown 22/May/2017:18:15:52 /networking/
209.126.120.38 US, United States 22/May/2017:18:15:34 /technical/
190.201.102.63 VE, Venezuela 22/May/2017:18:15:12 /
190.201.102.63 VE, Venezuela 22/May/2017:18:15:11 /radio/probes.html
199.116.85.58 US, United States 22/May/2017:18:14:52 /3d/
194.255.34.211 DK, Denmark 22/May/2017:18:14:49 /linux/performance-tuning/tcp.html
69.169.225.83 Unknown 22/May/2017:18:14:48 /linux/raspberry-pi/openvas.html
71.192.224.240 US, United States 22/May/2017:18:14:32 /travel/belgium/bastogne-ardennes/ardennes-forest.html
66.249.69.18 US, United States 22/May/2017:18:14:30 /travel/usa/new-york-mcgees/
107.77.68.35 Unknown 22/May/2017:18:13:52 /technical/dsl/
99.230.43.80 CA, Canada 22/May/2017:18:13:37 /robots.txt
184.4.153.113 Unknown 22/May/2017:18:13:32 /technical/dsl/
40.77.167.130 US, United States 22/May/2017:18:13:17 /fun/fingerbox/
40.77.167.130 US, United States 22/May/2017:18:13:17 /cybersecurity/history/dl3g/Index.html
68.180.228.169 US, United States 22/May/2017:18:13:03 /linux/digital-camera.html
54.236.77.227 US, United States 22/May/2017:18:12:32 /travel/usa/us-wash-masonic.html
54.236.77.227 US, United States 22/May/2017:18:12:32 /robots.txt
108.240.154.93 Unknown 22/May/2017:18:12:26 /
209.202.5.170 CA, Canada 22/May/2017:18:12:12 /technical/dsl/
107.23.247.249 Unknown 22/May/2017:18:12:04 /linux/performance-tuning/disks.html
2.155.3.71 Unknown 22/May/2017:18:10:27 /russian/grammar.html
66.249.69.14 US, United States 22/May/2017:18:10:00 /turkish/
151.80.109.121 IT, Italy 22/May/2017:18:09:43 /site-map.html
124.187.94.69 AU, Australia 22/May/2017:18:09:35 /networking/commands.html
40.77.167.130 US, United States 22/May/2017:18:09:21 /travel/greece/
166.137.90.31 US, United States 22/May/2017:18:09:09 /travel/uk/oxford-lewis-tolkien/
144.76.100.237 DE, Germany 22/May/2017:18:09:07 /cybersecurity/hostile/
217.73.208.156 IT, Italy 22/May/2017:18:09:01 /cybersecurity/netusers/Index/uz
157.55.39.203 US, United States 22/May/2017:18:08:41 /travel/bulgaria/Index.html
66.249.75.58 US, United States 22/May/2017:18:08:32 /travel/france/school-lunch-menus/
216.244.66.249 US, United States 22/May/2017:18:08:16 /cybersecurity/crypto/culture.html
216.244.66.249 US, United States 22/May/2017:18:08:14 /cybersecurity/history/uss-chaumont/photos-other.html
216.244.66.249 US, United States 22/May/2017:18:08:13 /cybersecurity/netusers/Index/to
68.180.228.169 US, United States 22/May/2017:18:08:11 /travel/uk/glastonbury/holy-grail.html
216.244.66.249 US, United States 22/May/2017:18:08:09 /pubs.html
216.244.66.249 US, United States 22/May/2017:18:08:09 /linux/raspberry-pi/ads-b-antenna.html
192.188.48.174 EC, Ecuador 22/May/2017:18:08:06 /linux/rhel-centos-5-6-7/
216.244.66.249 US, United States 22/May/2017:18:08:04 /travel/Index.html
54.166.170.222 US, United States 22/May/2017:18:07:40 /technical/dsl/
69.169.229.223 Unknown 22/May/2017:18:07:28 /technical/
72.21.217.114 US, United States 22/May/2017:18:07:16 /travel/usa/new-york-st-marks-place/
69.169.227.67 Unknown 22/May/2017:18:06:59 /cybersecurity/
144.76.100.237 DE, Germany 22/May/2017:18:06:56 /cybersecurity/Index.html
209.190.185.178 US, United States 22/May/2017:18:06:53 /networking/
203.244.221.2 KR, Korea, Republic of 22/May/2017:18:06:25 /linux/sysfs.html
66.249.88.5 US, United States 22/May/2017:18:05:47 /radio/rf-spectrum.html
66.249.75.62 US, United States 22/May/2017:18:05:30 /travel/usa/new-york-st-marks-place/
46.118.155.24 Unknown 22/May/2017:18:04:16 /cybersecurity/
46.118.155.24 Unknown 22/May/2017:18:04:15 /cybersecurity/
217.73.208.156 IT, Italy 22/May/2017:18:03:08 /travel/turkey/selcuk/Index.html
216.244.66.249 US, United States 22/May/2017:18:03:05 /radio/fort-tuthill.html
176.31.100.167 Unknown 22/May/2017:18:02:58 /technical/convert-youtube-to-xvid.html
113.77.84.205 Unknown 22/May/2017:18:01:09 /
66.249.69.14 US, United States 22/May/2017:18:00:59 /cybersecurity/netusers/data/mx
180.58.67.197 Unknown 22/May/2017:18:00:50 /
180.58.67.197 Unknown 22/May/2017:18:00:49 /radio/probes.html
108.240.154.93 Unknown 22/May/2017:17:59:17 /
216.244.66.249 US, United States 22/May/2017:17:58:41 /travel/belgium/belgian-beers/a-la-becasse.html
216.244.66.249 US, United States 22/May/2017:17:58:37 /cybersecurity/netusers/Index/co
174.204.20.126 US, United States 22/May/2017:17:58:29 /travel/usa/us-wash-masonic.html
69.169.236.107 Unknown 22/May/2017:17:58:28 /cybersecurity/privacy-policy.html
216.244.66.249 US, United States 22/May/2017:17:58:13 /cybersecurity/netusers/ssi/?N=D
222.93.7.229 CN, China 22/May/2017:17:58:03 /networking/commands.html
193.136.26.202 PT, Portugal 22/May/2017:17:57:56 /linux/package-management.html
193.136.26.202 PT, Portugal 22/May/2017:17:57:26 /technical/samsung-galaxy/linux.html
54.159.55.252 US, United States 22/May/2017:17:56:31 /travel/usa/us-wash-masonic.html
66.249.75.56 US, United States 22/May/2017:17:56:30 /
172.115.43.239 Unknown 22/May/2017:17:56:29 /travel/usa/us-wash-masonic.html
180.76.15.146 Unknown 22/May/2017:17:56:21 /cybersecurity/crypto/
198.148.27.13 US, United States 22/May/2017:17:55:54 /
120.17.11.186 AU, Australia 22/May/2017:17:54:47 /technical/dsl/
129.176.151.14 US, United States 22/May/2017:17:54:39 /linux/performance-tuning/disks.html
54.162.112.119 US, United States 22/May/2017:17:53:26 /travel/france/ronin/
72.83.25.28 US, United States 22/May/2017:17:53:16 /travel/france/ronin/
209.126.103.239 US, United States 22/May/2017:17:52:06 /cybersecurity/root-password.html
66.249.69.254 US, United States 22/May/2017:17:52:00 /
54.86.60.143 US, United States 22/May/2017:17:51:44 /networking/terminology.html
54.86.60.143 US, United States 22/May/2017:17:51:44 /robots.txt
54.210.73.168 US, United States 22/May/2017:17:50:57 /travel/belgium/art-nouveau-architecture/
125.255.242.54 AU, Australia 22/May/2017:17:50:55 /travel/belgium/art-nouveau-architecture/
69.169.236.35 Unknown 22/May/2017:17:48:06 /linux/lvm-rescue-boot.html
66.249.69.14 US, United States 22/May/2017:17:47:30 /
66.249.69.14 US, United States 22/May/2017:17:47:00 /cybersecurity/netusers/Index/et
69.169.225.239 Unknown 22/May/2017:17:46:33 /
34.210.231.17 US, United States 22/May/2017:17:45:58 /contact.html
199.116.85.58 US, United States 22/May/2017:17:45:21 /technical/samsung-galaxy/ssh.html
81.141.235.73 GB, United Kingdom 22/May/2017:17:44:29 /travel/uk/scotland-isle-of-iona/
180.76.15.15 Unknown 22/May/2017:17:44:09 /
68.180.228.169 US, United States 22/May/2017:17:43:32 /wshta/2011-09-17/
72.21.217.155 US, United States 22/May/2017:17:43:25 /travel/greece/delphi.html
34.224.3.70 US, United States 22/May/2017:17:43:13 /travel/greece/delphi.html
180.76.15.143 Unknown 22/May/2017:17:43:02 /
66.249.69.254 US, United States 22/May/2017:17:43:00 /travel/greece/delphi.html
95.233.1.190 Unknown 22/May/2017:17:42:39 /travel/uk/bletchley-park/
223.25.50.55 Unknown 22/May/2017:17:41:42 /
223.25.50.55 Unknown 22/May/2017:17:41:41 /radio/probes.html
40.77.167.130 US, United States 22/May/2017:17:41:20 /travel/
54.237.212.125 US, United States 22/May/2017:17:40:55 /networking/netstat-s.html
54.237.212.125 US, United States 22/May/2017:17:40:55 /robots.txt
68.180.228.171 US, United States 22/May/2017:17:40:23 /wshta/2011-09-17/
68.180.228.169 US, United States 22/May/2017:17:40:19 /wshta/
206.16.134.16 US, United States 22/May/2017:17:40:18 /contact.html
157.55.39.174 US, United States 22/May/2017:17:39:32 /travel/usa/new-york-nighthawks/
123.30.175.168 VN, Vietnam 22/May/2017:17:39:32 /travel/japan/nikko.html
50.246.96.85 Unknown 22/May/2017:17:39:30 /linux/sysfs.html
123.30.175.168 VN, Vietnam 22/May/2017:17:39:30 /
123.30.175.170 VN, Vietnam 22/May/2017:17:39:28 /robots.txt
89.145.95.70 GB, United Kingdom 22/May/2017:17:38:55 /networking/terminology.html
66.249.69.14 US, United States 22/May/2017:17:38:30 /technical/samsung-galaxy/secret-code.html
68.180.228.171 US, United States 22/May/2017:17:38:28 /wshta/

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