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 27/Sep/2016:14:11:43 /technical/Index.html RO, Romania 27/Sep/2016:14:11:42 /radio/nc2030-qrp-transceiver/ TR, Turkey 27/Sep/2016:14:11:36 /turkish/turkish-verbs.pdf Unknown 27/Sep/2016:14:11:28 /linux/sendmail-ssl.html RO, Romania 27/Sep/2016:14:11:22 /radio/hfqrp.html RU, Russian Federation 27/Sep/2016:14:11:10 / RU, Russian Federation 27/Sep/2016:14:11:10 / RU, Russian Federation 27/Sep/2016:14:11:09 / US, United States 27/Sep/2016:14:11:07 /travel/usa/new-york-fictional-architecture/greenwich-village.html HU, Hungary 27/Sep/2016:14:10:26 /technical/samsung-galaxy/linux.html GB, United Kingdom 27/Sep/2016:14:10:19 / Unknown 27/Sep/2016:14:09:46 /turkish/verbs.html US, United States 27/Sep/2016:14:08:39 /linux/openbsd-qemu-windows-howto.html US, United States 27/Sep/2016:14:08:31 /travel/uk/ben-nevis/Index.html US, United States 27/Sep/2016:14:08:30 /robots.txt US, United States 27/Sep/2016:14:08:24 /travel/uk/the-road-to-the-isles/luibeilt-steall.html DK, Denmark 27/Sep/2016:14:08:13 /travel/usa/new-york-mcgees/ US, United States 27/Sep/2016:14:08:10 /travel/usa/new-york-mcgees/Index.html US, United States 27/Sep/2016:14:07:56 /travel/egypt/ US, United States 27/Sep/2016:14:07:54 /robots.txt US, United States 27/Sep/2016:14:07:12 /travel/belgium/belgian-beers/ US, United States 27/Sep/2016:14:06:59 /travel/uk/dover/ US, United States 27/Sep/2016:14:06:59 /linux/openbsd-qemu-windows-howto.html US, United States 27/Sep/2016:14:06:45 /technical/html4-or-xhtml-to-html5.html CA, Canada 27/Sep/2016:14:06:37 /technical/samsung-galaxy/linux.html Unknown 27/Sep/2016:14:06:36 / Unknown 27/Sep/2016:14:06:04 /linux/performance-tuning/nfs.html US, United States 27/Sep/2016:14:05:32 /turkish/nouns.html US, United States 27/Sep/2016:14:04:43 /travel/greece/tiryns.html Unknown 27/Sep/2016:14:04:40 /turkish/verbs.html US, United States 27/Sep/2016:14:04:32 /oliver-cromwell/ US, United States 27/Sep/2016:14:04:02 /linux/performance-tuning/disks.html US, United States 27/Sep/2016:14:03:56 /technical/dsl/ US, United States 27/Sep/2016:14:03:44 /travel/france/seine-river-art-history-monet/haute-isle.html US, United States 27/Sep/2016:14:03:37 /travel/france/seine-river-art-history-monet/haute-isle.html Unknown 27/Sep/2016:14:03:35 /linux/crashdumps.html FR, France 27/Sep/2016:14:03:34 /travel/france/seine-river-art-history-monet/haute-isle.html US, United States 27/Sep/2016:14:03:28 /wshta/ US, United States 27/Sep/2016:14:03:16 /travel/italy/napoli/ US, United States 27/Sep/2016:14:03:10 /travel/italy/napoli/ Unknown 27/Sep/2016:14:03:05 /travel/greece/meteora.html BH, Bahrain 27/Sep/2016:14:02:11 / US, United States 27/Sep/2016:14:02:07 /cybersecurity/cloud-exploit.html Unknown 27/Sep/2016:14:02:02 /cybersecurity/cloud-exploit.html Unknown 27/Sep/2016:14:01:41 /robots.txt DE, Germany 27/Sep/2016:14:01:34 /cybersecurity/hostile/downloader-tibs.html DE, Germany 27/Sep/2016:14:01:15 /brewing/ DE, Germany 27/Sep/2016:14:01:06 /cybersecurity/history/uss-chaumont/logs.html DE, Germany 27/Sep/2016:14:00:58 /linux/biblical-unix.html DE, Germany 27/Sep/2016:14:00:49 /travel/greece/greek-mainland.html FR, France 27/Sep/2016:14:00:44 /travel/france/saumur-megaliths/ DE, Germany 27/Sep/2016:14:00:42 /cybersecurity/crypto/reading.html FR, France 27/Sep/2016:14:00:34 /travel/france/saumur-megaliths/ DE, Germany 27/Sep/2016:14:00:34 /travel/belgium/art-nouveau-architecture/ DE, Germany 27/Sep/2016:14:00:25 /linux/linux-kernel.html DE, Germany 27/Sep/2016:14:00:17 /travel/athens-to-paris/veliko-tarnovo-bucharest.html US, United States 27/Sep/2016:14:00:10 /networking/cisco-switch-repair/ DE, Germany 27/Sep/2016:14:00:09 /robots.txt DE, Germany 27/Sep/2016:14:00:02 /robots.txt US, United States 27/Sep/2016:14:00:00 /linux/openbsd-qemu-windows-howto.html US, United States 27/Sep/2016:13:59:46 /technical/dsl/ US, United States 27/Sep/2016:13:58:49 /linux/raspberry-pi/openvas.html US, United States 27/Sep/2016:13:58:32 /fun/ US, United States 27/Sep/2016:13:58:06 /linux/openbsd-qemu-windows-howto.html Unknown 27/Sep/2016:13:57:21 /travel/france/normandy/omaha-beach.html IT, Italy 27/Sep/2016:13:57:13 /linux/raspberry-pi/openvas.html US, United States 27/Sep/2016:13:57:02 / US, United States 27/Sep/2016:13:56:57 /technical/dsl/ Unknown 27/Sep/2016:13:56:44 /turkish/ Unknown 27/Sep/2016:13:56:41 /cybersecurity/hacker-passwords.html US, United States 27/Sep/2016:13:56:32 /fun/fingerbox/ BE, Belgium 27/Sep/2016:13:56:30 /fun/fingerbox/ US, United States 27/Sep/2016:13:56:21 /cybersecurity/netusers/Index/kz US, United States 27/Sep/2016:13:56:12 /linux/linux-boot.html Unknown 27/Sep/2016:13:56:02 /travel/usa/us-wash-masonic.html FR, France 27/Sep/2016:13:55:56 / FR, France 27/Sep/2016:13:55:56 /radio/probes.html Unknown 27/Sep/2016:13:55:43 /travel/usa/us-wash-masonic.html US, United States 27/Sep/2016:13:55:27 /linux/raspberry-pi/openvas.html Unknown 27/Sep/2016:13:55:21 /travel/france/seine-river-art-history-monet/rolleboise-lavacourt-vetheuil.html Unknown 27/Sep/2016:13:54:51 /travel/usa/us-wash-masonic.html PR, Puerto Rico 27/Sep/2016:13:54:42 /3d/xray/scanner.html US, United States 27/Sep/2016:13:54:26 /3d/xray/ PR, Puerto Rico 27/Sep/2016:13:54:24 /3d/xray/ US, United States 27/Sep/2016:13:54:20 /travel/france/pierre-tourneresse/ Unknown 27/Sep/2016:13:54:04 /travel/usa/us-wash-masonic.html US, United States 27/Sep/2016:13:54:01 /technical/google-adsense-and-xhtml.html US, United States 27/Sep/2016:13:53:43 /travel/usa/ US, United States 27/Sep/2016:13:53:43 /travel/usa/ US, United States 27/Sep/2016:13:53:40 /robots.txt US, United States 27/Sep/2016:13:53:17 /russian/grammar.html US, United States 27/Sep/2016:13:52:56 /technical/dsl/ US, United States 27/Sep/2016:13:52:30 /wshta/2011-10-08/ US, United States 27/Sep/2016:13:52:27 /3d/data-collection.html US, United States 27/Sep/2016:13:52:15 / GB, United Kingdom 27/Sep/2016:13:52:12 /linux/openbsd-kernel.html PT, Portugal 27/Sep/2016:13:51:58 /linux/rhel-centos-5-6-7/ US, United States 27/Sep/2016:13:51:08 /fun/fingerbox/ Unknown 27/Sep/2016:13:51:06 /travel/greece/ferries.html US, United States 27/Sep/2016:13:50:44 /travel/uk/orkney-west-coast-walk/ US, United States 27/Sep/2016:13:50:26 /fun/fingerbox/ US, United States 27/Sep/2016:13:50:20 /technical/dsl/ Unknown 27/Sep/2016:13:50:18 /cybersecurity/netusers/Index/ci CN, China 27/Sep/2016:13:50:01 /robots.txt US, United States 27/Sep/2016:13:49:59 /robots.txt US, United States 27/Sep/2016:13:49:44 /technical/dsl/ RO, Romania 27/Sep/2016:13:49:35 /fun/fingerbox/ US, United States 27/Sep/2016:13:49:29 /travel/uk/oxford-lewis-tolkien/ NL, Netherlands 27/Sep/2016:13:48:50 /technical/samsung-galaxy/linux.html US, United States 27/Sep/2016:13:48:15 /travel/belgium/bastogne-ardennes/background.html Unknown 27/Sep/2016:13:48:13 /travel/france/normandy/pegasus-bridge.html US, United States 27/Sep/2016:13:48:04 /linux/raspberry-pi/openvas.html US, United States 27/Sep/2016:13:48:04 /travel/uk/orkney-neolithic/ring-of-brodgar.html US, United States 27/Sep/2016:13:47:54 /travel/uk/orkney-neolithic/ring-of-brodgar.html Unknown 27/Sep/2016:13:47:52 /turkish/turkish-verbs.pdf US, United States 27/Sep/2016:13:47:41 /technical/how-to-copy-dvds.html US, United States 27/Sep/2016:13:46:29 /turkish/verbs.html IT, Italy 27/Sep/2016:13:45:41 /radio/probes.html US, United States 27/Sep/2016:13:45:21 /travel/uk/glastonbury/chalice-spring-tor.html Unknown 27/Sep/2016:13:45:09 /cybersecurity/root-password.html CA, Canada 27/Sep/2016:13:44:48 /linux/openbsd-kernel.html CA, Canada 27/Sep/2016:13:44:33 /linux/openbsd-kernel.html US, United States 27/Sep/2016:13:43:25 /travel/usa/us-wash-masonic.html US, United States 27/Sep/2016:13:43:09 /linux/ssh-3-user.html US, United States 27/Sep/2016:13:43:04 /technical/samsung-galaxy/block-calls.html US, United States 27/Sep/2016:13:42:40 /robots.txt IN, India 27/Sep/2016:13:40:18 /linux/sendmail-ssl.html GB, United Kingdom 27/Sep/2016:13:38:52 / Unknown 27/Sep/2016:13:38:39 /linux/rhel-centos-5-6-7/users-groups.html DE, Germany 27/Sep/2016:13:38:32 /travel/uk/scotland-pitlochry/ US, United States 27/Sep/2016:13:37:54 /travel/turkey/mountain-trek/ US, United States 27/Sep/2016:13:37:52 /travel/trinidad/background.html US, United States 27/Sep/2016:13:37:43 /travel/uk/harwell-glider-base/ ES, Spain 27/Sep/2016:13:37:22 /linux/cluster.html US, United States 27/Sep/2016:13:37:16 /linux/openbsd-kernel.html US, United States 27/Sep/2016:13:36:06 /radio/power-meter.html Unknown 27/Sep/2016:13:35:27 /technical/ata-ide-sata-usb-cable-pinouts.html Unknown 27/Sep/2016:13:35:22 /technical/ata-ide-sata-usb-cable-pinouts.html US, United States 27/Sep/2016:13:34:54 /radio/power-meter.html US, United States 27/Sep/2016:13:34:49 /networking/logs-in-color.html Unknown 27/Sep/2016:13:34:36 /linux/apache-https-x509v3.html US, United States 27/Sep/2016:13:34:07 / Unknown 27/Sep/2016:13:33:44 /technical/ata-ide-sata-usb-cable-pinouts.html US, United States 27/Sep/2016:13:33:34 /travel/france/normandy/pegasus-bridge.html US, United States 27/Sep/2016:13:33:22 /linux/performance-tuning/disks.html US, United States 27/Sep/2016:13:32:02 /russian/grammar.html US, United States 27/Sep/2016:13:31:55 /travel/belgium/bastogne-ardennes/ardennes-forest.html Unknown 27/Sep/2016:13:31:37 /cybersecurity/hacker-passwords.html US, United States 27/Sep/2016:13:31:32 /cybersecurity/netusers/Index/pe GB, United Kingdom 27/Sep/2016:13:31:07 / NL, Netherlands 27/Sep/2016:13:30:43 /linux/multiboot-windows-openbsd/ US, United States 27/Sep/2016:13:30:29 /travel/france/mont-saint-michel-saint-malo/ US, United States 27/Sep/2016:13:30:28 /robots.txt US, United States 27/Sep/2016:13:30:20 /linux/linux-break-in-howto.html Unknown 27/Sep/2016:13:29:28 /technical/html-greyscale-test.html GB, United Kingdom 27/Sep/2016:13:28:40 /cybersecurity/software.html GB, United Kingdom 27/Sep/2016:13:28:38 /robots.txt US, United States 27/Sep/2016:13:27:51 /travel/uk/glastonbury/town.html Unknown 27/Sep/2016:13:27:49 /travel/uk/glastonbury/town.html US, United States 27/Sep/2016:13:27:40 /travel/uk/oxford-lewis-tolkien/ CN, China 27/Sep/2016:13:27:38 /linux/linux-commands.html CN, China 27/Sep/2016:13:27:37 /linux/getting-started.html CN, China 27/Sep/2016:13:27:37 /cybersecurity/ec2-secure-storage.html CN, China 27/Sep/2016:13:27:37 /linux/linux-blog.html CN, China 27/Sep/2016:13:27:37 /linux/ssh.html CN, China 27/Sep/2016:13:27:37 /linux/kerberos.html CN, China 27/Sep/2016:13:27:37 /linux/linux-break-in-howto.html CN, China 27/Sep/2016:13:27:37 /linux/sendmail-ssl.html CN, China 27/Sep/2016:13:27:36 /linux/system-administration.html CN, China 27/Sep/2016:13:27:33 /cybersecurity/linux-hardening.html CN, China 27/Sep/2016:13:27:33 /linux/qemu-unix.html CN, China 27/Sep/2016:13:27:32 /steampunk/gsm-soviet-telephone.html CN, China 27/Sep/2016:13:27:32 /radio/internet-radio.html CN, China 27/Sep/2016:13:27:32 /cybersecurity/surveillance.html CN, China 27/Sep/2016:13:27:30 /pubs.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 blue, 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