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?


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. US, United States 30/Mar/2017:03:56:11 /cybersecurity/authentication.html US, United States 30/Mar/2017:03:56:10 /networking/vlan.html US, United States 30/Mar/2017:03:56:09 /networking/netstat-a.html US, United States 30/Mar/2017:03:56:07 /travel/uk/the-road-to-the-isles/glen-nevis-fort-william.html US, United States 30/Mar/2017:03:56:06 /fun/teaching/ostrich.html US, United States 30/Mar/2017:03:56:04 /cybersecurity/history/uss-chaumont/photos-navsourceorg.html US, United States 30/Mar/2017:03:56:03 /linux/rpm-patch.html US, United States 30/Mar/2017:03:56:02 /travel/usa/venice-california/Index.html US, United States 30/Mar/2017:03:56:00 /cybersecurity/hostile/Index.html US, United States 30/Mar/2017:03:55:59 /fun/brilliant-movie-ideas/no-worse.html US, United States 30/Mar/2017:03:55:58 /linux/file-system.html US, United States 30/Mar/2017:03:55:56 /travel/greece/paros.html US, United States 30/Mar/2017:03:55:55 /technical/ata-ide-sata-usb-cable-pinouts.html US, United States 30/Mar/2017:03:55:54 /linux/performance-tuning/ethernet.html US, United States 30/Mar/2017:03:55:53 /travel/usa/new-york-roosevelts/Index.html US, United States 30/Mar/2017:03:55:51 /travel/france/boat/maintenance.html US, United States 30/Mar/2017:03:55:50 /cybersecurity/netusers/Index/it US, United States 30/Mar/2017:03:55:49 /cybersecurity/sysaudit.html US, United States 30/Mar/2017:03:55:47 /digsig/Index.html US, United States 30/Mar/2017:03:55:46 /travel/uk/scotland-isle-of-iona/iona.html US, United States 30/Mar/2017:03:55:45 /travel/italy/amalfi/Index.html US, United States 30/Mar/2017:03:55:43 /fun/brilliant-movie-ideas/unholy-unions.html US, United States 30/Mar/2017:03:55:42 /cybersecurity/netusers/Index/ca US, United States 30/Mar/2017:03:55:40 /linux/crashdumps.html US, United States 30/Mar/2017:03:55:39 /travel/france/boat-trip-canal-lateral-a-la-loire/briare-to-beaulieu-sur-loire.html US, United States 30/Mar/2017:03:55:38 /linux/ftp-howto.html US, United States 30/Mar/2017:03:55:36 /travel/uk/swingate-chain-home/Index.html US, United States 30/Mar/2017:03:55:35 /radio/ic2sat-part-2.html US, United States 30/Mar/2017:03:55:34 /cybersecurity/history/uss-chaumont/crewmen.html Unknown 30/Mar/2017:03:55:33 /radio/hf-short-dipoles.html US, United States 30/Mar/2017:03:55:32 /linux/raspberry-pi/sdr-ads-b-flight-tracking.html US, United States 30/Mar/2017:03:55:31 /travel/russia/getting-there.html US, United States 30/Mar/2017:03:55:30 /fun/teaching/us-vs-britain-vs-france.html US, United States 30/Mar/2017:03:55:28 /linux/performance-tuning/Index.html US, United States 30/Mar/2017:03:55:25 /cybersecurity/history/uk-wwii.html US, United States 30/Mar/2017:03:55:23 /technical/samsung-galaxy/secret-code.html US, United States 30/Mar/2017:03:55:20 /cybersecurity/netusers/Index/sf Unknown 30/Mar/2017:03:55:18 / DE, Germany 30/Mar/2017:03:55:18 /linux/performance-tuning/ethernet.html Unknown 30/Mar/2017:03:55:18 /radio/probes.html US, United States 30/Mar/2017:03:55:17 /travel/greece/orthodox-shrines.html US, United States 30/Mar/2017:03:55:12 /linux/keyboard-mouse.html US, United States 30/Mar/2017:03:55:11 /robots.txt US, United States 30/Mar/2017:03:54:53 /linux/migrate-rhel-to-centos.html US, United States 30/Mar/2017:03:54:52 /travel/italy/trains/ HK, Hong Kong 30/Mar/2017:03:54:51 /cybersecurity/ HK, Hong Kong 30/Mar/2017:03:53:59 /cybersecurity/crypto/cipher-strength.html Unknown 30/Mar/2017:03:53:40 / Unknown 30/Mar/2017:03:53:40 /radio/probes.html DE, Germany 30/Mar/2017:03:53:24 /linux/vim-word-count.html TR, Turkey 30/Mar/2017:03:53:15 /networking/nat.html TR, Turkey 30/Mar/2017:03:53:14 /networking/routing.html US, United States 30/Mar/2017:03:51:38 /technical/samsung-galaxy/linux.html Unknown 30/Mar/2017:03:51:30 /travel/usa/new-york-lga-arrival/ Unknown 30/Mar/2017:03:51:30 /3d/histogram/ GB, United Kingdom 30/Mar/2017:03:51:28 /travel/usa/new-york-lga-arrival/ US, United States 30/Mar/2017:03:51:27 / US, United States 30/Mar/2017:03:50:57 /travel/latvia/?D=D US, United States 30/Mar/2017:03:50:51 /3d/xray/xsane.html NO, Norway 30/Mar/2017:03:50:16 /linux/lvm-rescue-boot.html US, United States 30/Mar/2017:03:49:43 /technical/google-adsense-and-xhtml.html US, United States 30/Mar/2017:03:49:39 /russian/grammar.html Unknown 30/Mar/2017:03:49:24 /networking/switch-programming.html Unknown 30/Mar/2017:03:49:23 /turkish/verbs.html US, United States 30/Mar/2017:03:49:05 /cybersecurity/crypto/digital-signatures-and-certificates.html Unknown 30/Mar/2017:03:48:52 / Unknown 30/Mar/2017:03:48:51 /radio/probes.html Unknown 30/Mar/2017:03:48:06 /linux/sendmail-ssl.html US, United States 30/Mar/2017:03:47:56 /robots.txt US, United States 30/Mar/2017:03:47:56 /robots.txt US, United States 30/Mar/2017:03:47:48 /turkish/nouns.html IT, Italy 30/Mar/2017:03:47:40 /technical/samsung-galaxy/linux.html Unknown 30/Mar/2017:03:47:30 /networking/commands.html CN, China 30/Mar/2017:03:47:29 / RO, Romania 30/Mar/2017:03:47:29 / CZ, Czech Republic 30/Mar/2017:03:47:23 /travel/turkey/lycia/ CZ, Czech Republic 30/Mar/2017:03:47:22 /technical/video-camera-rotate.html CZ, Czech Republic 30/Mar/2017:03:47:17 /robots.txt KG, Kyrgyzstan 30/Mar/2017:03:47:02 /turkish/turkish-verbs.pdf FI, Finland 30/Mar/2017:03:46:50 /linux/performance-tuning/disks.html Unknown 30/Mar/2017:03:46:47 /linux/missing-gtk-modules.html Unknown 30/Mar/2017:03:46:41 /cybersecurity/netusers/Index/cu US, United States 30/Mar/2017:03:46:41 /turkish/ NZ, New Zealand 30/Mar/2017:03:46:39 /travel/france/boat/ GB, United Kingdom 30/Mar/2017:03:46:30 /travel/uk/glastonbury/king-arthur.html GB, United Kingdom 30/Mar/2017:03:46:20 /robots.txt Unknown 30/Mar/2017:03:46:18 /robots.txt Unknown 30/Mar/2017:03:46:11 /turkish/verbs.html Unknown 30/Mar/2017:03:46:11 /linux/lvm-rescue-boot.html Unknown 30/Mar/2017:03:46:11 /linux/dev-random.html Unknown 30/Mar/2017:03:46:11 /technical/samsung-galaxy/linux.html UA, Ukraine 30/Mar/2017:03:45:35 /technical/ata-ide-sata-usb-cable-pinouts.html NZ, New Zealand 30/Mar/2017:03:45:23 /travel/france/ US, United States 30/Mar/2017:03:44:35 /technical/samsung-galaxy/secret-code.html US, United States 30/Mar/2017:03:44:34 /cybersecurity/os-specific.html TR, Turkey 30/Mar/2017:03:44:31 /networking/protocols.html Unknown 30/Mar/2017:03:44:30 /linux/unix-tips.html GB, United Kingdom 30/Mar/2017:03:44:27 /linux/unix-tips.html Unknown 30/Mar/2017:03:44:27 /cybersecurity/os-specific.html Unknown 30/Mar/2017:03:43:55 /linux/linux-kernel.html Unknown 30/Mar/2017:03:43:54 /linux/linux-kernel.html CN, China 30/Mar/2017:03:43:48 /turkish/background.html Unknown 30/Mar/2017:03:43:43 /technical/samsung-galaxy/linux.html SG, Singapore 30/Mar/2017:03:43:21 /travel/japan/tokyo-ueno-koen.html TR, Turkey 30/Mar/2017:03:43:08 /turkish/ Unknown 30/Mar/2017:03:43:06 /3d/xray/ SG, Singapore 30/Mar/2017:03:43:06 /travel/japan/tokyo-ueno-koen.html TR, Turkey 30/Mar/2017:03:42:50 /networking/nat.html TR, Turkey 30/Mar/2017:03:42:49 /networking/ TR, Turkey 30/Mar/2017:03:42:48 /networking/routing.html US, United States 30/Mar/2017:03:42:24 /travel/france/boat/ NZ, New Zealand 30/Mar/2017:03:42:22 /travel/france/boat/ GB, United Kingdom 30/Mar/2017:03:42:10 /travel/uk/stonehenge/ US, United States 30/Mar/2017:03:42:04 / US, United States 30/Mar/2017:03:41:55 /3d/data-collection.html US, United States 30/Mar/2017:03:41:47 /robots.txt DE, Germany 30/Mar/2017:03:41:16 /travel/usa/new-york-mcgees/ GB, United Kingdom 30/Mar/2017:03:41:13 /travel/usa/new-york-mcgees/ US, United States 30/Mar/2017:03:40:50 /3d/xray/ Unknown 30/Mar/2017:03:40:04 /cybersecurity/password.html Unknown 30/Mar/2017:03:39:58 /travel/turkey/ CN, China 30/Mar/2017:03:39:52 /travel/china/guangzhou-1.html TR, Turkey 30/Mar/2017:03:39:51 /cybersecurity/verify-digital-signature.html TR, Turkey 30/Mar/2017:03:39:40 /cybersecurity/ US, United States 30/Mar/2017:03:39:26 /travel/turkey/nemrut-dagi/ DE, Germany 30/Mar/2017:03:38:36 /linux/performance-tuning/ethernet.html Unknown 30/Mar/2017:03:38:17 /technical/samsung-galaxy/linux.html US, United States 30/Mar/2017:03:37:46 /travel/turkey/temple-of-artemis/ US, United States 30/Mar/2017:03:37:38 /travel/usa/new-york-fictional-architecture/ Unknown 30/Mar/2017:03:37:31 / Unknown 30/Mar/2017:03:36:17 / FR, France 30/Mar/2017:03:36:14 /turkish/turkish-suffixes.html GB, United Kingdom 30/Mar/2017:03:35:38 /linux/linux-kernel.html CA, Canada 30/Mar/2017:03:35:06 / CA, Canada 30/Mar/2017:03:35:06 /radio/probes.html US, United States 30/Mar/2017:03:34:57 /technical/samsung-galaxy/cyanogenmod.html US, United States 30/Mar/2017:03:34:56 /3d/xray/ US, United States 30/Mar/2017:03:34:18 /radio/copper-wire/ SE, Sweden 30/Mar/2017:03:33:40 /linux/linux-break-in-howto.html US, United States 30/Mar/2017:03:32:51 /fun/brilliant-movie-ideas/no-worse.html FR, France 30/Mar/2017:03:32:17 /turkish/turkish-verbs.pdf Unknown 30/Mar/2017:03:32:08 /travel/trinidad/Index.html DE, Germany 30/Mar/2017:03:31:23 /3d/extrema.html NL, Netherlands 30/Mar/2017:03:29:54 /radio/power-meter.html US, United States 30/Mar/2017:03:29:38 /linux/kodi/ US, United States 30/Mar/2017:03:29:25 /travel/belgium/bastogne-ardennes/ US, United States 30/Mar/2017:03:29:21 / US, United States 30/Mar/2017:03:29:09 /travel/usa/new-york-revolutionary/catholic-worker.html US, United States 30/Mar/2017:03:29:06 /linux/qemu-unix.html IN, India 30/Mar/2017:03:28:51 /networking/commands.html US, United States 30/Mar/2017:03:28:42 /travel/greece/greek/lessons-001-005.html TR, Turkey 30/Mar/2017:03:28:13 /networking/ US, United States 30/Mar/2017:03:28:00 /travel/turkey/halicarnassus/ US, United States 30/Mar/2017:03:27:59 /robots.txt Unknown 30/Mar/2017:03:27:03 / Unknown 30/Mar/2017:03:27:03 /radio/probes.html GB, United Kingdom 30/Mar/2017:03:25:42 /travel/usa/new-york-jewish-les/grand-street.html DE, Germany 30/Mar/2017:03:25:28 /travel/usa/baltimore/ GB, United Kingdom 30/Mar/2017:03:24:50 /technical/samsung-galaxy/block-calls.html US, United States 30/Mar/2017:03:24:06 / US, United States 30/Mar/2017:03:24:01 /linux/performance-tuning/ethernet.html GB, United Kingdom 30/Mar/2017:03:23:39 /cybersecurity/password.html Unknown 30/Mar/2017:03:23:34 /technical/ Unknown 30/Mar/2017:03:23:08 /linux/linux-break-in-howto.html US, United States 30/Mar/2017:03:22:36 /travel/mexico/teotihuacan.html Unknown 30/Mar/2017:03:22:20 /technical/samsung-galaxy/secret-code.html US, United States 30/Mar/2017:03:22:02 /3d/xray/scanning.html GB, United Kingdom 30/Mar/2017:03:21:38 /travel/france/ronin/ US, United States 30/Mar/2017:03:21:22 /travel/uk/hadrians-wall/ US, United States 30/Mar/2017:03:20:54 / US, United States 30/Mar/2017:03:20:44 /cybersecurity/netusers/Index/ua Unknown 30/Mar/2017:03:20:32 / Unknown 30/Mar/2017:03:20:32 /radio/probes.html US, United States 30/Mar/2017:03:20:16 /travel/egypt/ US, United States 30/Mar/2017:03:18:52 /fun/latin.html IT, Italy 30/Mar/2017:03:18:30 /technical/samsung-galaxy/linux.html BG, Bulgaria 30/Mar/2017:03:18:13 /travel/belgium/bastogne-ardennes/houffalize-malmedy-st-hubert.html BG, Bulgaria 30/Mar/2017:03:18:12 /travel/belgium/bastogne-ardennes/

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, through are orange shifting to yellow, through are shades of green, the /16 networks through about are shades of blue, then it's shades of purple into magenta for the /24 networks and up through

The HTML file on the server has a line where PHP uses passthru() to call the following shell script:


# 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' |
		COUNTRY=$( geoiplookup $CLIENTIP |
				sed 's/.*Edition: //' |
				sed 's/IP Address not found/Unknown/' )
		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);

Other Pages