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 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.

54.92.174.226 US, United States 19/Aug/2018:10:00:35 /travel/greece/greek-mainland.html
54.92.174.226 US, United States 19/Aug/2018:10:00:33 /cybersecurity/hostile/stration.html
54.92.174.226 US, United States 19/Aug/2018:10:00:31 /technical/svga.html
54.92.174.226 US, United States 19/Aug/2018:10:00:29 /travel/belgium/belgian-beers/a-la-becasse.html
54.92.174.226 US, United States 19/Aug/2018:10:00:27 /travel/bulgaria/food/Index.html
54.92.174.226 US, United States 19/Aug/2018:10:00:25 /open-source/build-packages.html
54.92.174.226 US, United States 19/Aug/2018:10:00:23 /open-source/google-freebsd-tls/apache-log-cache.html
54.92.174.226 US, United States 19/Aug/2018:10:00:21 /travel/usa/new-york-st-marks-place/2nd-1st-north.html
54.92.174.226 US, United States 19/Aug/2018:10:00:19 /fun/teaching/math-trouble.html
54.92.174.226 US, United States 19/Aug/2018:10:00:17 /travel/france/budget-hotels/Index.html
54.92.174.226 US, United States 19/Aug/2018:10:00:13 /fun/brilliant-movie-ideas/beaver.html
54.92.174.226 US, United States 19/Aug/2018:10:00:11 /travel/japan/shinto-buddhism/buddhism.html
54.92.174.226 US, United States 19/Aug/2018:10:00:09 /cybersecurity/history/uk-wwii.html
54.92.174.226 US, United States 19/Aug/2018:10:00:07 /radio/mwdx.html
54.92.174.226 US, United States 19/Aug/2018:10:00:05 /open-source/unix-tips.html
54.92.174.226 US, United States 19/Aug/2018:10:00:03 /travel/turkey/ephesus/Index.html
54.92.174.226 US, United States 19/Aug/2018:10:00:01 /travel/egypt/aswan.html
54.92.174.226 US, United States 19/Aug/2018:09:59:59 /technical/quickdisk-recovery.html
54.92.174.226 US, United States 19/Aug/2018:09:59:58 /technical/samsung-galaxy/linux.html
54.92.174.226 US, United States 19/Aug/2018:09:59:56 /radio/hf-short-dipoles.html
54.92.174.226 US, United States 19/Aug/2018:09:59:53 /travel/usa/new-york-st-marks-place/3rd-2nd-south.html
54.92.174.226 US, United States 19/Aug/2018:09:59:51 /travel/france/boat-trip-canal-lateral-a-la-loire/st-thibault-to-la-chapelle-montlinard.html
54.92.174.226 US, United States 19/Aug/2018:09:59:50 /turkish/background.html
54.92.174.226 US, United States 19/Aug/2018:09:59:48 /travel/usa/new-york-sro-flophouses/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:59:46 /open-source/openbsd-kernel.html
54.92.174.226 US, United States 19/Aug/2018:09:59:44 /travel/japan/tokyo-asakusa/senso-ji.html
54.92.174.226 US, United States 19/Aug/2018:09:59:42 /travel/china/yangshuo.html
54.92.174.226 US, United States 19/Aug/2018:09:59:40 /open-source/performance-tuning/tcp.html
54.92.174.226 US, United States 19/Aug/2018:09:59:38 /travel/turkey/konya/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:59:35 /cybersecurity/crypto/hash-search.html
54.92.174.226 US, United States 19/Aug/2018:09:59:34 /travel/usa/new-york-nighthawks/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:59:32 /travel/uk/glen-nevis/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:59:30 /travel/athens-to-paris/thessaloniki-sofia.html
54.92.174.226 US, United States 19/Aug/2018:09:59:28 /travel/uk/glastonbury/holy-grail.html
118.211.210.194 AU, Australia 19/Aug/2018:09:59:27 /travel/france/boat/canal-selection-and-logs.html
54.92.174.226 US, United States 19/Aug/2018:09:59:26 /cybersecurity/badguys.html
70.173.27.150 US, United States 19/Aug/2018:09:59:26 /open-source/sendmail-ssl.html
54.92.174.226 US, United States 19/Aug/2018:09:59:22 /fun/brilliant-movie-ideas/deja-viewed.html
54.92.174.226 US, United States 19/Aug/2018:09:59:20 /travel/turkey/food/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:59:18 /open-source/samba-active-directory/freebsd-raspberry-pi.html
54.92.174.226 US, United States 19/Aug/2018:09:59:16 /technical/samsung-galaxy/insufficient-storage.html
54.92.174.226 US, United States 19/Aug/2018:09:59:14 /cybersecurity/attack-study/attacker-perspective.html
54.92.174.226 US, United States 19/Aug/2018:09:59:12 /open-source/rhel-centos-5-6-7/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:59:10 /open-source/letsencrypt-tls-cert-godaddy.html
54.92.174.226 US, United States 19/Aug/2018:09:59:08 /travel/china/logistics-and-language.html
54.92.174.226 US, United States 19/Aug/2018:09:59:06 /open-source/package-management.html
54.92.174.226 US, United States 19/Aug/2018:09:59:04 /fun/writing-thoughts.html
144.202.193.40 US, United States 19/Aug/2018:09:59:02 /travel/uk/ben-nevis/
54.92.174.226 US, United States 19/Aug/2018:09:59:02 /travel/usa/north-carolina/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:59:00 /technical/convert-youtube-to-xvid.html
54.92.174.226 US, United States 19/Aug/2018:09:58:58 /travel/usa/montgomery-alabama/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:56 /travel/belgium/comic-book-art/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:54 /travel/japan/kamakura/jochi-ji.html
54.92.174.226 US, United States 19/Aug/2018:09:58:52 /travel/turkey/trains/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:50 /cybersecurity/cyberwar.html
54.92.174.226 US, United States 19/Aug/2018:09:58:48 /fun/requests-for-quotes/bahrain/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:46 /fun/requests-for-quotes/manila-booklift/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:44 /cybersecurity/pki-failures.html
54.92.174.226 US, United States 19/Aug/2018:09:58:42 /radio/copper-wire/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:41 /open-source/raspberry-pi/sdr-ads-b-flight-tracking.html
54.92.174.226 US, United States 19/Aug/2018:09:58:39 /travel/usa/new-york-skate-manhattan/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:37 /cybersecurity/syslog-tls-cloud.html
54.92.174.226 US, United States 19/Aug/2018:09:58:35 /open-source/ssh-1-admin.html
54.92.174.226 US, United States 19/Aug/2018:09:58:33 /open-source/apache-referer-log-analysis.html
54.92.174.226 US, United States 19/Aug/2018:09:58:31 /resume/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:29 /cybersecurity/cipher-selection.html
2.87.45.78 GR, Greece 19/Aug/2018:09:58:28 /travel/athens-to-paris/
54.92.174.226 US, United States 19/Aug/2018:09:58:27 /open-source/canon-pixma-printer-scanner.html
54.92.174.226 US, United States 19/Aug/2018:09:58:25 /brewing/brewing-links.html
54.92.174.226 US, United States 19/Aug/2018:09:58:23 /technical/search-engine-optimization-howto.html
54.92.174.226 US, United States 19/Aug/2018:09:58:21 /travel/turkey/lycia/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:19 /travel/france/electricity/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:17 /3d/range-maps.html
54.92.174.226 US, United States 19/Aug/2018:09:58:15 /travel/usa/new-york-phone-booths/Index.html
173.239.219.11 US, United States 19/Aug/2018:09:58:15 /travel/turkey/ephesus/walk.html
54.92.174.226 US, United States 19/Aug/2018:09:58:13 /travel/japan/kamakura/tokei-ji.html
54.92.174.226 US, United States 19/Aug/2018:09:58:11 /3d/sensor-design.html
54.92.174.226 US, United States 19/Aug/2018:09:58:09 /cybersecurity/attack-study/200.213.105.90-i192-list.html
54.92.174.226 US, United States 19/Aug/2018:09:58:07 /networking/wan-specs.html
54.92.174.226 US, United States 19/Aug/2018:09:58:05 /travel/france/mont-saint-michel-saint-malo/Index.html
54.92.174.226 US, United States 19/Aug/2018:09:58:04 /travel/greece/trains.html
54.92.174.226 US, United States 19/Aug/2018:09:58:02 /3d/raytrace/fishray.html
54.92.174.226 US, United States 19/Aug/2018:09:57:58 /networking/wlan-specs.html
54.92.174.226 US, United States 19/Aug/2018:09:57:56 /networking/cisco.html
54.92.174.226 US, United States 19/Aug/2018:09:57:54 /open-source/qemu-unix.html
54.92.174.226 US, United States 19/Aug/2018:09:57:52 /open-source/xsane-invalid-argument.html
54.92.174.226 US, United States 19/Aug/2018:09:57:50 /travel/belgium/belgian-beers/absinthe-bar.html
54.92.174.226 US, United States 19/Aug/2018:09:57:50 /robots.txt
70.173.27.150 US, United States 19/Aug/2018:09:57:47 /open-source/sendmail-ssl.html
46.229.168.69 US, United States 19/Aug/2018:09:57:31 /cybersecurity/
46.229.168.75 US, United States 19/Aug/2018:09:57:29 /robots.txt
118.211.210.194 AU, Australia 19/Aug/2018:09:57:08 /travel/france/boat/
185.69.145.78 GB, United Kingdom 19/Aug/2018:09:57:04 /russian/grammar.html
5.255.250.17 US, United States 19/Aug/2018:09:56:54 /open-source/canon-pixma-printer-scanner.html
123.125.67.222 CN, China 19/Aug/2018:09:56:48 /
202.106.159.120 CN, China 19/Aug/2018:09:56:39 /
157.55.39.211 US, United States 19/Aug/2018:09:56:10 /russian/latex.html
40.77.167.102 US, United States 19/Aug/2018:09:55:45 /travel/belgium/bastogne-ardennes/ardennes-forest.html
103.214.13.2 PH, Philippines 19/Aug/2018:09:54:54 /radio/rhombic-antennas.html
89.205.125.217 MK, Macedonia 19/Aug/2018:09:54:13 /
94.130.134.200 DE, Germany 19/Aug/2018:09:53:32 /open-source/raspberry-pi/openvas.html
87.255.2.144 RU, Russian Federation 19/Aug/2018:09:53:26 /open-source/raspberry-pi/openvas.html
103.27.162.202 AP, Asia/Pacific Region 19/Aug/2018:09:53:22 /open-source/performance-tuning/nfs.html
144.202.193.40 US, United States 19/Aug/2018:09:53:11 /networking/wlan-specs.html
64.140.135.1 US, United States 19/Aug/2018:09:52:18 /
144.202.193.40 US, United States 19/Aug/2018:09:51:31 /technical/samsung-galaxy/rip-cyanogenmod.html
95.163.255.176 RU, Russian Federation 19/Aug/2018:09:51:12 /robots.txt
217.73.208.144 IT, Italy 19/Aug/2018:09:49:28 /robots.txt
144.202.193.40 US, United States 19/Aug/2018:09:49:18 /travel/egypt/
73.194.146.25 US, United States 19/Aug/2018:09:49:01 /travel/usa/new-york-jewish-les/stanton-rivington.html
101.87.63.96 CN, China 19/Aug/2018:09:48:41 /open-source/performance-tuning/tcp.html
185.69.145.78 GB, United Kingdom 19/Aug/2018:09:48:22 /russian/grammar.html
141.212.122.112 US, United States 19/Aug/2018:09:48:12 /
17.58.102.12 US, United States 19/Aug/2018:09:47:45 /travel/uk/skara-brae/
174.203.13.24 US, United States 19/Aug/2018:09:47:37 /travel/usa/new-york-lga-arrival/
91.65.15.24 DE, Germany 19/Aug/2018:09:47:19 /technical/samsung-galaxy/linux.html
198.108.66.32 US, United States 19/Aug/2018:09:45:59 /
5.255.250.17 US, United States 19/Aug/2018:09:45:19 /open-source/rhel-centos-5-6-7/packages-and-software.html
81.247.130.157 BE, Belgium 19/Aug/2018:09:44:27 /travel/belgium/bastogne-ardennes/ardennes-forest.html
91.252.74.224 IT, Italy 19/Aug/2018:09:43:12 /travel/greece/trains.html
137.226.113.28 DE, Germany 19/Aug/2018:09:41:41 /
5.255.250.17 US, United States 19/Aug/2018:09:40:53 /russian/grammar.html
47.15.151.227 IN, India 19/Aug/2018:09:40:01 /open-source/performance-tuning/disks.html
86.136.144.27 GB, United Kingdom 19/Aug/2018:09:39:46 /travel/italy/driving.html
66.102.6.181 US, United States 19/Aug/2018:09:38:18 /technical/convert-youtube-to-xvid.html
144.202.193.40 US, United States 19/Aug/2018:09:35:31 /open-source/stig-compliance.html
54.36.148.167 FR, France 19/Aug/2018:09:35:23 /travel/belgium/belgian-beers/a-la-becasse.html
212.2.212.10 TR, Turkey 19/Aug/2018:09:34:59 /travel/turkey/olimpos/
17.58.102.12 US, United States 19/Aug/2018:09:33:44 /travel/usa/new-york-internet/
17.58.102.12 US, United States 19/Aug/2018:09:33:44 /robots.txt
17.58.102.12 US, United States 19/Aug/2018:09:33:44 /robots.txt
17.58.102.12 US, United States 19/Aug/2018:09:33:44 /robots.txt
84.136.114.40 DE, Germany 19/Aug/2018:09:33:33 /open-source/raspberry-pi/sdr-ads-b-piaware-and-fr24feed.html
5.45.137.24 JO, Jordan 19/Aug/2018:09:32:38 /turkish/turkish-verbs.pdf
46.229.168.79 US, United States 19/Aug/2018:09:32:25 /travel/usa/new-york-revolutionary/anarchists.html
95.215.164.62 UA, Ukraine 19/Aug/2018:09:32:13 /oliver-cromwell/
5.255.250.17 US, United States 19/Aug/2018:09:31:35 /cybersecurity/root-password.html
5.255.250.17 US, United States 19/Aug/2018:09:30:25 /open-source/samba-active-directory/samba.html
46.229.168.72 US, United States 19/Aug/2018:09:30:06 /cybersecurity/refs.html
144.202.193.40 US, United States 19/Aug/2018:09:28:32 /travel/usa/new-york-andy-warhol/

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-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