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 05/Dec/2019:15:23:39 /robots.txt US, United States 05/Dec/2019:15:23:38 /travel/romania/bucharest/?s=tb US, United States 05/Dec/2019:15:23:36 /travel/uk/scapa-flow/ US, United States 05/Dec/2019:15:23:36 /travel/egypt/giza.html?s=tb RO, Romania 05/Dec/2019:15:23:35 /open-source/performance-tuning/disks.html US, United States 05/Dec/2019:15:23:33 /robots.txt US, United States 05/Dec/2019:15:23:04 /travel/hungary/ CN, China 05/Dec/2019:15:22:56 /robots.txt CN, China 05/Dec/2019:15:22:56 /robots.txt US, United States 05/Dec/2019:15:22:51 /travel/uk/glen-nevis/?s=tweetbot KR, Korea, Republic of 05/Dec/2019:15:22:09 /open-source/rhel-centos-5-6-7-8/ US, United States 05/Dec/2019:15:22:09 /travel/france/boat/Index.html ES, Spain 05/Dec/2019:15:22:06 /open-source/performance-tuning/tcp.html GB, United Kingdom 05/Dec/2019:15:21:51 /open-source/performance-tuning/ethernet.html US, United States 05/Dec/2019:15:21:16 /travel/france/school-lunch-menus/ US, United States 05/Dec/2019:15:21:15 /fun/santaism.html GB, United Kingdom 05/Dec/2019:15:21:12 /travel/uk/skara-brae/ US, United States 05/Dec/2019:15:20:57 /travel/japan/kamakura/kencho-ji.html RU, Russian Federation 05/Dec/2019:15:19:55 /open-source/performance-tuning/file-systems.html CN, China 05/Dec/2019:15:19:41 / DE, Germany 05/Dec/2019:15:19:32 /travel/russia/getting-there.html?s=tb DE, Germany 05/Dec/2019:15:19:32 /robots.txt ES, Spain 05/Dec/2019:15:18:47 /open-source/performance-tuning/ethernet.html RU, Russian Federation 05/Dec/2019:15:18:40 /turkish/nouns.html US, United States 05/Dec/2019:15:18:39 /turkish/verbs.html RU, Russian Federation 05/Dec/2019:15:18:31 /turkish/nouns.html US, United States 05/Dec/2019:15:18:20 /open-source/sendmail-ssl.html US, United States 05/Dec/2019:15:18:20 /travel/athens-to-paris/ US, United States 05/Dec/2019:15:17:40 /travel/france/boat/meals.html US, United States 05/Dec/2019:15:17:23 /fun/fingerbox/ US, United States 05/Dec/2019:15:17:19 /fun/fingerbox/ IN, India 05/Dec/2019:15:17:11 /cybersecurity/history/ US, United States 05/Dec/2019:15:17:07 /travel/russia/getting-there.html?s=tb US, United States 05/Dec/2019:15:17:07 / US, United States 05/Dec/2019:15:17:07 /travel/turkey/hans/ US, United States 05/Dec/2019:15:16:53 /travel/turkey/hans/ IT, Italy 05/Dec/2019:15:16:22 /open-source/performance-tuning/disks.html US, United States 05/Dec/2019:15:16:18 /open-source/stig-compliance.html FR, France 05/Dec/2019:15:15:42 /turkish/verbs.html DE, Germany 05/Dec/2019:15:15:18 /travel/china/li-river.html?s=tb US, United States 05/Dec/2019:15:15:17 /travel/usa/new-york-revolutionary/anarchists.html?s=tb DE, Germany 05/Dec/2019:15:14:59 /travel/russia/getting-there.html?s=tb DE, Germany 05/Dec/2019:15:14:58 /robots.txt DE, Germany 05/Dec/2019:15:14:56 /travel/china/li-river.html?s=tb FR, France 05/Dec/2019:15:14:56 /travel/china/li-river.html?s=tb BG, Bulgaria 05/Dec/2019:15:14:47 /open-source/rhel-centos-multimedia.html US, United States 05/Dec/2019:15:14:28 / US, United States 05/Dec/2019:15:14:16 /travel/russia/getting-there.html?s=tb FR, France 05/Dec/2019:15:14:14 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:14:07 /travel/russia/getting-there.html?s=tb US, United States 05/Dec/2019:15:14:02 /ads.txt US, United States 05/Dec/2019:15:14:02 /travel/russia/getting-there.html?s=tb US, United States 05/Dec/2019:15:14:01 /travel/russia/getting-there.html?s=tb US, United States 05/Dec/2019:15:13:53 /cybersecurity/history/uss-chaumont/history.html CN, China 05/Dec/2019:15:13:48 /radio/frequencies.html CZ, Czech Republic 05/Dec/2019:15:13:41 /cybersecurity/history/uss-chaumont/history.html US, United States 05/Dec/2019:15:13:39 /turkish/nouns.html GB, United Kingdom 05/Dec/2019:15:13:39 /3d/xray/film.html RU, Russian Federation 05/Dec/2019:15:13:15 /open-source/performance-tuning/file-systems.html US, United States 05/Dec/2019:15:13:04 /text/reports/3snark.2.txt US, United States 05/Dec/2019:15:12:35 /cybersecurity/basics/06-safe-email-and-web.html US, United States 05/Dec/2019:15:12:14 /travel/belgium/bastogne-ardennes/background.html US, United States 05/Dec/2019:15:11:57 /travel/france/flaneur-1/?s=tb DE, Germany 05/Dec/2019:15:11:31 /open-source/performance-tuning/disks.html US, United States 05/Dec/2019:15:11:11 /travel/usa/new-york-mcgees/ US, United States 05/Dec/2019:15:10:06 /technical/ata-ide-sata-usb-cable-pinouts.html FR, France 05/Dec/2019:15:09:35 /travel/japan/kofun/emperor-kaika.html?s=tb DE, Germany 05/Dec/2019:15:09:19 /travel/japan/kofun/emperor-kaika.html?s=tb US, United States 05/Dec/2019:15:09:17 /travel/japan/kofun/emperor-kaika.html?s=tb CA, Canada 05/Dec/2019:15:09:05 /travel/japan/kofun/emperor-kaika.html?s=tb CA, Canada 05/Dec/2019:15:09:05 /travel/japan/kofun/emperor-kaika.html?s=tb US, United States 05/Dec/2019:15:09:01 /travel/japan/kofun/emperor-kaika.html?s=tb US, United States 05/Dec/2019:15:09:01 /travel/japan/kofun/emperor-kaika.html?s=tb RU, Russian Federation 05/Dec/2019:15:08:58 /text/reports/5great.3.txt US, United States 05/Dec/2019:15:08:54 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:08:52 /turkish/Index.html FR, France 05/Dec/2019:15:08:48 /cybersecurity/ssh-attack-study.html DE, Germany 05/Dec/2019:15:08:30 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:08:25 /cybersecurity/basics/10-road-warrior.html US, United States 05/Dec/2019:15:08:25 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:08:23 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:08:15 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:08:15 /robots.txt US, United States 05/Dec/2019:15:08:11 /cybersecurity/availability/ddos.html DE, Germany 05/Dec/2019:15:08:11 /cybersecurity/availability/ddos.html DE, Germany 05/Dec/2019:15:08:10 /robots.txt US, United States 05/Dec/2019:15:08:10 /open-source/raspberry-pi/sdr-ads-b-piaware-and-fr24feed.html US, United States 05/Dec/2019:15:08:01 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:08:00 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:08:00 /cybersecurity/availability/ddos.html US, United States 05/Dec/2019:15:08:00 /open-source/raspberry-pi/sdr-ads-b-piaware-and-fr24feed.html US, United States 05/Dec/2019:15:07:52 /technical/dsl/ US, United States 05/Dec/2019:15:07:47 /cybersecurity/basics/02-smart-phone-and-tablet.html US, United States 05/Dec/2019:15:07:44 /open-source/stig-compliance.html US, United States 05/Dec/2019:15:07:32 /open-source/performance-tuning/ethernet.html RU, Russian Federation 05/Dec/2019:15:07:13 /travel/turkey/hans/ RU, Russian Federation 05/Dec/2019:15:07:12 /robots.txt US, United States 05/Dec/2019:15:06:47 /cybersecurity/basics/ US, United States 05/Dec/2019:15:06:42 /cybersecurity/ CA, Canada 05/Dec/2019:15:06:37 /radio/tv-antenna.html US, United States 05/Dec/2019:15:06:15 /open-source/lvm-rescue-boot.html US, United States 05/Dec/2019:15:05:23 /travel/uk/orkney-west-coast-walk/ US, United States 05/Dec/2019:15:05:23 /cybersecurity/isc2-cissp/ US, United States 05/Dec/2019:15:04:56 /cybersecurity/isc2-ccsp/ US, United States 05/Dec/2019:15:04:52 /travel/uk/orkney-west-coast-walk/ US, United States 05/Dec/2019:15:04:30 /cybersecurity/isc2-cissp/ CH, Switzerland 05/Dec/2019:15:04:14 /open-source/pdf-not-authorized.html US, United States 05/Dec/2019:15:04:10 /technical/how-to-copy-dvds.html US, United States 05/Dec/2019:15:04:08 /robots.txt TR, Turkey 05/Dec/2019:15:03:19 /travel/china/li-river.html?s=tb US, United States 05/Dec/2019:15:03:05 /travel/china/li-river.html?s=tb US, United States 05/Dec/2019:15:03:04 / US, United States 05/Dec/2019:15:02:15 /travel/japan/nikko/takino-shrine-path.html?s=tb IE, Ireland 05/Dec/2019:15:01:53 /travel/usa/new-york-mcgees/ GB, United Kingdom 05/Dec/2019:15:01:39 /travel/usa/new-york-mcgees/ RU, Russian Federation 05/Dec/2019:15:01:35 /open-source/openbsd-wireless-wpa2.html US, United States 05/Dec/2019:15:00:43 /cybersecurity/cloud-exploit.html GB, United Kingdom 05/Dec/2019:15:00:36 /open-source/linux-break-in-howto.html GB, United Kingdom 05/Dec/2019:14:59:58 /open-source/performance-tuning/disks.html DE, Germany 05/Dec/2019:14:59:33 /travel/uk/orkney-neolithic/stones-of-stenness.html US, United States 05/Dec/2019:14:59:32 /open-source/performance-tuning/ethernet.html US, United States 05/Dec/2019:14:59:23 /open-source/samba-active-directory/slave-dns.html US, United States 05/Dec/2019:14:59:19 /technical/dsl/ DE, Germany 05/Dec/2019:14:59:15 /travel/japan/nikko/nikko.html US, United States 05/Dec/2019:14:59:10 /open-source/stig-compliance.html PK, Pakistan 05/Dec/2019:14:59:07 /open-source/performance-tuning/tcp.html DE, Germany 05/Dec/2019:14:58:55 /travel/france/boat/meals.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