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 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 19/Oct/2019:16:54:28 /steampunk/ US, United States 19/Oct/2019:16:54:28 /robots.txt US, United States 19/Oct/2019:16:53:08 /technical/dsl/ US, United States 19/Oct/2019:16:52:11 /open-source/rhel-centos-5-6-7-8/network-services.html BY, Belarus 19/Oct/2019:16:51:20 /open-source/performance-tuning/tcp.html US, United States 19/Oct/2019:16:50:25 /travel/japan/kamakura/path-yagura.html?s=tweetbot US, United States 19/Oct/2019:16:49:51 /open-source/performance-tuning/ethernet.html FR, France 19/Oct/2019:16:49:00 /cybersecurity/monitoring.html CN, China 19/Oct/2019:16:48:50 /cybersecurity/ FR, France 19/Oct/2019:16:48:33 /open-source/rhel-centos-5-6-7-8/ UA, Ukraine 19/Oct/2019:16:48:28 /contact.html UA, Ukraine 19/Oct/2019:16:48:27 /travel/japan/tokyo-asakusa/sushi-train.html UA, Ukraine 19/Oct/2019:16:48:22 /travel/japan/tokyo-asakusa/markets-and-streets.html US, United States 19/Oct/2019:16:47:44 /open-source/rhel-centos-5-6-7-8/ US, United States 19/Oct/2019:16:47:43 /technical/dsl/ KR, Korea, Republic of 19/Oct/2019:16:47:41 /networking/commands.html DE, Germany 19/Oct/2019:16:47:39 /radio/rf-spectrum.html US, United States 19/Oct/2019:16:46:59 /fun/fingerbox/ DK, Denmark 19/Oct/2019:16:46:19 /radio/power-meter.html US, United States 19/Oct/2019:16:46:08 /cybersecurity/syn2.html US, United States 19/Oct/2019:16:46:04 /cybersecurity/attack-study/attacker-perspective.html IN, India 19/Oct/2019:16:45:46 /travel/usa/new-york-mcgees/ DE, Germany 19/Oct/2019:16:45:04 /technical/html4-or-xhtml-to-html5.html GB, United Kingdom 19/Oct/2019:16:44:30 /travel/hungary/budapest/?s=tb DE, Germany 19/Oct/2019:16:44:23 /travel/hungary/budapest/?s=tb US, United States 19/Oct/2019:16:44:16 /travel/hungary/budapest/?s=tb US, United States 19/Oct/2019:16:44:04 /technical/dsl/ US, United States 19/Oct/2019:16:44:01 /travel/hungary/budapest/?s=tb US, United States 19/Oct/2019:16:44:01 /travel/hungary/budapest/?s=tb US, United States 19/Oct/2019:16:44:00 /robots.txt US, United States 19/Oct/2019:16:43:36 /open-source/font-config-warnings.html DE, Germany 19/Oct/2019:16:43:35 /open-source/font-config-warnings.html US, United States 19/Oct/2019:16:42:54 /travel/megaliths/ CN, China 19/Oct/2019:16:42:38 /fun/foxnews.html US, United States 19/Oct/2019:16:42:01 /travel/usa/new-york-skate-manhattan/ BE, Belgium 19/Oct/2019:16:41:51 /technical/samsung-galaxy/ssh.html NL, Netherlands 19/Oct/2019:16:41:48 /cybersecurity/virtualization.html TT, Trinidad and Tobago 19/Oct/2019:16:41:42 /radio/tv-antenna.html US, United States 19/Oct/2019:16:41:39 /travel/turkey/ephesus/ US, United States 19/Oct/2019:16:41:38 /robots.txt US, United States 19/Oct/2019:16:41:34 /networking/terminology.html IN, India 19/Oct/2019:16:41:21 /open-source/ AT, Austria 19/Oct/2019:16:40:41 /technical/convert-youtube-to-xvid.html US, United States 19/Oct/2019:16:40:34 /cybersecurity/verify-digital-signature.html GB, United Kingdom 19/Oct/2019:16:40:20 /travel/usa/new-york-mcgees/ US, United States 19/Oct/2019:16:40:01 /travel/usa/new-york-sro-flophouses/shutdown.html US, United States 19/Oct/2019:16:40:00 /open-source/performance-tuning/disks.html US, United States 19/Oct/2019:16:40:00 /open-source/performance-tuning/disks.html US, United States 19/Oct/2019:16:39:59 /travel/uk/glastonbury/wearyall-hill.html US, United States 19/Oct/2019:16:39:50 /open-source/performance-tuning/disks.html US, United States 19/Oct/2019:16:39:31 /open-source/performance-tuning/disks.html US, United States 19/Oct/2019:16:39:30 /open-source/performance-tuning/disks.html US, United States 19/Oct/2019:16:39:18 /open-source/performance-tuning/hardware.html US, United States 19/Oct/2019:16:39:14 /robots.txt TR, Turkey 19/Oct/2019:16:38:59 /travel/turkey/ephesus/walk.html TR, Turkey 19/Oct/2019:16:38:59 /travel/turkey/ephesus/walk.html US, United States 19/Oct/2019:16:38:50 /travel/uk/glastonbury/holy-grail.html IT, Italy 19/Oct/2019:16:38:38 /open-source/rhel-centos-5-6-7-8/ FR, France 19/Oct/2019:16:38:26 /travel/france/marseille/arrival.html FR, France 19/Oct/2019:16:38:14 /open-source/performance-tuning/disks.html US, United States 19/Oct/2019:16:37:17 /open-source/ftp-howto.html FR, France 19/Oct/2019:16:37:11 /travel/france/school-lunch-menus/?s=tweetbot US, United States 19/Oct/2019:16:36:41 /travel/uk/orkney-neolithic/stones-of-stenness.html US, United States 19/Oct/2019:16:36:11 /travel/uk/glastonbury/abbey-church.html?s=tb US, United States 19/Oct/2019:16:35:43 /travel/usa/new-york-nighthawks/ US, United States 19/Oct/2019:16:35:39 /travel/france/ronin/ US, United States 19/Oct/2019:16:35:39 /travel/france/ronin/ US, United States 19/Oct/2019:16:35:27 /travel/usa/detroit/Index.html US, United States 19/Oct/2019:16:35:26 /travel/uk/ US, United States 19/Oct/2019:16:35:24 /travel/france/ronin/ US, United States 19/Oct/2019:16:35:00 /open-source/openbsd-kernel.html CN, China 19/Oct/2019:16:34:59 /robots.txt CH, Switzerland 19/Oct/2019:16:34:11 /radio/probes.html US, United States 19/Oct/2019:16:33:44 / FR, France 19/Oct/2019:16:33:33 /travel/greece/trains.html DE, Germany 19/Oct/2019:16:33:33 /travel/poland/?s=tb US, United States 19/Oct/2019:16:33:25 /travel/uk/glastonbury/chalice-spring-tor.html FR, France 19/Oct/2019:16:32:59 /travel/poland/?s=tb US, United States 19/Oct/2019:16:32:54 /open-source/rhel-centos-5-6-7-8/ GB, United Kingdom 19/Oct/2019:16:32:52 / DE, Germany 19/Oct/2019:16:32:29 /travel/poland/?s=tb GB, United Kingdom 19/Oct/2019:16:32:29 /open-source/virtualization.html GB, United Kingdom 19/Oct/2019:16:32:25 /travel/poland/?s=tb GB, United Kingdom 19/Oct/2019:16:32:25 /travel/uk/glastonbury/chalice-spring-tor.html GB, United Kingdom 19/Oct/2019:16:31:43 /open-source/system-administration.html GB, United Kingdom 19/Oct/2019:16:30:20 /open-source/virtualization.html US, United States 19/Oct/2019:16:30:18 /ads.txt US, United States 19/Oct/2019:16:30:06 /travel/latvia/ US, United States 19/Oct/2019:16:29:56 /open-source/openbsd-wireless-wpa2.html GB, United Kingdom 19/Oct/2019:16:29:36 /3d/xray/ GB, United Kingdom 19/Oct/2019:16:29:34 /robots.txt US, United States 19/Oct/2019:16:29:27 /travel/greece/meteora.html?s=tb Unknown 19/Oct/2019:16:29:27 /turkish/ US, United States 19/Oct/2019:16:29:12 /cybersecurity/public-key.html RU, Russian Federation 19/Oct/2019:16:29:02 /open-source/sendmail-ssl.html DE, Germany 19/Oct/2019:16:28:51 /travel/poland/?s=tb US, United States 19/Oct/2019:16:28:48 /travel/ US, United States 19/Oct/2019:16:28:48 /open-source/python-twitter-automation/ US, United States 19/Oct/2019:16:28:24 /travel/poland/?s=tb US, United States 19/Oct/2019:16:28:19 /travel/uk/the-road-to-the-isles/glen-nevis-fort-william.html TR, Turkey 19/Oct/2019:16:28:13 /travel/turkey/ephesus/ US, United States 19/Oct/2019:16:28:01 /travel/poland/?s=tb US, United States 19/Oct/2019:16:28:01 /travel/poland/?s=tb US, United States 19/Oct/2019:16:28:00 /travel/poland/?s=tb IT, Italy 19/Oct/2019:16:27:50 /open-source/performance-tuning/disks.html US, United States 19/Oct/2019:16:27:28 /technical/dsl/ US, United States 19/Oct/2019:16:27:23 /technical/dsl/ US, United States 19/Oct/2019:16:26:55 /open-source/rhel-centos-5-6-7-8/ US, United States 19/Oct/2019:16:26:37 /travel/france/saint-denis/ CA, Canada 19/Oct/2019:16:26:30 /open-source/rhel-centos-5-6-7-8/booting.html IT, Italy 19/Oct/2019:16:26:23 /travel/usa/new-york-mcgees/ US, United States 19/Oct/2019:16:25:46 /technical/dsl/ CA, Canada 19/Oct/2019:16:25:15 /turkish/Index.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-12 textleft\" ");
			printf("style=\"color:#000; background:#%02x%02x%02x;\"> ", r, g, b);
			for (i = 5; i <= NF; i++) {
				printf("%s ", $i);

Other Pages