Rack of Ethernet switches.

Visualizing Log Patterns with Color

Nginx and 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 23/Sep/2023:09:50:15 /robots.txt US, United States 23/Sep/2023:09:50:09 /travel/uk/national-grid-os-maps/?s=mb US, United States 23/Sep/2023:09:50:08 /travel/russia/getting-there.html?s=tweetbot CN, China 23/Sep/2023:09:49:50 /open-source/rhel-oracle-centos-6-7-8-9/users-groups.html MD, Moldova, Republic of 23/Sep/2023:09:49:45 /cybersecurity/root-password.html US, United States 23/Sep/2023:09:49:27 /travel/greece/meteora.html?s=tweetbot RU, Russian Federation 23/Sep/2023:09:48:32 /open-source/tar-and-ssh.html FR, France 23/Sep/2023:09:48:12 /travel/france/boat/tying-up-and-weather.html?s=tweetbot US, United States 23/Sep/2023:09:48:10 /travel/belgium/belgian-beers/delirium-tremens.html CN, China 23/Sep/2023:09:47:23 /cybersecurity/hostile/gibe-f-worm.html US, United States 23/Sep/2023:09:45:32 /travel/usa/new-york-sro-flophouses/vigilant.html FR, France 23/Sep/2023:09:45:26 /open-source/performance-tuning/nfs.html US, United States 23/Sep/2023:09:45:05 /travel/france/boat/boat-handling-and-locks.html Unknown 23/Sep/2023:09:45:01 /radio/copper-wire/ FR, France 23/Sep/2023:09:44:27 /open-source/openbsd-wireless-wpa2.html US, United States 23/Sep/2023:09:44:22 /networking/terminology.html MD, Moldova, Republic of 23/Sep/2023:09:44:14 /travel/france/loire-valley/ US, United States 23/Sep/2023:09:44:12 / MD, Moldova, Republic of 23/Sep/2023:09:44:11 /travel/greece/kos/ US, United States 23/Sep/2023:09:43:49 /open-source/linux-amd-ryzen-gpu/ KR, Korea, Republic of 23/Sep/2023:09:43:29 /open-source/raspberry-pi/sdr-getting-started.html TH, Thailand 23/Sep/2023:09:43:25 /open-source/performance-tuning/file-systems.html US, United States 23/Sep/2023:09:42:54 /radio/9-1-unun/ US, United States 23/Sep/2023:09:42:05 /open-source/raspberry-pi/sdr-getting-started.html US, United States 23/Sep/2023:09:41:40 / US, United States 23/Sep/2023:09:41:33 /networking/terminology.html US, United States 23/Sep/2023:09:41:08 /travel/greece/greek-mainland.html?s=tb CN, China 23/Sep/2023:09:40:49 /travel/japan/aizu-wakamatsu/otsukayama-kofun/ CN, China 23/Sep/2023:09:40:33 /open-source/raspberry-pi/openvas.html RU, Russian Federation 23/Sep/2023:09:40:30 /travel/greece/crete/ US, United States 23/Sep/2023:09:40:24 /travel/usa/new-york-fictional-architecture/upper-west-side.html CA, Canada 23/Sep/2023:09:40:22 /cybersecurity/generalinfo.html US, United States 23/Sep/2023:09:40:22 /travel/athens-to-paris/veliko-tarnovo-bucharest.html?s=mb US, United States 23/Sep/2023:09:40:16 / US, United States 23/Sep/2023:09:40:14 /travel/usa/new-york-fictional-architecture/upper-west-side.html CN, China 23/Sep/2023:09:40:05 /travel/belgium/bastogne-ardennes/?s=mb GB, United Kingdom 23/Sep/2023:09:39:58 /travel/uk/scapa-flow/ US, United States 23/Sep/2023:09:39:55 /travel/morocco/tangier/casablanca-to-tangier.html GB, United Kingdom 23/Sep/2023:09:39:53 /travel/uk/scapa-flow/ US, United States 23/Sep/2023:09:39:52 / GB, United Kingdom 23/Sep/2023:09:39:51 /travel/uk/scapa-flow/ FI, Finland 23/Sep/2023:09:39:19 /contact.html FI, Finland 23/Sep/2023:09:39:17 /cybersecurity/hostile/gibe-f-worm.html US, United States 23/Sep/2023:09:38:44 /fun/requests-for-quotes/seman-peru/ US, United States 23/Sep/2023:09:38:42 /travel/japan/koyasan/okunoin-cemetery.html RU, Russian Federation 23/Sep/2023:09:38:37 /turkish/verbs.html RU, Russian Federation 23/Sep/2023:09:38:37 /travel/usa/us-wash-masonic.html RU, Russian Federation 23/Sep/2023:09:38:36 /travel/usa/new-york-st-marks-place/ RU, Russian Federation 23/Sep/2023:09:38:35 /travel/turkey/halicarnassus/ IE, Ireland 23/Sep/2023:09:38:18 /travel/france/budget-hotels/ FR, France 23/Sep/2023:09:38:10 /travel/romania/bucharest/ MD, Moldova, Republic of 23/Sep/2023:09:36:57 /travel/egypt/sinai.html JO, Jordan 23/Sep/2023:09:36:48 / JO, Jordan 23/Sep/2023:09:36:48 / US, United States 23/Sep/2023:09:36:32 /radio/copper-wire/?s=mb IE, Ireland 23/Sep/2023:09:36:23 /travel/uk/glastonbury/chalice-spring-tor.html US, United States 23/Sep/2023:09:36:21 /technical/current-box.html?s=mb US, United States 23/Sep/2023:09:36:19 /travel/france/budget-hotels/ US, United States 23/Sep/2023:09:36:14 /travel/france/pierre-tourneresse/ US, United States 23/Sep/2023:09:36:09 /fun/requests-for-quotes/seman-peru/ US, United States 23/Sep/2023:09:36:08 /travel/uk/orkney-sousterrain/ US, United States 23/Sep/2023:09:36:08 /travel/france/provence-megaliths/ US, United States 23/Sep/2023:09:36:07 /travel/uk/skara-brae/ US, United States 23/Sep/2023:09:36:05 /travel/uk/orkney-neolithic/maeshowe.html US, United States 23/Sep/2023:09:36:03 / US, United States 23/Sep/2023:09:35:44 /networking/commands.html US, United States 23/Sep/2023:09:35:42 /robots.txt US, United States 23/Sep/2023:09:35:34 /open-source/performance-tuning/ethernet.html US, United States 23/Sep/2023:09:35:32 /open-source/thunderbird-default-browser.html?s=mc US, United States 23/Sep/2023:09:35:26 /travel/uk/glastonbury/chalice-spring-tor.html SG, Singapore 23/Sep/2023:09:35:16 /travel/uk/glastonbury/chalice-spring-tor.html US, United States 23/Sep/2023:09:34:57 /travel/hungary/budapest/?s=mb MD, Moldova, Republic of 23/Sep/2023:09:34:34 /travel/usa/north-carolina/ AU, Australia 23/Sep/2023:09:34:32 /travel/uk/glastonbury/chalice-spring-tor.html US, United States 23/Sep/2023:09:34:30 /travel/egypt/aswan.html US, United States 23/Sep/2023:09:34:29 /travel/france/budget-hotels/ DE, Germany 23/Sep/2023:09:34:29 /travel/france/budget-hotels/ US, United States 23/Sep/2023:09:34:28 /travel/france/budget-hotels/ AU, Australia 23/Sep/2023:09:34:20 /travel/france/budget-hotels/ FR, France 23/Sep/2023:09:34:09 /technical/dsl/ DE, Germany 23/Sep/2023:09:33:49 /technical/dsl/ MD, Moldova, Republic of 23/Sep/2023:09:33:27 /travel/france/boat/tying-up-and-weather.html US, United States 23/Sep/2023:09:33:07 /travel/russia/ US, United States 23/Sep/2023:09:32:51 /cybersecurity/isc2-ccsp/ IE, Ireland 23/Sep/2023:09:32:42 / US, United States 23/Sep/2023:09:32:16 /open-source/performance-tuning/nfs.html FR, France 23/Sep/2023:09:31:58 /travel/usa/philadelphia/ SA, Saudi Arabia 23/Sep/2023:09:31:55 /turkish/word-order.html GB, United Kingdom 23/Sep/2023:09:29:41 /travel/france/normandy/pegasus-bridge.html GB, United Kingdom 23/Sep/2023:09:29:22 /travel/france/normandy/pegasus-bridge.html US, United States 23/Sep/2023:09:29:16 /travel/france/marseille/vieux-port.html US, United States 23/Sep/2023:09:29:15 /travel/france/school-lunch-menus/ US, United States 23/Sep/2023:09:29:00 /travel/trinidad/job.html US, United States 23/Sep/2023:09:28:53 /open-source/windows-path.html US, United States 23/Sep/2023:09:28:14 / US, United States 23/Sep/2023:09:28:08 /robots.txt Unknown 23/Sep/2023:09:27:52 /travel/uk/orkney-sousterrain/ FR, France 23/Sep/2023:09:27:39 /open-source/performance-tuning/file-systems.html US, United States 23/Sep/2023:09:27:09 /cybersecurity/isc2-ccsp/?s=tb US, United States 23/Sep/2023:09:26:58 /travel/alaska/november/ RU, Russian Federation 23/Sep/2023:09:26:24 /open-source/samba-active-directory/deployment.html US, United States 23/Sep/2023:09:26:14 /cybersecurity/crypto/cipher-strength.html US, United States 23/Sep/2023:09:25:51 /travel/france/seine-river-art-history-monet/chateau-gaillard.html PK, Pakistan 23/Sep/2023:09:25:19 /technical/dsl/ FR, France 23/Sep/2023:09:25:19 /travel/greece/meteora.html US, United States 23/Sep/2023:09:24:17 /robots.txt US, United States 23/Sep/2023:09:24:17 /robots.txt IE, Ireland 23/Sep/2023:09:23:54 /travel/turkey/konya/ US, United States 23/Sep/2023:09:23:53 /open-source/vim-word-count.html US, United States 23/Sep/2023:09:23:21 /travel/uk/orkney-sousterrain/ RU, Russian Federation 23/Sep/2023:09:22:59 /travel/alaska/equinox/ DE, Germany 23/Sep/2023:09:22:58 /open-source/raspberry-pi/sdr-getting-started.html US, United States 23/Sep/2023:09:22:35 /cybersecurity/crypto/diffie-hellman.html

Here's what's going on.

Each line above is a request from a client, extracted from Nginx's /var/www/logs/httpd-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.

Geolocate IP

You can use a service such as Abstract's IP geolocation to check if the conversion was successful, or if the client IP address is the exit portal of a VPN.

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