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.

1.128.96.254 Unknown 29/Apr/2017:22:07:09 /steampunk/lamp.html
221.217.195.52 CN, China 29/Apr/2017:22:07:06 /radio/frequencies.html
221.217.195.52 CN, China 29/Apr/2017:22:07:04 /radio/frequencies.html
221.217.195.52 CN, China 29/Apr/2017:22:07:03 /radio/frequencies.html
54.159.73.215 US, United States 29/Apr/2017:22:07:01 /networking/switch-programming.html
54.159.73.215 US, United States 29/Apr/2017:22:06:42 /radio/probes.html
54.159.73.215 US, United States 29/Apr/2017:22:06:33 /cybersecurity/monitoring.html
54.159.73.215 US, United States 29/Apr/2017:22:06:23 /linux/linux-boot.html
54.159.73.215 US, United States 29/Apr/2017:22:06:14 /technical/google-adsense-and-xhtml.html
54.159.73.215 US, United States 29/Apr/2017:22:06:04 /turkish/verbs.html
54.159.73.215 US, United States 29/Apr/2017:22:05:54 /cybersecurity/netusers/Index/
54.159.73.215 US, United States 29/Apr/2017:22:05:44 /linux/linux-break-in-howto.html
5.137.164.114 Unknown 29/Apr/2017:22:05:42 /travel/greece/bus-travel.html
54.159.73.215 US, United States 29/Apr/2017:22:05:34 /turkish/
54.159.73.215 US, United States 29/Apr/2017:22:05:23 /travel/uk/ben-nevis/
192.161.190.69 Unknown 29/Apr/2017:22:05:23 /cybersecurity/qr-nfc.html
54.159.73.215 US, United States 29/Apr/2017:22:05:13 /linux/openbsd-qemu-windows-howto.html
157.55.39.226 US, United States 29/Apr/2017:22:05:12 /fun/brilliant-movie-ideas/puns.html
54.159.73.215 US, United States 29/Apr/2017:22:05:03 /cybersecurity/netusers/Index/ipk
69.169.228.221 Unknown 29/Apr/2017:22:04:59 /steampunk/gsm-soviet-telephone.html
66.249.75.4 US, United States 29/Apr/2017:22:04:52 /travel/france/normandy/reenactors.html
54.159.73.215 US, United States 29/Apr/2017:22:04:51 /3d/histogram/
216.244.66.249 US, United States 29/Apr/2017:22:04:50 /cybersecurity/netusers/css/?D=A
67.254.130.191 Unknown 29/Apr/2017:22:04:46 /travel/usa/new-york-mcgees/
54.159.73.215 US, United States 29/Apr/2017:22:04:41 /linux/linux-kernel.html
54.159.73.215 US, United States 29/Apr/2017:22:04:31 /travel/turkey/mountain-trek/
184.66.230.218 Unknown 29/Apr/2017:22:04:19 /linux/rhel-centos-multimedia.html
54.159.73.215 US, United States 29/Apr/2017:22:04:19 /travel/turkey/gallipoli/
54.159.73.215 US, United States 29/Apr/2017:22:04:08 /travel/uk/swingate-chain-home/
221.145.183.167 KR, Korea, Republic of 29/Apr/2017:22:03:57 /
221.145.183.167 KR, Korea, Republic of 29/Apr/2017:22:03:56 /
5.255.250.33 Unknown 29/Apr/2017:22:03:50 /travel/belgium/belgian-beers/a-la-becasse.html
184.151.222.227 Unknown 29/Apr/2017:22:03:49 /
54.159.73.215 US, United States 29/Apr/2017:22:03:47 /cybersecurity/linux-hardening.html
54.159.73.215 US, United States 29/Apr/2017:22:03:36 /cybersecurity/stack-hardening.html
54.159.73.215 US, United States 29/Apr/2017:22:03:26 /radio/tone-control.html
54.159.73.215 US, United States 29/Apr/2017:22:03:14 /radio/power-meter.html
216.244.66.249 US, United States 29/Apr/2017:22:03:08 /travel/usa/san-francisco-dashiell-hammett/
54.159.73.215 US, United States 29/Apr/2017:22:03:04 /radio/hfqrp.html
54.159.73.215 US, United States 29/Apr/2017:22:02:51 /travel/france/normandy/brecourt-manor.html
221.145.183.167 KR, Korea, Republic of 29/Apr/2017:22:02:42 /
221.145.183.167 KR, Korea, Republic of 29/Apr/2017:22:02:41 /
54.159.73.215 US, United States 29/Apr/2017:22:02:38 /russian/latex.html
54.159.73.215 US, United States 29/Apr/2017:22:02:22 /travel/uk/lee-ho-fook/
89.12.17.71 DE, Germany 29/Apr/2017:22:02:05 /linux/performance-tuning/tcp.html
54.159.73.215 US, United States 29/Apr/2017:22:02:02 /travel/turkey/
54.173.68.34 US, United States 29/Apr/2017:22:02:01 /cybersecurity/netusers/Index/sl
72.21.217.82 US, United States 29/Apr/2017:22:02:00 /cybersecurity/netusers/Index/sl
207.41.163.20 US, United States 29/Apr/2017:22:01:55 /
5.255.250.33 Unknown 29/Apr/2017:22:01:47 /travel/egypt/luxor.html
5.255.250.33 Unknown 29/Apr/2017:22:01:45 /travel/usa/new-york-skate-manhattan/
5.255.250.33 Unknown 29/Apr/2017:22:01:43 /linux/linux-alpha.html
5.255.250.33 Unknown 29/Apr/2017:22:01:40 /cybersecurity/linux-hardening.html
5.255.250.33 Unknown 29/Apr/2017:22:01:38 /networking/netstat-a.html
5.255.250.33 Unknown 29/Apr/2017:22:01:36 /travel/athens-to-paris/
71.237.96.224 US, United States 29/Apr/2017:22:01:34 /travel/france/normandy/utah-beach-hike.html
5.255.250.33 Unknown 29/Apr/2017:22:01:33 /travel/greece/bus-travel.html
66.249.75.1 US, United States 29/Apr/2017:22:01:31 /travel/france/
5.255.250.33 Unknown 29/Apr/2017:22:01:31 /steampunk/power-controller.html
5.255.250.33 Unknown 29/Apr/2017:22:01:29 /linux/
54.159.73.215 US, United States 29/Apr/2017:22:01:00 /travel/turkey/halicarnassus/
54.159.73.215 US, United States 29/Apr/2017:22:01:00 /robots.txt
98.7.63.125 US, United States 29/Apr/2017:22:00:34 /travel/usa/new-york-mcgees/
107.77.68.93 Unknown 29/Apr/2017:22:00:15 /cybersecurity/password.html
216.244.66.249 US, United States 29/Apr/2017:21:59:53 /cybersecurity/history/nsa-museum.html
40.77.169.102 US, United States 29/Apr/2017:21:59:27 /travel/usa/new-york-black-chamber/
69.169.224.209 Unknown 29/Apr/2017:21:59:26 /linux/linux-blog.html
157.55.39.226 US, United States 29/Apr/2017:21:58:29 /cybersecurity/hostile/manitowoc-bank-scam.html
96.37.139.98 US, United States 29/Apr/2017:21:57:31 /fun/fingerbox/
157.55.39.65 US, United States 29/Apr/2017:21:57:21 /linux/tux-gospel.html
216.244.66.249 US, United States 29/Apr/2017:21:57:10 /travel/usa/new-york-lga-arrival/
180.76.15.30 Unknown 29/Apr/2017:21:57:08 /cybersecurity/history/Index.html
216.244.66.249 US, United States 29/Apr/2017:21:57:02 /linux/raspberry-pi/sdr-ads-b-flight-tracking.html
69.169.231.43 Unknown 29/Apr/2017:21:56:57 /radio/
173.33.15.51 CA, Canada 29/Apr/2017:21:56:50 /radio/probes.html
104.154.58.95 Unknown 29/Apr/2017:21:56:00 /robots.txt
125.209.235.171 Unknown 29/Apr/2017:21:55:30 /travel/athens-to-paris/
52.2.10.94 US, United States 29/Apr/2017:21:55:13 /robots.txt
181.188.125.143 Unknown 29/Apr/2017:21:55:06 /travel/trinidad/port-of-spain.html
181.188.125.143 Unknown 29/Apr/2017:21:54:50 /travel/trinidad/background.html
157.55.39.171 US, United States 29/Apr/2017:21:54:13 /linux/apache-mod_gzip-openbsd.html
54.175.126.210 US, United States 29/Apr/2017:21:52:12 /travel/france/loire-valley/
72.21.217.114 US, United States 29/Apr/2017:21:52:11 /travel/france/loire-valley/
66.249.75.1 US, United States 29/Apr/2017:21:52:00 /travel/france/loire-valley/
69.169.230.93 Unknown 29/Apr/2017:21:51:59 /cybersecurity/surveillance.html
37.187.249.76 Unknown 29/Apr/2017:21:51:40 /
54.91.17.109 US, United States 29/Apr/2017:21:51:33 /linux/performance-tuning/disks.html
208.15.90.2 US, United States 29/Apr/2017:21:51:32 /linux/performance-tuning/disks.html
66.249.69.229 US, United States 29/Apr/2017:21:51:30 /cybersecurity/crypto/hash-search.html
209.126.103.238 US, United States 29/Apr/2017:21:50:59 /technical/hp-printer-ready-message.html
202.180.111.39 NZ, New Zealand 29/Apr/2017:21:49:37 /travel/usa/new-york-lga-arrival/
207.46.13.147 US, United States 29/Apr/2017:21:49:19 /linux/sendmail-ssl.html
54.236.1.11 US, United States 29/Apr/2017:21:49:16 /travel/usa/philadelphia/
54.236.1.13 US, United States 29/Apr/2017:21:49:00 /travel/uk/scotland-isle-of-iona/iona.html
125.209.235.179 Unknown 29/Apr/2017:21:48:19 /turkish/nouns.html
70.198.138.62 US, United States 29/Apr/2017:21:48:18 /technical/dsl/
65.55.218.33 US, United States 29/Apr/2017:21:47:59 /radio/rhombic-antennas.html
73.220.36.54 US, United States 29/Apr/2017:21:46:21 /fun/fingerbox/
172.58.78.179 Unknown 29/Apr/2017:21:46:15 /technical/samsung-galaxy/ssh.html
66.249.69.237 US, United States 29/Apr/2017:21:45:09 /cybersecurity/intrusion-analysis/
209.51.197.34 US, United States 29/Apr/2017:21:45:03 /networking/terminology.html
209.51.202.186 US, United States 29/Apr/2017:21:45:03 /radio/
209.51.205.2 US, United States 29/Apr/2017:21:45:03 /steampunk/
209.51.197.34 US, United States 29/Apr/2017:21:45:03 /radio/fort-tuthill.html
209.190.95.34 US, United States 29/Apr/2017:21:45:03 /steampunk/lamp.html
209.190.2.178 US, United States 29/Apr/2017:21:45:03 /radio/power-meter.html
209.190.95.42 US, United States 29/Apr/2017:21:45:03 /linux/linux-kernel.html
209.190.95.42 US, United States 29/Apr/2017:21:45:03 /contact.html
52.2.10.94 US, United States 29/Apr/2017:21:45:02 /robots.txt
69.64.15.74 US, United States 29/Apr/2017:21:44:40 /technical/
65.55.211.248 US, United States 29/Apr/2017:21:44:40 /travel/uk/scapa-flow/
180.76.15.33 Unknown 29/Apr/2017:21:43:58 /fun/requests-for-quotes/bahrain/pictures/BAH-approach-visual.pdf
94.23.209.167 FR, France 29/Apr/2017:21:43:15 /technical/convert-youtube-to-xvid.html
37.59.11.93 Unknown 29/Apr/2017:21:42:09 /technical/convert-youtube-to-xvid.html
157.55.39.171 US, United States 29/Apr/2017:21:42:06 /travel/uk/orkney-neolithic/knowe-of-onston.html
157.55.39.171 US, United States 29/Apr/2017:21:41:51 /technical/video-camera-rotate.html
157.55.39.65 US, United States 29/Apr/2017:21:41:30 /networking/
69.169.228.25 Unknown 29/Apr/2017:21:41:21 /
157.55.39.171 US, United States 29/Apr/2017:21:41:20 /cybersecurity/netusers/?M=A
207.46.13.147 US, United States 29/Apr/2017:21:41:10 /travel/usa/new-york-nypd/Index.html
85.93.91.84 DE, Germany 29/Apr/2017:21:40:42 /cybersecurity/ssh-attack-study.html
137.74.207.188 CA, Canada 29/Apr/2017:21:39:51 /networking/cisco-switch-repair/
187.56.169.184 Unknown 29/Apr/2017:21:39:39 /linux/unix-tips.html
157.55.39.171 US, United States 29/Apr/2017:21:39:29 /travel/turkey/olimpos/Index.html
65.55.211.243 US, United States 29/Apr/2017:21:39:23 /travel/france/normandy/omaha-beach.html
54.147.171.208 US, United States 29/Apr/2017:21:39:21 /technical/hdmi.html
108.28.97.128 Unknown 29/Apr/2017:21:39:19 /technical/hdmi.html
66.249.75.1 US, United States 29/Apr/2017:21:39:09 /radio/rhombic-antennas.html
66.249.69.229 US, United States 29/Apr/2017:21:38:54 /cybersecurity/history/
157.55.39.171 US, United States 29/Apr/2017:21:38:14 /cybersecurity/root-password.html
98.212.212.103 US, United States 29/Apr/2017:21:37:47 /technical/ata-ide-sata-usb-cable-pinouts.html
104.181.82.25 Unknown 29/Apr/2017:21:37:38 /radio/probes.html
180.76.15.156 Unknown 29/Apr/2017:21:37:14 /
8.37.225.125 US, United States 29/Apr/2017:21:36:58 /linux/torrent-magnet-links.html
180.76.15.27 Unknown 29/Apr/2017:21:36:19 /
52.2.10.94 US, United States 29/Apr/2017:21:34:44 /robots.txt
69.143.160.38 US, United States 29/Apr/2017:21:34:42 /technical/samsung-galaxy/linux.html
157.55.39.65 US, United States 29/Apr/2017:21:34:17 /technical/samsung-galaxy/insufficient-storage.html
66.102.7.233 US, United States 29/Apr/2017:21:34:12 /travel/usa/new-york-skate-manhattan/
207.46.13.147 US, United States 29/Apr/2017:21:33:48 /travel/usa/new-york-revolutionary/catholic-worker.html
69.169.227.17 Unknown 29/Apr/2017:21:33:40 /technical/hp-printer-ready-message.html
209.126.103.238 US, United States 29/Apr/2017:21:33:25 /networking/
98.212.212.103 US, United States 29/Apr/2017:21:33:18 /technical/ata-ide-sata-usb-cable-pinouts.html
66.249.75.4 US, United States 29/Apr/2017:21:33:11 /travel/japan/
70.95.2.3 US, United States 29/Apr/2017:21:32:55 /linux/missing-gtk-modules.html
51.255.66.99 GB, United Kingdom 29/Apr/2017:21:32:09 /technical/quickdisk-recovery.html
66.249.69.233 US, United States 29/Apr/2017:21:31:33 /cybersecurity/verify-digital-signature.html
207.46.13.147 US, United States 29/Apr/2017:21:31:02 /travel/
180.76.15.5 Unknown 29/Apr/2017:21:30:41 /travel/uk/the-road-to-the-isles/
144.76.100.237 DE, Germany 29/Apr/2017:21:30:25 /cybersecurity/intrusion.html
144.76.100.237 DE, Germany 29/Apr/2017:21:30:21 /cybersecurity/ssl-tls.html
125.209.235.173 Unknown 29/Apr/2017:21:28:23 /turkish/Index.html
125.209.235.175 Unknown 29/Apr/2017:21:28:22 /robots.txt
104.154.58.95 Unknown 29/Apr/2017:21:28:02 /linux/rhel-centos-5-6-7/networking.html
209.150.42.112 US, United States 29/Apr/2017:21:27:46 /travel/usa/new-york-internet/
157.55.39.226 US, United States 29/Apr/2017:21:27:30 /travel/romania/food/Index.html
52.71.155.178 US, United States 29/Apr/2017:21:27:00 /networking/what-is-ipsec.html
24.164.131.185 US, United States 29/Apr/2017:21:26:52 /linux/performance-tuning/disks.html
104.154.58.95 Unknown 29/Apr/2017:21:26:47 /travel/turkey/gallipoli/
72.21.217.135 US, United States 29/Apr/2017:21:26:20 /travel/uk/the-road-to-the-isles/
104.154.58.95 Unknown 29/Apr/2017:21:26:20 /robots.txt
66.249.75.4 US, United States 29/Apr/2017:21:26:18 /travel/uk/the-road-to-the-isles/
123.126.113.126 CN, China 29/Apr/2017:21:25:49 /networking/netstat-s.html
123.126.113.126 CN, China 29/Apr/2017:21:25:37 /networking/routing.html
108.29.19.114 Unknown 29/Apr/2017:21:25:30 /travel/usa/new-york-obama/
123.126.113.126 CN, China 29/Apr/2017:21:25:27 /travel/usa/new-york-roosevelts/
123.126.113.126 CN, China 29/Apr/2017:21:25:15 /travel/usa/new-york-fictional-architecture/greenwich-village.html
66.249.69.233 US, United States 29/Apr/2017:21:25:13 /cybersecurity/web-mail-spear-phishing.html
123.126.113.126 CN, China 29/Apr/2017:21:25:05 /cybersecurity/netusers/Index/cn
123.126.113.126 CN, China 29/Apr/2017:21:24:54 /cybersecurity/hacker-passwords.html
123.126.113.126 CN, China 29/Apr/2017:21:24:44 /linux/package-management.html
123.126.113.126 CN, China 29/Apr/2017:21:24:33 /networking/cisco-switch-repair/
209.190.96.34 US, United States 29/Apr/2017:21:23:03 /cybersecurity/cyberwar.html
209.190.2.178 US, United States 29/Apr/2017:21:23:03 /cybersecurity/intrusion-analysis/
209.190.2.178 US, United States 29/Apr/2017:21:23:03 /linux/flash-on-non-sse2-cpu.html
209.190.2.178 US, United States 29/Apr/2017:21:23:03 /linux/system-administration.html
209.51.197.122 US, United States 29/Apr/2017:21:23:03 /cybersecurity/linux-hardening.html
209.190.96.34 US, United States 29/Apr/2017:21:23:03 /networking/commands.html
209.190.95.42 US, United States 29/Apr/2017:21:23:03 /linux/digital-camera.html
209.51.205.2 US, United States 29/Apr/2017:21:23:03 /cybersecurity/password.html
207.46.13.147 US, United States 29/Apr/2017:21:22:50 /site-map.html
66.249.75.1 US, United States 29/Apr/2017:21:22:44 /linux/samba-active-directory/samba.html
206.246.93.34 US, United States 29/Apr/2017:21:22:41 /
69.169.227.169 Unknown 29/Apr/2017:21:22:40 /radio/

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