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.197.142.219 US, United States 08/Dec/2016:10:02:15 /cybersecurity/physical.html
54.197.142.219 US, United States 08/Dec/2016:10:02:10 /travel/usa/new-york-mudd-club/Index.html
72.21.217.156 US, United States 08/Dec/2016:10:02:01 /steampunk/
88.150.230.186 RS, Serbia 08/Dec/2016:10:01:59 /steampunk/
54.197.142.219 US, United States 08/Dec/2016:10:01:55 /cybersecurity/netusers/Index/bq
54.197.142.219 US, United States 08/Dec/2016:10:01:51 /travel/france/boat-trip-canal-lateral-a-la-loire/la-chapelle-montlinard-to-cours-les-barres.html
54.197.142.219 US, United States 08/Dec/2016:10:01:48 /brewing/mead-background.html
54.197.142.219 US, United States 08/Dec/2016:10:01:44 /networking/what-is-ipsec.html
198.148.27.6 US, United States 08/Dec/2016:10:01:42 /
54.197.142.219 US, United States 08/Dec/2016:10:01:41 /travel/uk/london-underground/Index.html
24.180.201.166 US, United States 08/Dec/2016:10:01:40 /radio/tek2445a.html
54.197.142.219 US, United States 08/Dec/2016:10:01:36 /fun/brilliant-movie-ideas/unclassifiable.html
54.197.142.219 US, United States 08/Dec/2016:10:01:31 /3d/normals.html
24.252.217.246 US, United States 08/Dec/2016:10:01:29 /fun/fingerbox/
54.197.142.219 US, United States 08/Dec/2016:10:01:28 /travel/greece/orthodox-shrines.html
54.197.142.219 US, United States 08/Dec/2016:10:01:24 /linux/getting-started.html
54.197.142.219 US, United States 08/Dec/2016:10:01:21 /cybersecurity/netusers/Index/ur
54.197.142.219 US, United States 08/Dec/2016:10:01:18 /travel/russia/getting-there.html
54.197.142.219 US, United States 08/Dec/2016:10:01:15 /cybersecurity/netusers/Index/int
54.197.142.219 US, United States 08/Dec/2016:10:01:11 /travel/usa/new-york-fictional-architecture/upper-west-side.html
54.197.142.219 US, United States 08/Dec/2016:10:01:07 /fun/brilliant-movie-ideas/no-worse.html
54.197.142.219 US, United States 08/Dec/2016:10:00:58 /travel/france/lavomat/Index.html
54.197.142.219 US, United States 08/Dec/2016:10:00:54 /radio/frequencies.html
54.197.142.219 US, United States 08/Dec/2016:10:00:50 /cybersecurity/hostile/gibe-f-worm.html
54.197.142.219 US, United States 08/Dec/2016:10:00:46 /cybersecurity/qr-nfc.html
54.197.142.219 US, United States 08/Dec/2016:10:00:42 /cybersecurity/netusers/Index/aj
54.197.142.219 US, United States 08/Dec/2016:10:00:38 /cybersecurity/hostile/stration.html
54.197.142.219 US, United States 08/Dec/2016:10:00:34 /fun/teaching/turn-the-page.html
54.197.142.219 US, United States 08/Dec/2016:10:00:30 /steampunk/gsm-soviet-telephone.html
54.197.142.219 US, United States 08/Dec/2016:10:00:26 /travel/france/electricity/Index.html
54.197.142.219 US, United States 08/Dec/2016:10:00:22 /travel/estonia/Index.html
54.197.142.219 US, United States 08/Dec/2016:10:00:18 /travel/uk/the-road-to-the-isles/steall-glen-nevis.html
54.197.142.219 US, United States 08/Dec/2016:10:00:10 /travel/france/boat/boat-crew-and-rental-company.html
54.197.142.219 US, United States 08/Dec/2016:10:00:10 /robots.txt
76.179.18.77 US, United States 08/Dec/2016:10:00:03 /travel/usa/new-york-internet/
173.252.124.72 Unknown 08/Dec/2016:09:59:45 /cybersecurity/history/nsa-museum.html
192.75.88.130 CA, Canada 08/Dec/2016:09:59:41 /linux/vim-word-count.html
54.208.241.203 US, United States 08/Dec/2016:09:59:36 /travel/latvia/
67.23.242.82 US, United States 08/Dec/2016:09:59:24 /travel/
209.190.95.42 US, United States 08/Dec/2016:09:59:20 /linux/performance-tuning/disks.html
209.51.197.122 US, United States 08/Dec/2016:09:59:06 /cybersecurity/os-specific.html
209.51.197.122 US, United States 08/Dec/2016:09:59:06 /linux/performance-tuning/nfs.html
209.190.95.42 US, United States 08/Dec/2016:09:58:35 /linux/ipv6-comcast-surfboard.html
209.51.197.122 US, United States 08/Dec/2016:09:58:35 /linux/system-administration.html
209.190.95.42 US, United States 08/Dec/2016:09:58:35 /linux/linux-kernel.html
54.234.193.38 US, United States 08/Dec/2016:09:58:17 /site-map.html
54.158.170.180 US, United States 08/Dec/2016:09:58:11 /site-map.html
94.196.218.249 Unknown 08/Dec/2016:09:58:07 /
192.30.80.18 US, United States 08/Dec/2016:09:58:02 /site-map.html
94.196.218.249 Unknown 08/Dec/2016:09:58:02 /radio/probes.html
64.20.243.132 US, United States 08/Dec/2016:09:57:48 /travel/france/saumur-megaliths/
64.20.243.132 US, United States 08/Dec/2016:09:57:47 /robots.txt
113.210.197.142 Unknown 08/Dec/2016:09:57:40 /technical/samsung-galaxy/secret-code.html
157.55.39.137 US, United States 08/Dec/2016:09:57:36 /wshta/2016-10-15/
72.21.217.129 US, United States 08/Dec/2016:09:57:11 /networking/commands.html
174.218.136.83 US, United States 08/Dec/2016:09:57:06 /networking/commands.html
50.134.137.236 Unknown 08/Dec/2016:09:56:57 /turkish/turkish-suffixes.html
50.134.137.236 Unknown 08/Dec/2016:09:56:51 /turkish/verbs.html
52.201.235.28 US, United States 08/Dec/2016:09:56:20 /travel/athens-to-paris/thessaloniki-sofia.html
46.177.111.92 Unknown 08/Dec/2016:09:56:17 /travel/athens-to-paris/thessaloniki-sofia.html
54.173.25.85 US, United States 08/Dec/2016:09:56:17 /travel/belgium/bastogne-ardennes/ardennes-forest.html
2.120.71.144 Unknown 08/Dec/2016:09:56:13 /travel/belgium/bastogne-ardennes/ardennes-forest.html
173.162.153.25 Unknown 08/Dec/2016:09:56:09 /technical/dsl/
68.172.219.168 US, United States 08/Dec/2016:09:55:54 /
72.21.217.143 US, United States 08/Dec/2016:09:55:50 /steampunk/power-and-light.html
54.172.177.98 US, United States 08/Dec/2016:09:55:49 /steampunk/power-and-light.html
72.21.217.143 US, United States 08/Dec/2016:09:55:48 /steampunk/power-and-light.html
209.58.135.66 US, United States 08/Dec/2016:09:55:48 /steampunk/power-and-light.html
54.234.193.141 US, United States 08/Dec/2016:09:55:47 /steampunk/power-and-light.html
72.21.217.105 US, United States 08/Dec/2016:09:55:47 /steampunk/power-and-light.html
173.162.153.25 Unknown 08/Dec/2016:09:55:43 /steampunk/power-and-light.html
206.16.134.24 US, United States 08/Dec/2016:09:55:32 /radio/
77.195.37.98 FR, France 08/Dec/2016:09:55:01 /
77.195.37.98 FR, France 08/Dec/2016:09:55:00 /radio/probes.html
173.162.153.25 Unknown 08/Dec/2016:09:54:55 /technical/dsl/
88.156.69.219 PL, Poland 08/Dec/2016:09:54:00 /technical/samsung-galaxy/linux.html
149.71.254.6 US, United States 08/Dec/2016:09:53:59 /technical/
137.89.176.15 US, United States 08/Dec/2016:09:53:49 /travel/belgium/bastogne-ardennes/
52.90.131.34 US, United States 08/Dec/2016:09:53:11 /linux/performance-tuning/ethernet.html
108.171.133.172 Unknown 08/Dec/2016:09:53:08 /linux/performance-tuning/ethernet.html
95.148.63.46 Unknown 08/Dec/2016:09:52:50 /technical/samsung-galaxy/linux.html
98.109.193.175 US, United States 08/Dec/2016:09:52:37 /technical/convert-youtube-to-xvid.html
208.111.126.36 Unknown 08/Dec/2016:09:52:00 /technical/dsl/
54.235.54.89 US, United States 08/Dec/2016:09:51:36 /technical/samsung-galaxy/insufficient-storage.html
128.182.160.67 US, United States 08/Dec/2016:09:51:34 /linux/linux-kernel.html
172.56.15.107 Unknown 08/Dec/2016:09:51:03 /technical/dsl/
72.21.217.154 US, United States 08/Dec/2016:09:50:58 /technical/
72.21.217.69 US, United States 08/Dec/2016:09:50:57 /technical/
207.200.187.10 US, United States 08/Dec/2016:09:50:55 /technical/
68.180.229.43 US, United States 08/Dec/2016:09:50:51 /cybersecurity/crypto/
180.76.15.33 Unknown 08/Dec/2016:09:50:40 /cybersecurity/scams-spam-phishing.html
128.182.160.240 US, United States 08/Dec/2016:09:50:11 /linux/linux-kernel.html
68.180.229.43 US, United States 08/Dec/2016:09:49:52 /linux/rtcrack-patch/Public.cpp
163.172.65.252 GB, United Kingdom 08/Dec/2016:09:49:39 /networking/netstat-s.html
66.249.93.83 US, United States 08/Dec/2016:09:49:26 /radio/tek2445a.html
217.145.199.68 SK, Slovakia 08/Dec/2016:09:49:04 /linux/windows-path.html
74.115.58.123 Unknown 08/Dec/2016:09:47:57 /radio/nc2030-qrp-transceiver/
85.93.91.84 DE, Germany 08/Dec/2016:09:47:54 /travel/bulgaria/sofia/
62.210.111.31 FR, France 08/Dec/2016:09:47:15 /
185.121.209.70 Unknown 08/Dec/2016:09:46:57 /technical/samsung-galaxy/linux.html
5.255.250.33 Unknown 08/Dec/2016:09:46:42 /linux/performance-tuning/file-systems.html
37.228.229.99 Unknown 08/Dec/2016:09:46:24 /
163.244.62.183 US, United States 08/Dec/2016:09:46:21 /linux/performance-tuning/disks.html
68.180.229.43 US, United States 08/Dec/2016:09:46:08 /cybersecurity/hostile/trojan-agent.html
54.254.250.150 US, United States 08/Dec/2016:09:45:22 /
38.130.180.9 US, United States 08/Dec/2016:09:45:21 /networking/
185.89.85.24 Unknown 08/Dec/2016:09:44:51 /turkish/verbs.html
157.55.39.137 US, United States 08/Dec/2016:09:44:39 /networking/cisco.html
5.255.250.33 Unknown 08/Dec/2016:09:44:34 /travel/usa/new-york-internet/
54.91.13.188 US, United States 08/Dec/2016:09:44:32 /linux/linux-boot.html
59.89.92.57 IN, India 08/Dec/2016:09:44:25 /linux/linux-boot.html
137.89.176.15 US, United States 08/Dec/2016:09:41:54 /travel/belgium/bastogne-ardennes/
72.239.1.234 US, United States 08/Dec/2016:09:41:51 /travel/usa/new-york-lga-arrival/
178.42.151.115 Unknown 08/Dec/2016:09:41:44 /linux/performance-tuning/tcp.html
137.89.176.15 US, United States 08/Dec/2016:09:41:42 /travel/belgium/bastogne-ardennes/
5.255.250.33 Unknown 08/Dec/2016:09:41:29 /russian/grammar.html
190.153.5.191 VE, Venezuela 08/Dec/2016:09:41:19 /technical/ata-ide-sata-usb-cable-pinouts.html
5.255.250.33 Unknown 08/Dec/2016:09:41:18 /linux/rhel-centos-5-6-7/booting.html
217.145.199.68 SK, Slovakia 08/Dec/2016:09:40:57 /linux/windows-path.html
157.55.39.137 US, United States 08/Dec/2016:09:40:21 /cybersecurity/netusers/Index.php
163.172.65.62 GB, United Kingdom 08/Dec/2016:09:40:04 /text/reports/4sshar.4.txt
43.250.80.75 JP, Japan 08/Dec/2016:09:40:01 /
43.250.80.75 JP, Japan 08/Dec/2016:09:40:01 /radio/probes.html
209.190.185.178 US, United States 08/Dec/2016:09:39:59 /radio/
5.255.250.33 Unknown 08/Dec/2016:09:39:57 /travel/usa/new-york-black-chamber/
82.247.113.53 FR, France 08/Dec/2016:09:39:53 /travel/turkey/trains/
151.213.179.54 US, United States 08/Dec/2016:09:39:48 /radio/probes.html
54.165.29.138 US, United States 08/Dec/2016:09:39:45 /radio/power-meter.html
64.12.116.133 US, United States 08/Dec/2016:09:39:41 /radio/power-meter.html
163.172.65.13 GB, United Kingdom 08/Dec/2016:09:38:55 /cybersecurity/netusers/data/css/?S=A
66.249.69.2 US, United States 08/Dec/2016:09:38:06 /linux/linux-boot.html
69.80.20.221 Unknown 08/Dec/2016:09:37:50 /technical/convert-youtube-to-xvid.html
71.191.202.55 US, United States 08/Dec/2016:09:37:49 /russian/grammar.html
151.213.179.54 US, United States 08/Dec/2016:09:37:48 /radio/probes.html
63.82.135.13 US, United States 08/Dec/2016:09:37:46 /technical/dsl/
71.191.202.55 US, United States 08/Dec/2016:09:37:38 /russian/grammar.html
54.208.251.49 US, United States 08/Dec/2016:09:36:59 /russian/grammar.html
172.56.3.176 Unknown 08/Dec/2016:09:36:57 /russian/grammar.html
54.211.197.167 US, United States 08/Dec/2016:09:36:09 /russian/
172.56.3.176 Unknown 08/Dec/2016:09:36:06 /russian/
197.224.93.168 Unknown 08/Dec/2016:09:35:59 /
197.224.93.168 Unknown 08/Dec/2016:09:35:58 /radio/probes.html
172.56.3.176 Unknown 08/Dec/2016:09:35:51 /russian/grammar.html
123.207.95.146 CN, China 08/Dec/2016:09:35:09 /
151.67.22.124 IT, Italy 08/Dec/2016:09:35:03 /linux/flash-on-non-sse2-cpu.html
98.191.55.39 US, United States 08/Dec/2016:09:34:45 /travel/italy/driving.html
71.191.202.55 US, United States 08/Dec/2016:09:34:35 /russian/grammar.html
196.28.57.7 PR, Puerto Rico 08/Dec/2016:09:34:18 /networking/commands.html
52.3.127.144 US, United States 08/Dec/2016:09:33:56 /robots.txt
193.95.84.228 TN, Tunisia 08/Dec/2016:09:33:27 /linux/sendmail-ssl.html
84.189.16.116 DE, Germany 08/Dec/2016:09:33:23 /radio/tek2445a.html
52.201.235.28 US, United States 08/Dec/2016:09:32:20 /travel/france/normandy/pegasus-bridge.html
2.120.71.144 Unknown 08/Dec/2016:09:32:17 /travel/france/normandy/pegasus-bridge.html
68.180.229.39 US, United States 08/Dec/2016:09:32:12 /steampunk/
188.138.75.239 Unknown 08/Dec/2016:09:31:41 /cybersecurity/ec2-secure-storage.html
72.21.217.156 US, United States 08/Dec/2016:09:31:38 /cybersecurity/ec2-secure-storage.html
54.147.110.94 US, United States 08/Dec/2016:09:31:38 /cybersecurity/ec2-secure-storage.html
72.21.217.178 US, United States 08/Dec/2016:09:31:37 /cybersecurity/ec2-secure-storage.html
151.237.234.244 Unknown 08/Dec/2016:09:31:35 /cybersecurity/ec2-secure-storage.html
180.76.15.28 Unknown 08/Dec/2016:09:31:08 /technical/
66.249.75.186 US, United States 08/Dec/2016:09:30:53 /
54.234.193.38 US, United States 08/Dec/2016:09:30:47 /cybersecurity/linux-hardening.html
54.174.74.82 US, United States 08/Dec/2016:09:30:42 /cybersecurity/linux-hardening.html
15.211.201.81 US, United States 08/Dec/2016:09:30:36 /cybersecurity/linux-hardening.html
15.211.201.81 US, United States 08/Dec/2016:09:30:20 /linux/raspberry-pi/nas.html
68.180.229.43 US, United States 08/Dec/2016:09:30:18 /steampunk/
207.46.13.100 US, United States 08/Dec/2016:09:30:15 /cybersecurity/netusers/Index.php
54.159.29.239 US, United States 08/Dec/2016:09:30:14 /linux/raspberry-pi/networking.html
15.211.201.81 US, United States 08/Dec/2016:09:30:11 /linux/raspberry-pi/networking.html
15.211.201.81 US, United States 08/Dec/2016:09:30:07 /linux/raspberry-pi/openvas.html
66.249.69.6 US, United States 08/Dec/2016:09:29:49 /travel/usa/new-york-mcgees/
54.234.193.141 US, United States 08/Dec/2016:09:29:47 /linux/raspberry-pi/sdr-ads-b-flight-tracking.html
5.255.250.14 Unknown 08/Dec/2016:09:29:41 /linux/raspberry-pi/sdr-ads-b-flight-tracking.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