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.

5.255.250.33 Unknown 26/Jun/2017:02:08:14 /travel/athens-to-paris/navtable.html
54.145.122.109 US, United States 26/Jun/2017:02:08:11 /travel/usa/us-wash-nss.html
5.255.250.33 Unknown 26/Jun/2017:02:08:10 /travel/usa/new-york-fictional-architecture/bowery-lower-east-side.html
176.54.162.131 Unknown 26/Jun/2017:02:08:04 /linux/openbsd-qemu-windows-howto.html
54.145.122.109 US, United States 26/Jun/2017:02:08:02 /linux/performance-tuning/ethernet.html
5.255.250.33 Unknown 26/Jun/2017:02:07:54 /travel/uk/the-road-to-the-isles/creaguaineach-staoineag.html
54.145.122.109 US, United States 26/Jun/2017:02:07:54 /cybersecurity/netusers/Index/dl
69.169.225.43 Unknown 26/Jun/2017:02:07:48 /linux/openbsd-kernel.html
54.145.122.109 US, United States 26/Jun/2017:02:07:44 /linux/performance-tuning/Index.html
54.145.122.109 US, United States 26/Jun/2017:02:07:36 /travel/turkey/konya/Index.html
209.126.120.40 US, United States 26/Jun/2017:02:07:36 /linux/openbsd-kernel.html
80.61.97.65 NL, Netherlands 26/Jun/2017:02:07:30 /turkish/verbs.html
54.145.122.109 US, United States 26/Jun/2017:02:07:25 /fun/requests-for-quotes/simu-construction/Index.html
54.145.122.109 US, United States 26/Jun/2017:02:07:16 /wshta/2011-09-17/Index.html
54.145.122.109 US, United States 26/Jun/2017:02:07:07 /fun/freudian-seuss.html
54.145.122.109 US, United States 26/Jun/2017:02:06:58 /cybersecurity/netusers/Index/id
54.145.122.109 US, United States 26/Jun/2017:02:06:48 /travel/france/boat-trip-canal-lateral-a-la-loire/briare.html
69.169.225.227 Unknown 26/Jun/2017:02:06:44 /cybersecurity/privacy-policy.html
54.145.122.109 US, United States 26/Jun/2017:02:06:39 /networking/wan-specs.html
193.57.249.2 FR, France 26/Jun/2017:02:06:32 /linux/performance-tuning/disks.html
54.145.122.109 US, United States 26/Jun/2017:02:06:28 /cybersecurity/history/uss-chaumont/crewmen.html
209.126.103.112 US, United States 26/Jun/2017:02:06:23 /cybersecurity/privacy-policy.html
89.145.95.69 GB, United Kingdom 26/Jun/2017:02:06:21 /technical/samsung-galaxy/secret-code.html
54.145.122.109 US, United States 26/Jun/2017:02:06:19 /travel/russia/getting-there.html
54.145.122.109 US, United States 26/Jun/2017:02:06:09 /linux/raspberry-pi/sdr-ads-b-flight-tracking.html
54.145.122.109 US, United States 26/Jun/2017:02:05:57 /travel/trinidad/Index.html
54.145.122.109 US, United States 26/Jun/2017:02:05:47 /travel/usa/new-york-st-marks-place/Index.html
188.165.200.217 Unknown 26/Jun/2017:02:05:42 /cybersecurity/netusers/Index/ipk
216.244.66.249 US, United States 26/Jun/2017:02:05:41 /3d/archival.html
216.244.66.249 US, United States 26/Jun/2017:02:05:38 /cybersecurity/hostile/trojan-agent.html
54.145.122.109 US, United States 26/Jun/2017:02:05:37 /cybersecurity/syn1.html
216.244.66.249 US, United States 26/Jun/2017:02:05:35 /travel/hungary/budapest/
216.244.66.249 US, United States 26/Jun/2017:02:05:34 /travel/italy/cinque-terre/
216.244.66.249 US, United States 26/Jun/2017:02:05:33 /travel/turkey/maryemana/
216.244.66.249 US, United States 26/Jun/2017:02:05:32 /travel/usa/new-york-nypd/
66.249.66.93 US, United States 26/Jun/2017:02:05:27 /travel/alaska/
66.249.66.92 US, United States 26/Jun/2017:02:05:27 /robots.txt
54.145.122.109 US, United States 26/Jun/2017:02:05:25 /travel/usa/new-york-fictional-architecture/tribeca-financial-district.html
54.145.122.109 US, United States 26/Jun/2017:02:05:15 /linux/apache-referer-log-analysis.html
210.195.125.137 MY, Malaysia 26/Jun/2017:02:05:07 /
210.195.125.137 MY, Malaysia 26/Jun/2017:02:05:06 /radio/probes.html
54.145.122.109 US, United States 26/Jun/2017:02:05:06 /linux/performance-tuning/disks.html
54.145.122.109 US, United States 26/Jun/2017:02:04:56 /cybersecurity/root-password.html
54.145.122.109 US, United States 26/Jun/2017:02:04:45 /travel/uk/avebury/Index.html
54.145.122.109 US, United States 26/Jun/2017:02:04:36 /radio/j-poles.html
54.145.122.109 US, United States 26/Jun/2017:02:04:26 /cybersecurity/sysaudit.html
216.244.66.202 US, United States 26/Jun/2017:02:04:19 /linux/performance-tuning/applications.html
54.145.122.109 US, United States 26/Jun/2017:02:04:17 /travel/romania/food/Index.html
5.255.250.33 Unknown 26/Jun/2017:02:04:07 /fun/tcpip-haiku.html
54.145.122.109 US, United States 26/Jun/2017:02:04:06 /travel/france/saumur-megaliths/Index.html
216.244.66.202 US, United States 26/Jun/2017:02:04:00 /linux/unix-tips.html
54.145.122.109 US, United States 26/Jun/2017:02:03:56 /linux/raspberry-pi/hardware.html
70.81.161.36 CA, Canada 26/Jun/2017:02:03:51 /
70.81.161.36 CA, Canada 26/Jun/2017:02:03:51 /radio/probes.html
54.145.122.109 US, United States 26/Jun/2017:02:03:45 /3d/extrema.html
54.145.122.109 US, United States 26/Jun/2017:02:03:34 /cybersecurity/netusers/Index/na
54.145.122.109 US, United States 26/Jun/2017:02:03:22 /cybersecurity/netusers/Index/uk
54.145.122.109 US, United States 26/Jun/2017:02:03:10 /cybersecurity/crypto/hash-search.html
118.143.92.209 HK, Hong Kong 26/Jun/2017:02:03:06 /travel/italy/cinque-terre/
146.88.178.138 US, United States 26/Jun/2017:02:03:02 /cybersecurity/privacy-policy.html
23.92.34.82 GB, United Kingdom 26/Jun/2017:02:03:00 /linux/openbsd-kernel.html
54.145.122.109 US, United States 26/Jun/2017:02:02:59 /travel/estonia/Index.html
54.145.122.109 US, United States 26/Jun/2017:02:02:48 /travel/uk/scapa-flow/Index.html
66.249.69.54 US, United States 26/Jun/2017:02:02:40 /cybersecurity/netusers/Index/us
54.145.122.109 US, United States 26/Jun/2017:02:02:37 /brewing/brewing-references.html
54.145.122.109 US, United States 26/Jun/2017:02:02:25 /travel/uk/the-road-to-the-isles/luibeilt-steall.html
54.145.122.109 US, United States 26/Jun/2017:02:02:13 /technical/extract-mp3-audio-from-video.html
54.145.122.109 US, United States 26/Jun/2017:02:02:02 /travel/usa/new-york-roosevelts/Index.html
180.76.15.9 Unknown 26/Jun/2017:02:01:55 /fun/requests-for-quotes/ittehad-chemicals/iso-14001.html
93.158.152.203 RU, Russian Federation 26/Jun/2017:02:01:55 /travel/usa/new-york-fictional-architecture/bowery-lower-east-side.html
5.255.250.33 Unknown 26/Jun/2017:02:01:54 /travel/greece/tiryns.html
54.145.122.109 US, United States 26/Jun/2017:02:01:50 /cybersecurity/hostile/trojan-exchanger.html
5.255.250.33 Unknown 26/Jun/2017:02:01:45 /travel/athens-to-paris/veliko-tarnovo-bucharest.html
54.145.122.109 US, United States 26/Jun/2017:02:01:39 /cybersecurity/netusers/Index/vn
54.145.122.109 US, United States 26/Jun/2017:02:01:27 /cybersecurity/netusers/Index/fr
54.145.122.109 US, United States 26/Jun/2017:02:01:16 /travel/uk/stonehenge/Index.html
66.249.69.85 US, United States 26/Jun/2017:02:01:16 /cybersecurity/netusers/Index/further
54.145.122.109 US, United States 26/Jun/2017:02:01:04 /linux/ssh.html
5.255.250.33 Unknown 26/Jun/2017:02:00:58 /cybersecurity/history/uk-wwii.html
54.145.122.109 US, United States 26/Jun/2017:02:00:53 /travel/athens-to-paris/budapest-prague.html
5.255.250.33 Unknown 26/Jun/2017:02:00:48 /linux/linux-commands.html
118.211.3.11 Unknown 26/Jun/2017:02:00:41 /technical/samsung-galaxy/linux.html
54.145.122.109 US, United States 26/Jun/2017:02:00:39 /linux/linux-blog.html
5.255.250.33 Unknown 26/Jun/2017:02:00:37 /linux/performance-tuning/
70.197.81.116 US, United States 26/Jun/2017:02:00:36 /networking/cisco.html
54.145.122.109 US, United States 26/Jun/2017:02:00:27 /radio/internet-radio.html
72.21.217.159 US, United States 26/Jun/2017:02:00:18 /travel/france/normandy/arromanches.html
180.191.134.73 Unknown 26/Jun/2017:02:00:16 /
180.191.134.73 Unknown 26/Jun/2017:02:00:15 /radio/probes.html
54.145.122.109 US, United States 26/Jun/2017:02:00:13 /travel/uk/lee-ho-fook/Index.html
210.74.130.170 CN, China 26/Jun/2017:02:00:12 /travel/france/normandy/arromanches.html
209.126.103.241 US, United States 26/Jun/2017:02:00:05 /3d/
54.145.122.109 US, United States 26/Jun/2017:01:59:59 /travel/uk/scotland-isle-of-iona/iona.html
95.9.27.174 Unknown 26/Jun/2017:01:59:55 /turkish/nouns.html
54.145.122.109 US, United States 26/Jun/2017:01:59:46 /travel/italy/amalfi/Index.html
46.118.124.89 Unknown 26/Jun/2017:01:59:45 /cybersecurity/
5.255.250.33 Unknown 26/Jun/2017:01:59:43 /3d/morphometrics.html
46.118.124.89 Unknown 26/Jun/2017:01:59:41 /cybersecurity/
46.118.124.89 Unknown 26/Jun/2017:01:59:41 /cybersecurity/
57.82.10.65 EU, Europe 26/Jun/2017:01:59:35 /linux/torrent-magnet-links.html
54.145.122.109 US, United States 26/Jun/2017:01:59:33 /travel/uk/glastonbury/king-arthur.html
5.255.250.33 Unknown 26/Jun/2017:01:59:33 /travel/russia/sankt-peterburg.html
52.90.238.3 US, United States 26/Jun/2017:01:59:22 /travel/greece/trains.html
54.145.122.109 US, United States 26/Jun/2017:01:59:20 /travel/france/boat-trip-canal-lateral-a-la-loire/briare-to-beaulieu-sur-loire.html
72.21.217.135 US, United States 26/Jun/2017:01:59:18 /travel/greece/trains.html
5.255.250.33 Unknown 26/Jun/2017:01:59:14 /cybersecurity/cyberwar.html
66.249.75.197 US, United States 26/Jun/2017:01:59:11 /travel/greece/trains.html
54.145.122.109 US, United States 26/Jun/2017:01:59:07 /cybersecurity/netusers/Index/sr
54.145.122.109 US, United States 26/Jun/2017:01:58:55 /cybersecurity/history/uk-wwii.html
5.255.250.33 Unknown 26/Jun/2017:01:58:50 /brewing/
5.255.250.33 Unknown 26/Jun/2017:01:58:47 /fun/teaching/math-trouble.html
5.255.250.33 Unknown 26/Jun/2017:01:58:45 /fun/
54.145.122.109 US, United States 26/Jun/2017:01:58:40 /3d/histogram/3d-histogram.html
5.255.250.33 Unknown 26/Jun/2017:01:58:32 /travel/japan/
5.255.250.33 Unknown 26/Jun/2017:01:58:30 /travel/lithuania/
5.255.250.33 Unknown 26/Jun/2017:01:58:28 /fun/requests-for-quotes/marlow-willard/
5.255.250.33 Unknown 26/Jun/2017:01:58:26 /travel/athens-to-paris/
54.145.122.109 US, United States 26/Jun/2017:01:58:26 /travel/uk/orkney-neolithic/ring-of-brodgar.html
163.172.71.23 GB, United Kingdom 26/Jun/2017:01:58:23 /linux/linux-kernel.html
163.172.71.23 GB, United Kingdom 26/Jun/2017:01:58:22 /robots.txt
54.145.122.109 US, United States 26/Jun/2017:01:58:13 /travel/athens-to-paris/Index.html
54.145.122.109 US, United States 26/Jun/2017:01:58:00 /travel/uk/the-road-to-the-isles/start-creaguaineach.html
54.145.122.109 US, United States 26/Jun/2017:01:57:47 /travel/usa/new-york-andy-warhol/Index.html
23.92.95.27 GB, United Kingdom 26/Jun/2017:01:57:37 /3d/
54.145.122.109 US, United States 26/Jun/2017:01:57:34 /cybersecurity/history/uss-chaumont/photos-other.html
54.145.122.109 US, United States 26/Jun/2017:01:57:21 /travel/latvia/Index.html
54.145.122.109 US, United States 26/Jun/2017:01:57:08 /linux/performance-tuning/file-systems.html
5.255.250.33 Unknown 26/Jun/2017:01:57:03 /networking/commands.html
216.244.66.202 US, United States 26/Jun/2017:01:56:56 /technical/samsung-galaxy/sim-unlocking.html
54.145.122.109 US, United States 26/Jun/2017:01:56:54 /linux/compiling-opencv-on-openbsd.html
54.145.122.109 US, United States 26/Jun/2017:01:56:37 /wshta/Index.html
5.255.250.33 Unknown 26/Jun/2017:01:56:25 /travel/usa/new-york-revolutionary/
5.255.250.33 Unknown 26/Jun/2017:01:56:23 /linux/unix-supermodel.html
54.145.122.109 US, United States 26/Jun/2017:01:56:22 /travel/belgium/bastogne-ardennes/ardennes-forest.html
54.145.122.109 US, United States 26/Jun/2017:01:56:05 /travel/france/normandy/omaha-beach.html
5.255.250.33 Unknown 26/Jun/2017:01:55:57 /travel/china/guangzhou-2.html
54.145.122.109 US, United States 26/Jun/2017:01:55:52 /3d/trilobite.html
54.145.122.109 US, United States 26/Jun/2017:01:55:37 /networking/switch-programming.html
5.255.250.33 Unknown 26/Jun/2017:01:55:33 /travel/belgium/bastogne-ardennes/
66.249.69.50 US, United States 26/Jun/2017:01:55:32 /cybersecurity/netusers/Index/ao
40.77.167.136 US, United States 26/Jun/2017:01:55:30 /networking/sdn.html
54.145.122.109 US, United States 26/Jun/2017:01:55:21 /radio/rhombic-antennas.html
5.255.250.33 Unknown 26/Jun/2017:01:55:07 /travel/uk/scotland-grit-boxes/
54.145.122.109 US, United States 26/Jun/2017:01:55:03 /travel/france/mont-saint-michel-saint-malo/pontorson.html
54.145.122.109 US, United States 26/Jun/2017:01:54:46 /travel/egypt/luxor.html
5.255.250.33 Unknown 26/Jun/2017:01:54:34 /technical/ata-ide-sata-usb-cable-pinouts.html?ref=binfind.com
54.145.122.109 US, United States 26/Jun/2017:01:54:30 /travel/athens-to-paris/bucharest-gura-humorului.html
54.145.122.109 US, United States 26/Jun/2017:01:54:14 /travel/uk/glastonbury/wearyall-hill.html
168.235.197.27 US, United States 26/Jun/2017:01:54:04 /linux/torrent-magnet-links.html
54.145.122.109 US, United States 26/Jun/2017:01:53:56 /cybersecurity/netusers/Index/sk
54.145.122.109 US, United States 26/Jun/2017:01:53:38 /travel/usa/new-york-lga-arrival/Index.html
78.141.179.155 LU, Luxembourg 26/Jun/2017:01:53:26 /linux/openbsd-qemu-windows-howto.html
54.145.122.109 US, United States 26/Jun/2017:01:53:21 /cybersecurity/public-key.html
180.76.15.142 Unknown 26/Jun/2017:01:53:13 /linux/linux-boot.html
23.27.149.60 GB, United Kingdom 26/Jun/2017:01:53:08 /travel/poland/
54.145.122.109 US, United States 26/Jun/2017:01:53:04 /travel/belgium/bastogne-ardennes/houffalize-malmedy-st-hubert.html
157.55.39.198 US, United States 26/Jun/2017:01:53:03 /linux/vmware-networking.html
54.145.122.109 US, United States 26/Jun/2017:01:52:47 /cybersecurity/descrambler.html
5.255.250.33 Unknown 26/Jun/2017:01:52:40 /3d/multiview.html
54.145.122.109 US, United States 26/Jun/2017:01:52:31 /russian/Index.html
54.145.122.109 US, United States 26/Jun/2017:01:52:13 /radio/frequencies.html
195.154.161.171 FR, France 26/Jun/2017:01:52:03 /linux/apache-https-x509v3.html
54.145.122.109 US, United States 26/Jun/2017:01:51:54 /linux/flash-on-non-sse2-cpu.html
5.255.250.33 Unknown 26/Jun/2017:01:51:34 /cybersecurity/crypto/haiku.html
54.145.122.109 US, United States 26/Jun/2017:01:51:34 /cybersecurity/netusers/Index/iz
54.145.122.109 US, United States 26/Jun/2017:01:51:15 /linux/144/Index.html
5.255.250.33 Unknown 26/Jun/2017:01:51:06 /cybersecurity/crypto/reading.html
54.145.122.109 US, United States 26/Jun/2017:01:50:52 /linux/system-administration.html
211.30.171.147 AU, Australia 26/Jun/2017:01:50:33 /technical/hdmi.html
54.237.219.64 US, United States 26/Jun/2017:01:50:22 /linux/vim-word-count.html
54.145.122.109 US, United States 26/Jun/2017:01:50:19 /travel/france/budget-hotels/Index.html
212.182.1.201 PL, Poland 26/Jun/2017:01:49:51 /russian/latex.html
68.180.228.171 US, United States 26/Jun/2017:01:49:43 /travel/belgium/belgian-beers/brussels-cafes.html
59.182.189.163 IN, India 26/Jun/2017:01:49:07 /
59.182.189.163 IN, India 26/Jun/2017:01:49:04 /radio/probes.html
54.145.122.109 US, United States 26/Jun/2017:01:48:58 /linux/rhel-centos-5-6-7/booting.html
82.131.207.136 HU, Hungary 26/Jun/2017:01:48:58 /technical/ata-ide-sata-usb-cable-pinouts.html
54.145.122.109 US, United States 26/Jun/2017:01:48:58 /robots.txt
69.169.236.29 Unknown 26/Jun/2017:01:48:55 /turkish/
66.249.69.54 US, United States 26/Jun/2017:01:48:27 /cybersecurity/netusers/Index/sf
5.255.250.33 Unknown 26/Jun/2017:01:48:24 /cybersecurity/crypto/
34.229.236.100 US, United States 26/Jun/2017:01:48:21 /travel/france/detectives/

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