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. GB, United Kingdom 28/Jun/2017:05:34:02 /linux/performance-tuning/ GB, United Kingdom 28/Jun/2017:05:34:01 /travel/uk/ben-nevis/ US, United States 28/Jun/2017:05:34:00 /cybersecurity/netusers/data/cy GB, United Kingdom 28/Jun/2017:05:33:50 /networking/terminology.html GB, United Kingdom 28/Jun/2017:05:33:40 /networking/cisco-switch-repair/ FR, France 28/Jun/2017:05:33:30 /linux/migrate-rhel-to-centos.html GB, United Kingdom 28/Jun/2017:05:33:29 /networking/what-is-ipsec.html GB, United Kingdom 28/Jun/2017:05:33:19 /networking/class-a-nets.html GB, United Kingdom 28/Jun/2017:05:33:07 /cybersecurity/netusers/Index/ipk GB, United Kingdom 28/Jun/2017:05:32:56 /turkish/verbs.html GB, United Kingdom 28/Jun/2017:05:32:45 /networking/nat.html GB, United Kingdom 28/Jun/2017:05:32:33 /linux/openbsd-qemu-windows-howto.html GB, United Kingdom 28/Jun/2017:05:32:23 /travel/turkey/mountain-trek/ GB, United Kingdom 28/Jun/2017:05:32:12 /networking/netstat-s.html GB, United Kingdom 28/Jun/2017:05:32:01 /cybersecurity/netusers/Index/ IN, India 28/Jun/2017:05:32:00 /linux/performance-tuning/disks.html GB, United Kingdom 28/Jun/2017:05:31:50 /networking/cisco.html Unknown 28/Jun/2017:05:31:41 /russian/ GB, United Kingdom 28/Jun/2017:05:31:38 /technical/google-adsense-and-xhtml.html US, United States 28/Jun/2017:05:31:37 /turkish/verbs.html GB, United Kingdom 28/Jun/2017:05:31:26 /networking/wan-specs.html GB, United Kingdom 28/Jun/2017:05:31:15 /networking/vlan.html GB, United Kingdom 28/Jun/2017:05:31:02 /turkish/ GB, United Kingdom 28/Jun/2017:05:30:49 /cybersecurity/netusers/ US, United States 28/Jun/2017:05:30:44 /travel/athens-to-paris/athens-thessaloniki.html GB, United Kingdom 28/Jun/2017:05:30:38 /linux/openbsd-dell.html GB, United Kingdom 28/Jun/2017:05:30:27 /linux/ssh-2-access-control.html GB, United Kingdom 28/Jun/2017:05:30:26 /robots.txt US, United States 28/Jun/2017:05:30:25 /travel/athens-to-paris/ FR, France 28/Jun/2017:05:29:52 /linux/performance-tuning/disks.html US, United States 28/Jun/2017:05:29:40 /travel/greece/trains.html Unknown 28/Jun/2017:05:28:06 /travel/syria/aleppo.html SE, Sweden 28/Jun/2017:05:28:00 /travel/italy/driving.html US, United States 28/Jun/2017:05:27:47 /linux/thunderbird-default-browser.html IN, India 28/Jun/2017:05:27:44 /technical/hdmi.html NL, Netherlands 28/Jun/2017:05:27:44 /linux/thunderbird-default-browser.html Unknown 28/Jun/2017:05:27:19 /linux/performance-tuning/disks.html US, United States 28/Jun/2017:05:27:14 /russian/ US, United States 28/Jun/2017:05:27:13 /robots.txt US, United States 28/Jun/2017:05:27:11 /cybersecurity/crypto/culture.html US, United States 28/Jun/2017:05:27:10 /cybersecurity/history/uss-chaumont/photos-other.html US, United States 28/Jun/2017:05:27:08 /linux/raspberry-pi/ads-b-antenna.html US, United States 28/Jun/2017:05:27:07 /pubs.html US, United States 28/Jun/2017:05:27:05 /travel/Index.html US, United States 28/Jun/2017:05:26:46 /cybersecurity/netusers/Index/ni US, United States 28/Jun/2017:05:26:41 /cybersecurity/linux-hardening.html US, United States 28/Jun/2017:05:26:41 /cybersecurity/netusers/Index/ni US, United States 28/Jun/2017:05:26:38 /cybersecurity/netusers/Index/ni US, United States 28/Jun/2017:05:26:23 /linux/vmware-networking.html US, United States 28/Jun/2017:05:26:23 /robots.txt PL, Poland 28/Jun/2017:05:26:19 /linux/performance-tuning/disks.html US, United States 28/Jun/2017:05:26:11 /technical/samsung-galaxy/cyanogenmod.html US, United States 28/Jun/2017:05:26:10 /robots.txt US, United States 28/Jun/2017:05:26:09 /technical/samsung-galaxy/ssh.html US, United States 28/Jun/2017:05:26:09 /robots.txt Unknown 28/Jun/2017:05:25:55 /technical/dsl/ US, United States 28/Jun/2017:05:25:47 /linux/bluray.html US, United States 28/Jun/2017:05:25:47 /robots.txt US, United States 28/Jun/2017:05:25:45 /travel/athens-to-paris/ US, United States 28/Jun/2017:05:25:44 /travel/gsm-sim-card/ US, United States 28/Jun/2017:05:25:43 /robots.txt Unknown 28/Jun/2017:05:25:43 /travel/ Unknown 28/Jun/2017:05:25:43 /robots.txt US, United States 28/Jun/2017:05:25:42 /technical/bios.html US, United States 28/Jun/2017:05:25:27 /cybersecurity/netusers/data/la US, United States 28/Jun/2017:05:25:17 /linux/system-administration.html US, United States 28/Jun/2017:05:25:17 /robots.txt US, United States 28/Jun/2017:05:25:12 /linux/compiling-opencv-on-openbsd.html US, United States 28/Jun/2017:05:25:12 /robots.txt US, United States 28/Jun/2017:05:25:10 /linux/raspberry-pi/nas.html US, United States 28/Jun/2017:05:25:10 /robots.txt US, United States 28/Jun/2017:05:24:58 /linux/apache-referer-log-analysis.html US, United States 28/Jun/2017:05:24:58 /robots.txt Unknown 28/Jun/2017:05:24:57 / US, United States 28/Jun/2017:05:24:47 /linux/openbsd-wireless-wpa2.html US, United States 28/Jun/2017:05:24:46 /robots.txt US, United States 28/Jun/2017:05:24:26 /linux/linux-alpha.html US, United States 28/Jun/2017:05:24:26 /robots.txt US, United States 28/Jun/2017:05:24:22 /linux/package-management.html US, United States 28/Jun/2017:05:24:22 /robots.txt US, United States 28/Jun/2017:05:24:05 /linux/qemu-unix.html US, United States 28/Jun/2017:05:24:05 /robots.txt US, United States 28/Jun/2017:05:23:47 /linux/samba-active-directory/ US, United States 28/Jun/2017:05:23:45 /robots.txt US, United States 28/Jun/2017:05:22:43 /cybersecurity/linux-hardening.html US, United States 28/Jun/2017:05:22:42 /robots.txt DE, Germany 28/Jun/2017:05:22:25 /networking/cisco.html US, United States 28/Jun/2017:05:20:10 /linux/openbsd-qemu-windows-howto.html IT, Italy 28/Jun/2017:05:20:05 /linux/sendmail-ssl.html US, United States 28/Jun/2017:05:19:42 /travel/turkey/aphrodisias/ US, United States 28/Jun/2017:05:19:31 /radio/fort-tuthill.html RU, Russian Federation 28/Jun/2017:05:19:17 /travel/athens-to-paris/ US, United States 28/Jun/2017:05:19:11 /linux/performance-tuning/ US, United States 28/Jun/2017:05:19:11 /linux/performance-tuning/ Unknown 28/Jun/2017:05:19:09 /linux/performance-tuning/ Unknown 28/Jun/2017:05:19:05 /travel/uk/ben-nevis/ US, United States 28/Jun/2017:05:18:46 /linux/file-system.html US, United States 28/Jun/2017:05:18:45 /linux/file-system.html Unknown 28/Jun/2017:05:18:43 /linux/file-system.html IL, Israel 28/Jun/2017:05:18:43 /cybersecurity/authentication.html US, United States 28/Jun/2017:05:18:31 /cybersecurity/comptia/ US, United States 28/Jun/2017:05:18:31 /robots.txt RU, Russian Federation 28/Jun/2017:05:18:30 /travel/bulgaria/veliko-tarnovo/ US, United States 28/Jun/2017:05:18:28 /cybersecurity/comptia/ US, United States 28/Jun/2017:05:18:16 /travel/usa/new-york-internet/ US, United States 28/Jun/2017:05:17:37 /fun/foxnews-search2.html SE, Sweden 28/Jun/2017:05:17:36 /linux/rhel-centos-5-6-7/ US, United States 28/Jun/2017:05:17:19 /robots.txt US, United States 28/Jun/2017:05:16:39 /3d/clsi/ US, United States 28/Jun/2017:05:16:08 /travel/belgium/belgian-beers/a-la-becasse.html DE, Germany 28/Jun/2017:05:15:49 /turkish/language-reform.html US, United States 28/Jun/2017:05:15:23 /cybersecurity/netusers/ssi/?N=D Unknown 28/Jun/2017:05:15:16 /technical/ US, United States 28/Jun/2017:05:15:10 /radio/hf-short-dipoles.html US, United States 28/Jun/2017:05:15:09 /cybersecurity/netusers/Index/to RU, Russian Federation 28/Jun/2017:05:15:06 /sitemap.txt US, United States 28/Jun/2017:05:15:01 /cybersecurity/netusers/Index/co Unknown 28/Jun/2017:05:14:54 /linux/openbsd-qemu-windows-howto.html US, United States 28/Jun/2017:05:14:35 /linux/multiboot-windows-openbsd/Index.html US, United States 28/Jun/2017:05:14:24 /linux/multiboot-windows-openbsd/Index.html GB, United Kingdom 28/Jun/2017:05:14:15 /linux/kodi/ US, United States 28/Jun/2017:05:14:15 /travel/france/boat-trip-canal-lateral-a-la-loire/briare.html IT, Italy 28/Jun/2017:05:14:12 /linux/performance-tuning/nfs.html US, United States 28/Jun/2017:05:13:38 /travel/turkey/temple-of-artemis/ Unknown 28/Jun/2017:05:13:38 / US, United States 28/Jun/2017:05:13:37 /travel/uk/glastonbury/ Unknown 28/Jun/2017:05:13:37 /radio/probes.html US, United States 28/Jun/2017:05:13:29 /travel/turkey/temple-of-artemis/ CZ, Czech Republic 28/Jun/2017:05:12:42 /robots.txt DE, Germany 28/Jun/2017:05:12:09 / DE, Germany 28/Jun/2017:05:12:09 / US, United States 28/Jun/2017:05:11:59 / US, United States 28/Jun/2017:05:11:58 /radio/probes.html US, United States 28/Jun/2017:05:11:27 /travel/turkey/temple-of-artemis/ US, United States 28/Jun/2017:05:11:27 /linux/kodi/ Unknown 28/Jun/2017:05:11:26 /travel/greece/greek-islands.html US, United States 28/Jun/2017:05:10:52 /cybersecurity/linux-hardening.html US, United States 28/Jun/2017:05:10:47 /linux/linux-commands.html AU, Australia 28/Jun/2017:05:10:30 /cybersecurity/password-breaking.html US, United States 28/Jun/2017:05:10:24 /turkish/verbs.html AU, Australia 28/Jun/2017:05:10:18 /cybersecurity/password.html Unknown 28/Jun/2017:05:10:03 /travel/france/ US, United States 28/Jun/2017:05:09:54 /travel/uk/glastonbury/town.html US, United States 28/Jun/2017:05:09:29 /travel/uk/skara-brae/ Unknown 28/Jun/2017:05:08:27 /cybersecurity/public-key.html Unknown 28/Jun/2017:05:08:26 /turkish/ Unknown 28/Jun/2017:05:08:25 /travel/ Unknown 28/Jun/2017:05:08:25 /technical/ Unknown 28/Jun/2017:05:08:23 /russian/ Unknown 28/Jun/2017:05:08:23 /radio/ SE, Sweden 28/Jun/2017:05:08:22 /linux/linux-boot.html GB, United Kingdom 28/Jun/2017:05:08:22 /cybersecurity/history/uss-chaumont/photos-lettersetc.html Unknown 28/Jun/2017:05:08:21 /networking/ Unknown 28/Jun/2017:05:08:20 /linux/ Unknown 28/Jun/2017:05:08:17 /fun/ Unknown 28/Jun/2017:05:08:17 /cybersecurity/root-password.html Unknown 28/Jun/2017:05:08:16 /cybersecurity/privacy-policy.html Unknown 28/Jun/2017:05:08:15 /cybersecurity/ Unknown 28/Jun/2017:05:08:14 /3d/ Unknown 28/Jun/2017:05:08:13 /pubs.html Unknown 28/Jun/2017:05:08:11 /site-map.html Unknown 28/Jun/2017:05:08:10 /contact.html Unknown 28/Jun/2017:05:08:10 / US, United States 28/Jun/2017:05:08:05 /fun/rick-mount-purdue.html Unknown 28/Jun/2017:05:07:24 /linux/performance-tuning/file-systems.html Unknown 28/Jun/2017:05:06:23 /3d/histogram/ US, United States 28/Jun/2017:05:05:56 /technical/samsung-galaxy/screenshot.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, 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