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.

82.25.213.49 GB, United Kingdom 28/Jun/2017:05:34:02 /linux/performance-tuning/
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:34:01 /travel/uk/ben-nevis/
66.249.69.52 US, United States 28/Jun/2017:05:34:00 /cybersecurity/netusers/data/cy
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:33:50 /networking/terminology.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:33:40 /networking/cisco-switch-repair/
195.25.72.163 FR, France 28/Jun/2017:05:33:30 /linux/migrate-rhel-to-centos.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:33:29 /networking/what-is-ipsec.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:33:19 /networking/class-a-nets.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:33:07 /cybersecurity/netusers/Index/ipk
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:32:56 /turkish/verbs.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:32:45 /networking/nat.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:32:33 /linux/openbsd-qemu-windows-howto.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:32:23 /travel/turkey/mountain-trek/
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:32:12 /networking/netstat-s.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:32:01 /cybersecurity/netusers/Index/
115.111.245.234 IN, India 28/Jun/2017:05:32:00 /linux/performance-tuning/disks.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:31:50 /networking/cisco.html
69.169.228.183 Unknown 28/Jun/2017:05:31:41 /russian/
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:31:38 /technical/google-adsense-and-xhtml.html
66.249.91.53 US, United States 28/Jun/2017:05:31:37 /turkish/verbs.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:31:26 /networking/wan-specs.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:31:15 /networking/vlan.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:31:02 /turkish/
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:30:49 /cybersecurity/netusers/
31.215.255.226 US, United States 28/Jun/2017:05:30:44 /travel/athens-to-paris/athens-thessaloniki.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:30:38 /linux/openbsd-dell.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:30:27 /linux/ssh-2-access-control.html
23.20.53.150 GB, United Kingdom 28/Jun/2017:05:30:26 /robots.txt
31.215.255.226 US, United States 28/Jun/2017:05:30:25 /travel/athens-to-paris/
157.99.161.102 FR, France 28/Jun/2017:05:29:52 /linux/performance-tuning/disks.html
31.215.255.226 US, United States 28/Jun/2017:05:29:40 /travel/greece/trains.html
180.76.15.16 Unknown 28/Jun/2017:05:28:06 /travel/syria/aleppo.html
83.185.93.167 SE, Sweden 28/Jun/2017:05:28:00 /travel/italy/driving.html
54.152.100.125 US, United States 28/Jun/2017:05:27:47 /linux/thunderbird-default-browser.html
125.99.112.234 IN, India 28/Jun/2017:05:27:44 /technical/hdmi.html
131.180.22.213 NL, Netherlands 28/Jun/2017:05:27:44 /linux/thunderbird-default-browser.html
95.128.148.65 Unknown 28/Jun/2017:05:27:19 /linux/performance-tuning/disks.html
34.204.79.238 US, United States 28/Jun/2017:05:27:14 /russian/
34.204.79.238 US, United States 28/Jun/2017:05:27:13 /robots.txt
216.244.66.249 US, United States 28/Jun/2017:05:27:11 /cybersecurity/crypto/culture.html
216.244.66.249 US, United States 28/Jun/2017:05:27:10 /cybersecurity/history/uss-chaumont/photos-other.html
216.244.66.249 US, United States 28/Jun/2017:05:27:08 /linux/raspberry-pi/ads-b-antenna.html
216.244.66.249 US, United States 28/Jun/2017:05:27:07 /pubs.html
216.244.66.249 US, United States 28/Jun/2017:05:27:05 /travel/Index.html
54.167.119.31 US, United States 28/Jun/2017:05:26:46 /cybersecurity/netusers/Index/ni
209.126.103.240 US, United States 28/Jun/2017:05:26:41 /cybersecurity/linux-hardening.html
72.21.217.75 US, United States 28/Jun/2017:05:26:41 /cybersecurity/netusers/Index/ni
66.249.75.30 US, United States 28/Jun/2017:05:26:38 /cybersecurity/netusers/Index/ni
54.175.227.218 US, United States 28/Jun/2017:05:26:23 /linux/vmware-networking.html
54.175.227.218 US, United States 28/Jun/2017:05:26:23 /robots.txt
157.25.63.10 PL, Poland 28/Jun/2017:05:26:19 /linux/performance-tuning/disks.html
34.228.233.177 US, United States 28/Jun/2017:05:26:11 /technical/samsung-galaxy/cyanogenmod.html
34.228.233.177 US, United States 28/Jun/2017:05:26:10 /robots.txt
54.197.212.198 US, United States 28/Jun/2017:05:26:09 /technical/samsung-galaxy/ssh.html
54.197.212.198 US, United States 28/Jun/2017:05:26:09 /robots.txt
188.123.102.69 Unknown 28/Jun/2017:05:25:55 /technical/dsl/
54.91.234.196 US, United States 28/Jun/2017:05:25:47 /linux/bluray.html
54.91.234.196 US, United States 28/Jun/2017:05:25:47 /robots.txt
31.215.255.226 US, United States 28/Jun/2017:05:25:45 /travel/athens-to-paris/
34.229.214.84 US, United States 28/Jun/2017:05:25:44 /travel/gsm-sim-card/
34.229.214.84 US, United States 28/Jun/2017:05:25:43 /robots.txt
184.73.73.49 Unknown 28/Jun/2017:05:25:43 /travel/
184.73.73.49 Unknown 28/Jun/2017:05:25:43 /robots.txt
54.82.217.90 US, United States 28/Jun/2017:05:25:42 /technical/bios.html
66.249.69.52 US, United States 28/Jun/2017:05:25:27 /cybersecurity/netusers/data/la
54.211.173.140 US, United States 28/Jun/2017:05:25:17 /linux/system-administration.html
54.211.173.140 US, United States 28/Jun/2017:05:25:17 /robots.txt
54.82.217.90 US, United States 28/Jun/2017:05:25:12 /linux/compiling-opencv-on-openbsd.html
54.82.217.90 US, United States 28/Jun/2017:05:25:12 /robots.txt
34.229.45.101 US, United States 28/Jun/2017:05:25:10 /linux/raspberry-pi/nas.html
34.229.45.101 US, United States 28/Jun/2017:05:25:10 /robots.txt
52.90.73.41 US, United States 28/Jun/2017:05:24:58 /linux/apache-referer-log-analysis.html
52.90.73.41 US, United States 28/Jun/2017:05:24:58 /robots.txt
69.169.226.223 Unknown 28/Jun/2017:05:24:57 /
54.242.3.161 US, United States 28/Jun/2017:05:24:47 /linux/openbsd-wireless-wpa2.html
54.242.3.161 US, United States 28/Jun/2017:05:24:46 /robots.txt
54.173.60.118 US, United States 28/Jun/2017:05:24:26 /linux/linux-alpha.html
54.173.60.118 US, United States 28/Jun/2017:05:24:26 /robots.txt
54.237.221.17 US, United States 28/Jun/2017:05:24:22 /linux/package-management.html
54.237.221.17 US, United States 28/Jun/2017:05:24:22 /robots.txt
54.211.40.211 US, United States 28/Jun/2017:05:24:05 /linux/qemu-unix.html
54.211.40.211 US, United States 28/Jun/2017:05:24:05 /robots.txt
52.201.201.153 US, United States 28/Jun/2017:05:23:47 /linux/samba-active-directory/
52.201.201.153 US, United States 28/Jun/2017:05:23:45 /robots.txt
34.229.209.154 US, United States 28/Jun/2017:05:22:43 /cybersecurity/linux-hardening.html
34.229.209.154 US, United States 28/Jun/2017:05:22:42 /robots.txt
195.140.123.22 DE, Germany 28/Jun/2017:05:22:25 /networking/cisco.html
31.33.251.163 US, United States 28/Jun/2017:05:20:10 /linux/openbsd-qemu-windows-howto.html
213.209.215.124 IT, Italy 28/Jun/2017:05:20:05 /linux/sendmail-ssl.html
68.180.228.169 US, United States 28/Jun/2017:05:19:42 /travel/turkey/aphrodisias/
216.244.66.249 US, United States 28/Jun/2017:05:19:31 /radio/fort-tuthill.html
87.242.74.135 RU, Russian Federation 28/Jun/2017:05:19:17 /travel/athens-to-paris/
66.249.91.55 US, United States 28/Jun/2017:05:19:11 /linux/performance-tuning/
54.173.77.223 US, United States 28/Jun/2017:05:19:11 /linux/performance-tuning/
113.35.111.66 Unknown 28/Jun/2017:05:19:09 /linux/performance-tuning/
180.76.15.160 Unknown 28/Jun/2017:05:19:05 /travel/uk/ben-nevis/
54.173.77.223 US, United States 28/Jun/2017:05:18:46 /linux/file-system.html
66.249.91.53 US, United States 28/Jun/2017:05:18:45 /linux/file-system.html
113.35.111.66 Unknown 28/Jun/2017:05:18:43 /linux/file-system.html
77.126.98.246 IL, Israel 28/Jun/2017:05:18:43 /cybersecurity/authentication.html
66.242.15.103 US, United States 28/Jun/2017:05:18:31 /cybersecurity/comptia/
66.242.15.103 US, United States 28/Jun/2017:05:18:31 /robots.txt
87.242.74.135 RU, Russian Federation 28/Jun/2017:05:18:30 /travel/bulgaria/veliko-tarnovo/
70.181.6.104 US, United States 28/Jun/2017:05:18:28 /cybersecurity/comptia/
66.249.69.85 US, United States 28/Jun/2017:05:18:16 /travel/usa/new-york-internet/
207.46.13.77 US, United States 28/Jun/2017:05:17:37 /fun/foxnews-search2.html
194.16.175.140 SE, Sweden 28/Jun/2017:05:17:36 /linux/rhel-centos-5-6-7/
72.21.217.136 US, United States 28/Jun/2017:05:17:19 /robots.txt
66.249.69.85 US, United States 28/Jun/2017:05:16:39 /3d/clsi/
216.244.66.249 US, United States 28/Jun/2017:05:16:08 /travel/belgium/belgian-beers/a-la-becasse.html
141.8.143.186 DE, Germany 28/Jun/2017:05:15:49 /turkish/language-reform.html
216.244.66.249 US, United States 28/Jun/2017:05:15:23 /cybersecurity/netusers/ssi/?N=D
69.169.231.109 Unknown 28/Jun/2017:05:15:16 /technical/
68.180.228.171 US, United States 28/Jun/2017:05:15:10 /radio/hf-short-dipoles.html
216.244.66.249 US, United States 28/Jun/2017:05:15:09 /cybersecurity/netusers/Index/to
87.242.74.135 RU, Russian Federation 28/Jun/2017:05:15:06 /sitemap.txt
216.244.66.249 US, United States 28/Jun/2017:05:15:01 /cybersecurity/netusers/Index/co
95.123.151.183 Unknown 28/Jun/2017:05:14:54 /linux/openbsd-qemu-windows-howto.html
54.173.100.78 US, United States 28/Jun/2017:05:14:35 /linux/multiboot-windows-openbsd/Index.html
72.21.217.170 US, United States 28/Jun/2017:05:14:24 /linux/multiboot-windows-openbsd/Index.html
89.145.95.79 GB, United Kingdom 28/Jun/2017:05:14:15 /linux/kodi/
157.55.39.79 US, United States 28/Jun/2017:05:14:15 /travel/france/boat-trip-canal-lateral-a-la-loire/briare.html
87.248.52.50 IT, Italy 28/Jun/2017:05:14:12 /linux/performance-tuning/nfs.html
54.173.100.78 US, United States 28/Jun/2017:05:13:38 /travel/turkey/temple-of-artemis/
197.157.255.220 Unknown 28/Jun/2017:05:13:38 /
66.249.69.87 US, United States 28/Jun/2017:05:13:37 /travel/uk/glastonbury/
197.157.255.220 Unknown 28/Jun/2017:05:13:37 /radio/probes.html
72.21.217.118 US, United States 28/Jun/2017:05:13:29 /travel/turkey/temple-of-artemis/
77.75.76.162 CZ, Czech Republic 28/Jun/2017:05:12:42 /robots.txt
138.246.253.30 DE, Germany 28/Jun/2017:05:12:09 /
138.246.253.30 DE, Germany 28/Jun/2017:05:12:09 /
130.43.114.157 US, United States 28/Jun/2017:05:11:59 /
130.43.114.157 US, United States 28/Jun/2017:05:11:58 /radio/probes.html
31.184.197.41 US, United States 28/Jun/2017:05:11:27 /travel/turkey/temple-of-artemis/
209.126.120.34 US, United States 28/Jun/2017:05:11:27 /linux/kodi/
95.13.5.73 Unknown 28/Jun/2017:05:11:26 /travel/greece/greek-islands.html
209.126.120.38 US, United States 28/Jun/2017:05:10:52 /cybersecurity/linux-hardening.html
209.126.120.16 US, United States 28/Jun/2017:05:10:47 /linux/linux-commands.html
141.168.231.122 AU, Australia 28/Jun/2017:05:10:30 /cybersecurity/password-breaking.html
66.249.91.53 US, United States 28/Jun/2017:05:10:24 /turkish/verbs.html
141.168.231.122 AU, Australia 28/Jun/2017:05:10:18 /cybersecurity/password.html
180.76.15.17 Unknown 28/Jun/2017:05:10:03 /travel/france/
66.249.75.30 US, United States 28/Jun/2017:05:09:54 /travel/uk/glastonbury/town.html
54.236.1.15 US, United States 28/Jun/2017:05:09:29 /travel/uk/skara-brae/
5.62.43.27 Unknown 28/Jun/2017:05:08:27 /cybersecurity/public-key.html
5.62.43.27 Unknown 28/Jun/2017:05:08:26 /turkish/
5.62.43.27 Unknown 28/Jun/2017:05:08:25 /travel/
5.62.43.27 Unknown 28/Jun/2017:05:08:25 /technical/
5.62.43.27 Unknown 28/Jun/2017:05:08:23 /russian/
5.62.43.27 Unknown 28/Jun/2017:05:08:23 /radio/
195.60.68.157 SE, Sweden 28/Jun/2017:05:08:22 /linux/linux-boot.html
51.255.65.67 GB, United Kingdom 28/Jun/2017:05:08:22 /cybersecurity/history/uss-chaumont/photos-lettersetc.html
5.62.43.27 Unknown 28/Jun/2017:05:08:21 /networking/
5.62.43.27 Unknown 28/Jun/2017:05:08:20 /linux/
5.62.43.27 Unknown 28/Jun/2017:05:08:17 /fun/
5.62.43.27 Unknown 28/Jun/2017:05:08:17 /cybersecurity/root-password.html
5.62.43.27 Unknown 28/Jun/2017:05:08:16 /cybersecurity/privacy-policy.html
5.62.43.27 Unknown 28/Jun/2017:05:08:15 /cybersecurity/
5.62.43.27 Unknown 28/Jun/2017:05:08:14 /3d/
5.62.43.27 Unknown 28/Jun/2017:05:08:13 /pubs.html
5.62.43.27 Unknown 28/Jun/2017:05:08:11 /site-map.html
5.62.43.27 Unknown 28/Jun/2017:05:08:10 /contact.html
5.62.43.27 Unknown 28/Jun/2017:05:08:10 /
66.249.69.85 US, United States 28/Jun/2017:05:08:05 /fun/rick-mount-purdue.html
113.35.111.66 Unknown 28/Jun/2017:05:07:24 /linux/performance-tuning/file-systems.html
192.155.198.102 Unknown 28/Jun/2017:05:06:23 /3d/histogram/
35.158.222.72 US, United States 28/Jun/2017:05:05:56 /technical/samsung-galaxy/screenshot.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 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