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 22/Feb/2019:20:09:00 /robots.txt AR, Argentina 22/Feb/2019:20:08:47 /open-source/sendmail-ssl.html US, United States 22/Feb/2019:20:08:21 /open-source/pdf-not-authorized.html CA, Canada 22/Feb/2019:20:08:08 /open-source/sendmail-ssl.html CZ, Czech Republic 22/Feb/2019:20:07:40 /cybersecurity/regulations.html US, United States 22/Feb/2019:20:07:29 / US, United States 22/Feb/2019:20:06:46 /fun/freudian-seuss.html US, United States 22/Feb/2019:20:06:40 /open-source/rhel-centos-5-6-7-8/logging.html CZ, Czech Republic 22/Feb/2019:20:06:35 /robots.txt ES, Spain 22/Feb/2019:20:06:35 /open-source/linux-boot.html GB, United Kingdom 22/Feb/2019:20:06:09 /turkish/orthography.html RU, Russian Federation 22/Feb/2019:20:06:06 /robots.txt IE, Ireland 22/Feb/2019:20:05:52 /open-source/performance-tuning/nfs.html CN, China 22/Feb/2019:20:05:32 /travel/bulgaria/food/ GB, United Kingdom 22/Feb/2019:20:04:14 /turkish/background.html US, United States 22/Feb/2019:20:04:10 /travel/belgium/bastogne-ardennes/bastogne.html US, United States 22/Feb/2019:20:04:01 /open-source/raspberry-pi/openvas.html US, United States 22/Feb/2019:20:03:58 /cybersecurity/physical.html US, United States 22/Feb/2019:20:03:26 /open-source/raspberry-pi/ads-b-antenna.html US, United States 22/Feb/2019:20:03:10 /networking/nat.html US, United States 22/Feb/2019:20:02:52 /travel/uk/scotland-pitlochry/ US, United States 22/Feb/2019:20:02:52 /technical/dsl/ US, United States 22/Feb/2019:20:02:46 /travel/mexico/teotihuacan.html GB, United Kingdom 22/Feb/2019:20:02:30 /turkish/ US, United States 22/Feb/2019:20:01:40 /travel/uk/lee-ho-fook/ IT, Italy 22/Feb/2019:20:00:44 /open-source/openbsd-qemu-windows-howto.html US, United States 22/Feb/2019:20:00:23 /travel/belgium/bastogne-ardennes/ardennes-forest.html US, United States 22/Feb/2019:20:00:13 /steampunk/lamp.html US, United States 22/Feb/2019:20:00:09 /open-source/performance-tuning/tcp.html US, United States 22/Feb/2019:20:00:01 /cybersecurity/ US, United States 22/Feb/2019:19:59:35 /travel/usa/new-york-skate-manhattan/ FR, France 22/Feb/2019:19:59:09 /fun/sarah-palin-baby-name-generator.html TR, Turkey 22/Feb/2019:19:58:40 /turkish/verbs.html US, United States 22/Feb/2019:19:58:26 / US, United States 22/Feb/2019:19:58:26 /robots.txt US, United States 22/Feb/2019:19:58:25 /robots.txt FR, France 22/Feb/2019:19:57:59 /open-source/letsencrypt-tls-cert-godaddy.html RU, Russian Federation 22/Feb/2019:19:57:55 /turkish/background.html US, United States 22/Feb/2019:19:57:20 /technical/dsl/ DK, Denmark 22/Feb/2019:19:57:13 /technical/dsl/ IN, India 22/Feb/2019:19:56:59 /technical/dsl/ RU, Russian Federation 22/Feb/2019:19:56:48 /turkish/ IN, India 22/Feb/2019:19:56:34 /technical/dsl/ BR, Brazil 22/Feb/2019:19:55:57 /open-source/rhel-centos-5-6-7-8/ RU, Russian Federation 22/Feb/2019:19:55:47 /turkish/ US, United States 22/Feb/2019:19:55:41 /robots.txt GB, United Kingdom 22/Feb/2019:19:54:41 /travel/usa/detroit/detroit-part3.html US, United States 22/Feb/2019:19:54:40 /radio/tv-antenna.html CL, Chile 22/Feb/2019:19:54:03 / US, United States 22/Feb/2019:19:54:02 /radio/rf-spectrum.html RS, Serbia 22/Feb/2019:19:53:54 /open-source/sendmail-ssl.html GB, United Kingdom 22/Feb/2019:19:53:50 /travel/usa/new-york-obama/ US, United States 22/Feb/2019:19:53:47 /travel/mexico/leon-trotsky.html US, United States 22/Feb/2019:19:53:24 /open-source/compiling-wireshark-on-openbsd.html GB, United Kingdom 22/Feb/2019:19:51:21 /3d/xray/lightbox.html TR, Turkey 22/Feb/2019:19:51:12 /turkish/word-order.html CN, China 22/Feb/2019:19:50:49 /russian/ BY, Belarus 22/Feb/2019:19:50:43 /open-source/nginx-tls-1.3/running-tls-1.3.html US, United States 22/Feb/2019:19:50:34 /travel/uk/glastonbury/holy-grail.html US, United States 22/Feb/2019:19:50:18 /open-source/sysfs.html FR, France 22/Feb/2019:19:50:16 /open-source/raspberry-pi/ US, United States 22/Feb/2019:19:50:12 /travel/usa/new-york-mcgees/ US, United States 22/Feb/2019:19:50:08 / FR, France 22/Feb/2019:19:50:03 /travel/mexico/cholula-puebla.html?s=tweetbot TR, Turkey 22/Feb/2019:19:50:03 /turkish/background.html US, United States 22/Feb/2019:19:50:02 /technical/dsl/ US, United States 22/Feb/2019:19:49:55 /robots.txt US, United States 22/Feb/2019:19:49:55 /turkish/language-reform.html US, United States 22/Feb/2019:19:49:52 / US, United States 22/Feb/2019:19:49:52 /robots.txt TR, Turkey 22/Feb/2019:19:49:48 /turkish/language-reform.html TR, Turkey 22/Feb/2019:19:49:47 /turkish/language-reform.html TR, Turkey 22/Feb/2019:19:49:39 /turkish/verbs.html US, United States 22/Feb/2019:19:49:23 /open-source/sysfs.html TR, Turkey 22/Feb/2019:19:49:11 /turkish/orthography.html HK, Hong Kong 22/Feb/2019:19:49:00 /travel/turkey/trains/ TR, Turkey 22/Feb/2019:19:48:34 /turkish/ TR, Turkey 22/Feb/2019:19:48:30 /turkish/background.html US, United States 22/Feb/2019:19:48:30 /3d/xray/ TR, Turkey 22/Feb/2019:19:48:29 /turkish/background.html TR, Turkey 22/Feb/2019:19:48:28 /turkish/background.html US, United States 22/Feb/2019:19:48:08 /open-source/openbsd-qemu-windows-howto.html GB, United Kingdom 22/Feb/2019:19:47:52 /travel/usa/detroit/ US, United States 22/Feb/2019:19:47:23 /open-source/performance-tuning/ TR, Turkey 22/Feb/2019:19:46:59 /turkish/word-order.html US, United States 22/Feb/2019:19:46:47 /cybersecurity/public-key.html US, United States 22/Feb/2019:19:46:45 /pubs.html US, United States 22/Feb/2019:19:46:44 / US, United States 22/Feb/2019:19:46:43 /travel/ US, United States 22/Feb/2019:19:46:41 /open-source/ US, United States 22/Feb/2019:19:46:39 /cybersecurity/ US, United States 22/Feb/2019:19:46:38 /networking/ FR, France 22/Feb/2019:19:46:37 /travel/turkey/buses/Index.html US, United States 22/Feb/2019:19:46:36 /technical/ US, United States 22/Feb/2019:19:46:35 /radio/ US, United States 22/Feb/2019:19:46:32 /site-map.html US, United States 22/Feb/2019:19:46:31 /open-source/google-freebsd-tls/apache-http2-php.html US, United States 22/Feb/2019:19:46:29 /open-source/nginx-tls-1.3/ US, United States 22/Feb/2019:19:46:27 /cybersecurity/privacy-policy.html US, United States 22/Feb/2019:19:46:26 /cybersecurity/root-password.html US, United States 22/Feb/2019:19:46:25 /contact.html JP, Japan 22/Feb/2019:19:46:23 /open-source/build-packages.html US, United States 22/Feb/2019:19:46:21 /contact.html US, United States 22/Feb/2019:19:46:19 /travel/usa/venice-california/Index.html US, United States 22/Feb/2019:19:45:45 /travel/usa/new-york-marvel/Index.html GB, United Kingdom 22/Feb/2019:19:44:13 /travel/mexico/cholula-puebla.html?s=tweetbot PL, Poland 22/Feb/2019:19:43:48 /technical/bios.html DE, Germany 22/Feb/2019:19:43:24 /travel/mexico/cholula-puebla.html?s=tweetbot US, United States 22/Feb/2019:19:43:11 /technical/dsl/ US, United States 22/Feb/2019:19:43:02 /turkish/nouns.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