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.

207.46.13.120 US, United States 30/Apr/2017:13:39:58 /linux/rhel-centos-5-6-7/
54.80.133.210 US, United States 30/Apr/2017:13:39:57 /cybersecurity/root-password.html
54.80.133.210 US, United States 30/Apr/2017:13:39:49 /networking/netstat-a.html
54.80.133.210 US, United States 30/Apr/2017:13:39:40 /networking/vlan.html
54.80.133.210 US, United States 30/Apr/2017:13:39:30 /linux/performance-tuning/Index.html
65.55.218.63 US, United States 30/Apr/2017:13:39:21 /travel/turkey/aphrodisias/
136.243.17.161 DE, Germany 30/Apr/2017:13:39:21 /cybersecurity/cyberwar.html
66.249.69.109 US, United States 30/Apr/2017:13:39:20 /russian/grammar.html
54.80.133.210 US, United States 30/Apr/2017:13:39:20 /travel/france/boat/maintenance.html
54.80.133.210 US, United States 30/Apr/2017:13:39:08 /cybersecurity/netusers/Index/it
107.133.87.93 Unknown 30/Apr/2017:13:38:59 /technical/dsl/
54.80.133.210 US, United States 30/Apr/2017:13:38:58 /cybersecurity/netusers/Index/su
54.80.133.210 US, United States 30/Apr/2017:13:38:49 /technical/ata-ide-sata-usb-cable-pinouts.html
54.80.133.210 US, United States 30/Apr/2017:13:38:40 /travel/italy/amalfi/02-the-sights-in-amalfi-and-atrani.html
54.80.133.210 US, United States 30/Apr/2017:13:38:31 /networking/switch-programming.html
54.80.133.210 US, United States 30/Apr/2017:13:38:21 /linux/file-system.html
54.80.133.210 US, United States 30/Apr/2017:13:38:12 /travel/france/provence-megaliths/Index.html
188.64.28.147 Unknown 30/Apr/2017:13:38:06 /technical/convert-youtube-to-xvid.html
54.80.133.210 US, United States 30/Apr/2017:13:38:03 /travel/greece/orthodox-shrines.html
54.80.133.210 US, United States 30/Apr/2017:13:37:52 /travel/france/budget-hotels/Index.html
176.239.79.15 Unknown 30/Apr/2017:13:37:48 /travel/turkey/nemrut-dagi/
54.80.133.210 US, United States 30/Apr/2017:13:37:43 /linux/performance-tuning/hardware.html
54.80.133.210 US, United States 30/Apr/2017:13:37:34 /travel/usa/new-york-sro-flophouses/
54.80.133.210 US, United States 30/Apr/2017:13:37:25 /cybersecurity/descrambler.html
5.255.250.33 Unknown 30/Apr/2017:13:37:23 /travel/france/mont-saint-michel-saint-malo/
5.255.250.33 Unknown 30/Apr/2017:13:37:21 /travel/greece/orthodox-shrines.html
94.65.192.136 GR, Greece 30/Apr/2017:13:37:21 /technical/convert-youtube-to-xvid.html
54.80.133.210 US, United States 30/Apr/2017:13:37:15 /cybersecurity/availability.html
54.80.133.210 US, United States 30/Apr/2017:13:37:05 /travel/romania/Index.html
94.228.231.68 Unknown 30/Apr/2017:13:37:00 /technical/convert-youtube-to-xvid.html
54.80.133.210 US, United States 30/Apr/2017:13:36:56 /linux/raspberry-pi/hardware.html
64.62.252.164 US, United States 30/Apr/2017:13:36:55 /travel/usa/us-wash-ah.html
54.80.133.210 US, United States 30/Apr/2017:13:36:47 /linux/linux-alpha.html
64.62.252.164 US, United States 30/Apr/2017:13:36:39 /travel/usa/new-york-black-chamber/
64.62.252.164 US, United States 30/Apr/2017:13:36:39 /cybersecurity/history/uk-wwii.html
54.80.133.210 US, United States 30/Apr/2017:13:36:37 /cybersecurity/crypto/diffie-hellman.html
131.253.26.235 CA, Canada 30/Apr/2017:13:36:33 /travel/greece/
54.80.133.210 US, United States 30/Apr/2017:13:36:27 /cybersecurity/netusers/Index/fr
64.62.252.164 US, United States 30/Apr/2017:13:36:24 /travel/uk/scapa-flow/
64.62.252.164 US, United States 30/Apr/2017:13:36:24 /travel/uk/harwell-glider-base/
64.62.252.164 US, United States 30/Apr/2017:13:36:24 /travel/uk/swingate-chain-home/
64.62.252.164 US, United States 30/Apr/2017:13:36:24 /travel/uk/dover/
54.80.133.210 US, United States 30/Apr/2017:13:36:16 /travel/usa/us-wash-nss.html
54.80.133.210 US, United States 30/Apr/2017:13:36:07 /linux/ftp-howto.html
64.62.252.164 US, United States 30/Apr/2017:13:36:06 /travel/uk/bletchley-park/
207.46.13.121 US, United States 30/Apr/2017:13:36:05 /cybersecurity/netusers/Index/us
72.132.139.212 US, United States 30/Apr/2017:13:36:05 /linux/torrent-magnet-links.html
173.34.183.65 CA, Canada 30/Apr/2017:13:36:04 /travel/italy/amalfi/01-arriving-in-atrani.html
54.80.133.210 US, United States 30/Apr/2017:13:35:57 /travel/uk/the-road-to-the-isles/glen-nevis-fort-william.html
64.62.252.164 US, United States 30/Apr/2017:13:35:48 /cybersecurity/history/cabinet-war-rooms.html
54.80.133.210 US, United States 30/Apr/2017:13:35:47 /linux/raspberry-pi/nas.html
173.34.183.65 CA, Canada 30/Apr/2017:13:35:43 /travel/italy/amalfi/
69.133.146.187 US, United States 30/Apr/2017:13:35:41 /travel/france/normandy/pegasus-bridge.html
54.80.133.210 US, United States 30/Apr/2017:13:35:38 /travel/uk/glastonbury/king-arthur.html
145.255.245.151 Unknown 30/Apr/2017:13:35:35 /technical/dsl/
64.62.252.164 US, United States 30/Apr/2017:13:35:32 /travel/turkey/gallipoli/
64.62.252.164 US, United States 30/Apr/2017:13:35:31 /travel/italy/paestum/
64.62.252.164 US, United States 30/Apr/2017:13:35:31 /travel/france/normandy/
64.62.252.164 US, United States 30/Apr/2017:13:35:31 /travel/greece/greek/
54.80.133.210 US, United States 30/Apr/2017:13:35:28 /linux/rhel-centos-5-6-7/Index.html
54.80.133.210 US, United States 30/Apr/2017:13:35:18 /linux/rpm-patch.html
64.62.252.164 US, United States 30/Apr/2017:13:35:15 /russian/latex.html
64.62.252.164 US, United States 30/Apr/2017:13:35:14 /russian/grammar.html
64.62.252.164 US, United States 30/Apr/2017:13:35:14 /turkish/turkish-suffixes.html
54.80.133.210 US, United States 30/Apr/2017:13:35:07 /brewing/brewing-references.html
64.62.252.164 US, United States 30/Apr/2017:13:34:58 /turkish/verbs.html
54.80.133.210 US, United States 30/Apr/2017:13:34:56 /cybersecurity/hostile/win.trojan.upatre.html
54.80.133.210 US, United States 30/Apr/2017:13:34:45 /linux/ssh-1-admin.html
64.62.252.164 US, United States 30/Apr/2017:13:34:40 /turkish/nouns.html
64.62.252.164 US, United States 30/Apr/2017:13:34:40 /turkish/orthography.html
54.80.133.210 US, United States 30/Apr/2017:13:34:36 /travel/turkey/konya/Index.html
66.87.18.143 US, United States 30/Apr/2017:13:34:33 /technical/dsl/
54.80.133.210 US, United States 30/Apr/2017:13:34:26 /linux/compiling-opencv-on-openbsd.html
64.62.252.164 US, United States 30/Apr/2017:13:34:24 /turkish/background.html
5.9.6.70 Unknown 30/Apr/2017:13:34:23 /technical/convert-youtube-to-xvid.html
54.80.133.210 US, United States 30/Apr/2017:13:34:16 /linux/crashdumps.html
54.80.133.210 US, United States 30/Apr/2017:13:34:08 /travel/megaliths/Index.html
64.62.252.164 US, United States 30/Apr/2017:13:34:07 /pubs.html
64.62.252.164 US, United States 30/Apr/2017:13:34:07 /3d/raytrace/
64.62.252.164 US, United States 30/Apr/2017:13:34:07 /3d/3d-registration.html
64.62.252.164 US, United States 30/Apr/2017:13:34:06 /3d/clsi/
54.80.133.210 US, United States 30/Apr/2017:13:33:58 /travel/greece/greek-mainland.html
64.62.252.164 US, United States 30/Apr/2017:13:33:48 /3d/trilobite.html
64.62.252.164 US, United States 30/Apr/2017:13:33:48 /cybersecurity/hostile/manitowoc-bank-scam.html
54.80.133.210 US, United States 30/Apr/2017:13:33:48 /travel/latvia/Index.html
64.62.252.164 US, United States 30/Apr/2017:13:33:48 /cybersecurity/hostile/trojan-downloader.html
64.62.252.164 US, United States 30/Apr/2017:13:33:48 /cybersecurity/hostile/trojan-exchanger.html
54.80.133.210 US, United States 30/Apr/2017:13:33:39 /technical/samsung-galaxy/secret-code.html
64.62.252.164 US, United States 30/Apr/2017:13:33:29 /cybersecurity/hostile/trojan-agent.html
54.80.133.210 US, United States 30/Apr/2017:13:33:29 /fun/teaching/ostrich.html
54.80.133.210 US, United States 30/Apr/2017:13:33:19 /travel/usa/new-york-roosevelts/Index.html
64.62.252.164 US, United States 30/Apr/2017:13:33:13 /cybersecurity/hostile/sober.html
64.62.252.164 US, United States 30/Apr/2017:13:33:13 /cybersecurity/hostile/stration.html
64.62.252.164 US, United States 30/Apr/2017:13:33:13 /cybersecurity/hostile/downloader.html
64.62.252.164 US, United States 30/Apr/2017:13:33:12 /cybersecurity/hostile/mydoom.m.html
54.80.133.210 US, United States 30/Apr/2017:13:33:09 /cybersecurity/hostile/trojan-exchanger.html
54.80.133.210 US, United States 30/Apr/2017:13:32:59 /cybersecurity/netusers/Index/uk
64.62.252.164 US, United States 30/Apr/2017:13:32:57 /cybersecurity/hostile/mytob.kb.html
64.62.252.164 US, United States 30/Apr/2017:13:32:57 /cybersecurity/hostile/bagel.html
54.80.133.210 US, United States 30/Apr/2017:13:32:49 /linux/ssh.html
64.62.252.164 US, United States 30/Apr/2017:13:32:41 /cybersecurity/hostile/win.trojan.upatre.html
64.62.252.164 US, United States 30/Apr/2017:13:32:41 /cybersecurity/hostile/downloader-tibs.html
64.62.252.164 US, United States 30/Apr/2017:13:32:41 /cybersecurity/hostile/gibe-f-worm.html
54.80.133.210 US, United States 30/Apr/2017:13:32:40 /cybersecurity/netusers/Index/na
54.80.133.210 US, United States 30/Apr/2017:13:32:28 /travel/uk/swingate-chain-home/Index.html
116.75.203.65 IN, India 30/Apr/2017:13:32:27 /
116.75.203.65 IN, India 30/Apr/2017:13:32:27 /radio/probes.html
64.62.252.164 US, United States 30/Apr/2017:13:32:23 /cybersecurity/crypto/reading.html
64.62.252.164 US, United States 30/Apr/2017:13:32:22 /cybersecurity/crypto/culture.html
64.62.252.164 US, United States 30/Apr/2017:13:32:22 /cybersecurity/crypto/digital-signatures-and-certificates.html
64.62.252.164 US, United States 30/Apr/2017:13:32:22 /cybersecurity/crypto/hash.html
54.80.133.210 US, United States 30/Apr/2017:13:32:16 /radio/ic2sat-part-2.html
64.62.252.164 US, United States 30/Apr/2017:13:32:05 /cybersecurity/crypto/cipher-strength.html
54.80.133.210 US, United States 30/Apr/2017:13:32:05 /fun/freudian-seuss.html
64.62.252.164 US, United States 30/Apr/2017:13:32:05 /cybersecurity/crypto/one-time-pad.html
82.28.126.119 GB, United Kingdom 30/Apr/2017:13:32:01 /
82.28.126.119 GB, United Kingdom 30/Apr/2017:13:32:00 /radio/probes.html
54.80.133.210 US, United States 30/Apr/2017:13:31:52 /fun/requests-for-quotes/marlow-willard/Index.html
66.249.69.109 US, United States 30/Apr/2017:13:31:50 /travel/belgium/bastogne-ardennes/
64.62.252.164 US, United States 30/Apr/2017:13:31:46 /cybersecurity/crypto/ciphers.html
64.62.252.164 US, United States 30/Apr/2017:13:31:46 /cybersecurity/crypto/terminology.html
64.62.252.164 US, United States 30/Apr/2017:13:31:46 /digsig/
54.80.133.210 US, United States 30/Apr/2017:13:31:41 /cybersecurity/netusers/Index/ca
69.169.229.35 Unknown 30/Apr/2017:13:31:35 /cybersecurity/
64.62.252.164 US, United States 30/Apr/2017:13:31:31 /cybersecurity/public-key.html
64.62.252.164 US, United States 30/Apr/2017:13:31:31 /networking/netstat-a.html
64.62.252.164 US, United States 30/Apr/2017:13:31:31 /linux/raspberry-pi/sdr-ads-b-piaware-and-fr24feed.html
54.80.133.210 US, United States 30/Apr/2017:13:31:29 /digsig/Index.html
54.80.133.210 US, United States 30/Apr/2017:13:31:14 /travel/belgium/namur-dinant-ardennes/Index.html
64.62.252.164 US, United States 30/Apr/2017:13:31:13 /linux/performance-tuning/measurements.html
64.62.252.164 US, United States 30/Apr/2017:13:31:13 /linux/performance-tuning/applications.html
64.62.252.164 US, United States 30/Apr/2017:13:31:12 /linux/performance-tuning/nfs.html
66.249.91.57 US, United States 30/Apr/2017:13:31:11 /turkish/verbs.html
216.244.66.249 US, United States 30/Apr/2017:13:31:07 /cybersecurity/crypto/
54.80.133.210 US, United States 30/Apr/2017:13:31:02 /fun/requests-for-quotes/Index.html
64.62.252.164 US, United States 30/Apr/2017:13:30:57 /linux/performance-tuning/tcp.html
64.62.252.164 US, United States 30/Apr/2017:13:30:57 /linux/performance-tuning/ethernet.html
64.62.252.164 US, United States 30/Apr/2017:13:30:57 /linux/performance-tuning/file-systems.html
64.62.252.164 US, United States 30/Apr/2017:13:30:57 /linux/performance-tuning/disks.html
54.80.133.210 US, United States 30/Apr/2017:13:30:48 /cybersecurity/netusers/Index/sr
64.62.252.164 US, United States 30/Apr/2017:13:30:39 /linux/performance-tuning/hardware.html
54.80.133.210 US, United States 30/Apr/2017:13:30:33 /travel/france/boat-trip-canal-lateral-a-la-loire/briare-to-beaulieu-sur-loire.html
72.21.217.135 US, United States 30/Apr/2017:13:30:28 /robots.txt
64.62.252.164 US, United States 30/Apr/2017:13:30:24 /radio/internet-radio.html
64.62.252.164 US, United States 30/Apr/2017:13:30:24 /radio/propagation.html
64.62.252.164 US, United States 30/Apr/2017:13:30:24 /radio/mwdx.html
64.62.252.164 US, United States 30/Apr/2017:13:30:24 /radio/frequencies.html
70.181.6.104 US, United States 30/Apr/2017:13:30:19 /cybersecurity/comptia/
54.80.133.210 US, United States 30/Apr/2017:13:30:16 /travel/italy/amalfi/Index.html
173.208.58.242 Unknown 30/Apr/2017:13:30:15 /technical/hp-printer-ready-message.html
64.62.252.164 US, United States 30/Apr/2017:13:30:03 /radio/rf-spectrum.html
64.62.252.164 US, United States 30/Apr/2017:13:30:03 /radio/ic-3220.html
64.62.252.164 US, United States 30/Apr/2017:13:30:03 /radio/ic229.html
54.80.133.210 US, United States 30/Apr/2017:13:29:49 /travel/uk/scotland-isle-of-iona/iona.html
64.62.252.164 US, United States 30/Apr/2017:13:29:47 /radio/ic2sat-part-2.html
64.62.252.164 US, United States 30/Apr/2017:13:29:47 /radio/ic2sat.html
64.62.252.164 US, United States 30/Apr/2017:13:29:47 /linux/raspberry-pi/ads-b-antenna.html
64.62.252.164 US, United States 30/Apr/2017:13:29:47 /radio/fort-tuthill.html
89.145.95.79 GB, United Kingdom 30/Apr/2017:13:29:45 /radio/morse-code.html
64.62.252.164 US, United States 30/Apr/2017:13:29:32 /radio/balanced-line.html
64.62.252.164 US, United States 30/Apr/2017:13:29:31 /radio/j-poles.html
64.62.252.164 US, United States 30/Apr/2017:13:29:16 /radio/hf-short-dipoles.html
64.62.252.164 US, United States 30/Apr/2017:13:29:15 /radio/rhombic-antennas.html
64.62.252.164 US, United States 30/Apr/2017:13:29:15 /radio/tone-control.html
64.62.252.164 US, United States 30/Apr/2017:13:29:15 /radio/copper-wire/
64.62.252.164 US, United States 30/Apr/2017:13:28:59 /radio/morse-code.html
64.62.252.164 US, United States 30/Apr/2017:13:28:59 /radio/hfqrp.html
64.62.252.164 US, United States 30/Apr/2017:13:28:59 /3d/morphometrics.html
90.173.5.40 ES, Spain 30/Apr/2017:13:28:43 /technical/samsung-galaxy/linux.html
54.80.133.210 US, United States 30/Apr/2017:13:28:42 /cybersecurity/hostile/Index.html
64.62.252.164 US, United States 30/Apr/2017:13:28:42 /3d/archaeology.html
64.62.252.164 US, United States 30/Apr/2017:13:28:41 /3d/extrema.html
64.62.252.164 US, United States 30/Apr/2017:13:28:41 /3d/multiview.html
64.62.252.164 US, United States 30/Apr/2017:13:28:41 /3d/range-analysis.html
54.80.133.210 US, United States 30/Apr/2017:13:28:31 /travel/usa/venice-california/Index.html
54.80.133.210 US, United States 30/Apr/2017:13:28:24 /travel/bulgaria/Index.html
64.62.252.164 US, United States 30/Apr/2017:13:28:23 /3d/normals.html
64.62.252.164 US, United States 30/Apr/2017:13:28:23 /3d/archival.html
64.62.252.164 US, United States 30/Apr/2017:13:28:23 /3d/range-maps.html
64.62.252.164 US, United States 30/Apr/2017:13:28:23 /technical/google-adsense-and-xhtml.html
64.62.252.164 US, United States 30/Apr/2017:13:28:07 /technical/html-greyscale-test.html
54.80.133.210 US, United States 30/Apr/2017:13:28:02 /travel/belgium/bastogne-ardennes/houffalize-malmedy-st-hubert.html
54.80.133.210 US, United States 30/Apr/2017:13:28:02 /robots.txt
64.62.252.164 US, United States 30/Apr/2017:13:27:49 /technical/search-engine-optimization-howto.html
64.62.252.164 US, United States 30/Apr/2017:13:27:49 /technical/htmlhelp.html
64.62.252.164 US, United States 30/Apr/2017:13:27:49 /technical/html4-or-xhtml-to-html5.html
64.62.252.164 US, United States 30/Apr/2017:13:27:48 /fun/writing-thoughts.html
64.62.252.164 US, United States 30/Apr/2017:13:27:31 /technical/click-of-death.html
64.62.252.164 US, United States 30/Apr/2017:13:27:31 /technical/quickdisk-recovery.html
64.62.252.164 US, United States 30/Apr/2017:13:27:31 /radio/construction.html
180.76.15.157 Unknown 30/Apr/2017:13:27:31 /travel/estonia/
64.62.252.164 US, United States 30/Apr/2017:13:27:30 /technical/current-box.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