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 24/Jan/2017:11:14:23 /cybersecurity/physical.html US, United States 24/Jan/2017:11:14:17 /linux/virtualbox-build.html US, United States 24/Jan/2017:11:14:16 /travel/usa/new-york-mudd-club/Index.html US, United States 24/Jan/2017:11:14:10 /cybersecurity/netusers/Index/bq US, United States 24/Jan/2017:11:14:09 /robots.txt US, United States 24/Jan/2017:11:14:03 /technical/html4-or-xhtml-to-html5.html US, United States 24/Jan/2017:11:14:03 /technical/html4-or-xhtml-to-html5.html PT, Portugal 24/Jan/2017:11:14:01 /technical/html4-or-xhtml-to-html5.html FR, France 24/Jan/2017:11:13:59 / FR, France 24/Jan/2017:11:13:58 /radio/probes.html ES, Spain 24/Jan/2017:11:13:53 /turkish/language-reform.html US, United States 24/Jan/2017:11:13:44 /linux/sysfs.html BR, Brazil 24/Jan/2017:11:13:44 /cybersecurity/netusers/data/pt US, United States 24/Jan/2017:11:13:42 /cybersecurity/ec2-secure-storage.html Unknown 24/Jan/2017:11:13:28 /travel/usa/us-wash-masonic.html NL, Netherlands 24/Jan/2017:11:13:17 /linux/performance-tuning/disks.html ES, Spain 24/Jan/2017:11:12:42 /turkish/word-order.html DE, Germany 24/Jan/2017:11:12:37 /cybersecurity/linux-hardening.html US, United States 24/Jan/2017:11:12:05 /linux/linux-alpha.html US, United States 24/Jan/2017:11:12:04 /robots.txt Unknown 24/Jan/2017:11:11:37 /networking/protocols.html Unknown 24/Jan/2017:11:11:24 /travel/usa/us-wash-masonic.html Unknown 24/Jan/2017:11:10:50 /technical/samsung-galaxy/cyanogenmod.html US, United States 24/Jan/2017:11:10:48 / US, United States 24/Jan/2017:11:10:13 /3d/histogram/ US, United States 24/Jan/2017:11:09:43 /fun/requests-for-quotes/tongan-misdirection/ CZ, Czech Republic 24/Jan/2017:11:08:46 /technical/ata-ide-sata-usb-cable-pinouts.html US, United States 24/Jan/2017:11:08:32 /russian/grammar.html ET, Ethiopia 24/Jan/2017:11:07:04 /technical/ata-ide-sata-usb-cable-pinouts.html US, United States 24/Jan/2017:11:06:48 /cybersecurity/password.html Unknown 24/Jan/2017:11:05:57 /cybersecurity/root-password.html US, United States 24/Jan/2017:11:05:56 /travel/usa/north-carolina/ MY, Malaysia 24/Jan/2017:11:05:35 /technical/dsl/ Unknown 24/Jan/2017:11:04:52 /cybersecurity/ Unknown 24/Jan/2017:11:04:22 /cybersecurity/monitoring.html CN, China 24/Jan/2017:11:04:21 /robots.txt US, United States 24/Jan/2017:11:04:20 / US, United States 24/Jan/2017:11:04:07 /brewing/brewing-references.html Unknown 24/Jan/2017:11:03:42 / Unknown 24/Jan/2017:11:03:42 /radio/probes.html US, United States 24/Jan/2017:11:03:05 /linux/digital-camera.html US, United States 24/Jan/2017:11:01:45 /technical/samsung-galaxy/secret-code.html CN, China 24/Jan/2017:11:01:37 /linux/openbsd-qemu-windows-howto.html US, United States 24/Jan/2017:11:01:04 /travel/greece/mycenae.html Unknown 24/Jan/2017:11:00:58 /travel/uk/dover/ Unknown 24/Jan/2017:10:59:57 /technical/samsung-galaxy/block-calls.html CN, China 24/Jan/2017:10:59:13 /linux/openbsd-qemu-windows-howto.html GB, United Kingdom 24/Jan/2017:10:59:08 /cybersecurity/netusers/Index/sa US, United States 24/Jan/2017:10:58:59 /travel/egypt/luxor.html US, United States 24/Jan/2017:10:58:22 /linux/rhel-centos-5-6-7/ US, United States 24/Jan/2017:10:58:21 /linux/rhel-centos-5-6-7/ DE, Germany 24/Jan/2017:10:58:08 /oliver-cromwell/crom-fu-fighting.html NL, Netherlands 24/Jan/2017:10:58:06 / DE, Germany 24/Jan/2017:10:57:51 /linux/rhel-centos-multimedia.html MX, Mexico 24/Jan/2017:10:57:40 /cybersecurity/forensics.html US, United States 24/Jan/2017:10:57:07 /travel/france/normandy/pegasus-bridge.html Unknown 24/Jan/2017:10:56:23 / US, United States 24/Jan/2017:10:56:12 /technical/convert-youtube-to-xvid.html Unknown 24/Jan/2017:10:55:57 / DE, Germany 24/Jan/2017:10:55:46 /oliver-cromwell/crom-fu-fighting.html US, United States 24/Jan/2017:10:55:26 /3d/xray/film.html DE, Germany 24/Jan/2017:10:55:25 /oliver-cromwell/crom-fu-fighting.html US, United States 24/Jan/2017:10:55:09 /cybersecurity/netusers/Index/sa US, United States 24/Jan/2017:10:55:07 /cybersecurity/netusers/Index/sa US, United States 24/Jan/2017:10:55:05 /cybersecurity/netusers/Index/sa US, United States 24/Jan/2017:10:55:05 /cybersecurity/netusers/Index/sa US, United States 24/Jan/2017:10:55:04 /cybersecurity/netusers/Index/sa US, United States 24/Jan/2017:10:55:03 /cybersecurity/netusers/Index/sa US, United States 24/Jan/2017:10:55:03 / US, United States 24/Jan/2017:10:55:02 /cybersecurity/netusers/Index/sa US, United States 24/Jan/2017:10:54:48 /oliver-cromwell/crom-fu-fighting.html DE, Germany 24/Jan/2017:10:54:43 /oliver-cromwell/crom-fu-fighting.html US, United States 24/Jan/2017:10:54:37 /3d/xray/scanning.html US, United States 24/Jan/2017:10:54:33 /linux/windows-path.html VN, Vietnam 24/Jan/2017:10:54:07 /linux/openbsd-qemu-windows-howto.html VN, Vietnam 24/Jan/2017:10:54:05 / VN, Vietnam 24/Jan/2017:10:54:03 /robots.txt US, United States 24/Jan/2017:10:53:39 /linux/rhel-centos-5-6-7/ PL, Poland 24/Jan/2017:10:53:13 / PL, Poland 24/Jan/2017:10:53:13 /radio/probes.html US, United States 24/Jan/2017:10:52:59 / DE, Germany 24/Jan/2017:10:52:51 /linux/rhel-centos-multimedia.html US, United States 24/Jan/2017:10:52:29 /travel/poland/ Unknown 24/Jan/2017:10:52:09 /travel/usa/us-wash-masonic.html US, United States 24/Jan/2017:10:52:04 / US, United States 24/Jan/2017:10:51:50 /networking/ EE, Estonia 24/Jan/2017:10:51:29 /cybersecurity/hacker-passwords.html FR, France 24/Jan/2017:10:51:27 /travel/belgium/art-nouveau-architecture/ US, United States 24/Jan/2017:10:51:20 /technical/dct-2000.html IN, India 24/Jan/2017:10:51:05 / IN, India 24/Jan/2017:10:51:04 /radio/probes.html FR, France 24/Jan/2017:10:50:42 /travel/belgium/art-nouveau-architecture/ DE, Germany 24/Jan/2017:10:50:40 /travel/belgium/art-nouveau-architecture/ US, United States 24/Jan/2017:10:50:35 /technical/dsl/ FR, France 24/Jan/2017:10:50:35 /travel/belgium/art-nouveau-architecture/ US, United States 24/Jan/2017:10:49:20 /cybersecurity/privacy-policy.html FR, France 24/Jan/2017:10:49:01 /russian/grammar.html US, United States 24/Jan/2017:10:48:39 /cybersecurity/history/uk-wwii.html US, United States 24/Jan/2017:10:47:13 /cybersecurity/ Unknown 24/Jan/2017:10:47:06 /cybersecurity/ US, United States 24/Jan/2017:10:46:38 /travel/turkey/trains/ US, United States 24/Jan/2017:10:46:34 /travel/turkey/trains/ US, United States 24/Jan/2017:10:46:33 /robots.txt US, United States 24/Jan/2017:10:46:32 /travel/turkey/trains/ US, United States 24/Jan/2017:10:46:32 /travel/turkey/trains/ US, United States 24/Jan/2017:10:46:29 /travel/turkey/trains/ US, United States 24/Jan/2017:10:44:43 /travel/poland/ US, United States 24/Jan/2017:10:44:13 /turkish/turkish-suffixes.html US, United States 24/Jan/2017:10:44:11 /3d/ US, United States 24/Jan/2017:10:44:10 /robots.txt Unknown 24/Jan/2017:10:42:36 / Unknown 24/Jan/2017:10:42:34 /radio/probes.html CN, China 24/Jan/2017:10:42:24 /robots.txt US, United States 24/Jan/2017:10:41:37 /travel/belgium/art-nouveau-architecture/ US, United States 24/Jan/2017:10:41:28 /linux/system-administration.html US, United States 24/Jan/2017:10:41:27 /linux/system-administration.html CN, China 24/Jan/2017:10:41:22 /travel/uk/swingate-chain-home/ UA, Ukraine 24/Jan/2017:10:41:09 /radio/probes.html US, United States 24/Jan/2017:10:40:53 /3d/xray/ IN, India 24/Jan/2017:10:40:51 / IN, India 24/Jan/2017:10:40:50 /radio/probes.html BG, Bulgaria 24/Jan/2017:10:40:20 /technical/ata-ide-sata-usb-cable-pinouts.html US, United States 24/Jan/2017:10:39:39 /cybersecurity/hardware.html Unknown 24/Jan/2017:10:39:29 / US, United States 24/Jan/2017:10:39:13 /robots.txt Unknown 24/Jan/2017:10:39:08 / Unknown 24/Jan/2017:10:39:07 /radio/probes.html Unknown 24/Jan/2017:10:38:28 / US, United States 24/Jan/2017:10:38:12 /3d/xray/film.html US, United States 24/Jan/2017:10:38:11 /travel/turkey/ US, United States 24/Jan/2017:10:38:10 /travel/turkey/ Unknown 24/Jan/2017:10:37:59 /turkish/verbs.html CZ, Czech Republic 24/Jan/2017:10:37:37 /linux/openbsd-qemu-windows-howto.html Unknown 24/Jan/2017:10:36:48 /robots.txt Unknown 24/Jan/2017:10:36:45 /linux/openbsd-wireless-wpa2.html US, United States 24/Jan/2017:10:36:45 /networking/wan-specs.html US, United States 24/Jan/2017:10:35:53 /technical/ US, United States 24/Jan/2017:10:35:34 /networking/nat.html AR, Argentina 24/Jan/2017:10:35:06 /linux/performance-tuning/nfs.html CA, Canada 24/Jan/2017:10:32:53 / CA, Canada 24/Jan/2017:10:32:52 /radio/probes.html US, United States 24/Jan/2017:10:32:51 /travel/usa/philadelphia/ CN, China 24/Jan/2017:10:32:30 /travel/uk/swingate-chain-home/ US, United States 24/Jan/2017:10:32:20 /cybersecurity/root-password.html US, United States 24/Jan/2017:10:31:53 /cybersecurity/stack-hardening.html DE, Germany 24/Jan/2017:10:31:46 /linux/performance-tuning/file-systems.html IL, Israel 24/Jan/2017:10:31:41 /linux/performance-tuning/file-systems.html CN, China 24/Jan/2017:10:31:26 /technical/samsung-galaxy/linux.html CH, Switzerland 24/Jan/2017:10:31:20 /networking/what-is-ipsec.html US, United States 24/Jan/2017:10:31:17 /travel/france/thomas-jefferson/ US, United States 24/Jan/2017:10:31:16 /travel/france/thomas-jefferson/ Unknown 24/Jan/2017:10:31:15 /travel/france/thomas-jefferson/ CN, China 24/Jan/2017:10:31:04 / US, United States 24/Jan/2017:10:30:19 /cybersecurity/netaudit.html IT, Italy 24/Jan/2017:10:30:02 /radio/hf-short-dipoles.html DE, Germany 24/Jan/2017:10:29:55 /

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