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?

Maybe...

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.

217.182.197.147 DE, Germany 20/Oct/2021:02:47:18 /ads.txt
3.236.165.32 US, United States 20/Oct/2021:02:47:15 /open-source/sysfs.html
199.189.86.33 US, United States 20/Oct/2021:02:47:14 /3d/histogram/
66.102.8.164 US, United States 20/Oct/2021:02:47:06 /travel/greece/meteora.html?s=tb
163.114.132.3 FR, France 20/Oct/2021:02:47:06 /open-source/sysfs.html
35.203.245.179 US, United States 20/Oct/2021:02:47:06 /travel/greece/meteora.html
35.203.245.179 US, United States 20/Oct/2021:02:47:05 /travel/greece/meteora.html?s=tb
95.216.226.118 FI, Finland 20/Oct/2021:02:47:04 /open-source/raspberry-pi/sdr-getting-started.html
18.206.245.90 US, United States 20/Oct/2021:02:46:36 /travel/greece/meteora.html?s=tb
3.235.179.111 US, United States 20/Oct/2021:02:46:04 /travel/latvia/
100.37.252.164 US, United States 20/Oct/2021:02:46:00 /travel/usa/new-york-internet/
47.186.175.119 US, United States 20/Oct/2021:02:45:35 /
17.121.112.101 US, United States 20/Oct/2021:02:45:06 /travel/greece/meteora.html?s=tb
203.89.68.178 AU, Australia 20/Oct/2021:02:44:38 /
144.76.22.137 DE, Germany 20/Oct/2021:02:44:35 /travel/greece/meteora.html?s=tb
66.249.79.232 US, United States 20/Oct/2021:02:44:27 /technical/how-to-copy-dvds.html
3.218.77.26 US, United States 20/Oct/2021:02:44:22 /travel/greece/meteora.html?s=tb
204.15.208.25 Unknown 20/Oct/2021:02:44:14 /open-source/raspberry-pi/sdr-getting-started.html
3.235.179.111 US, United States 20/Oct/2021:02:44:10 /cybersecurity/cloud-survey.html
152.228.167.63 US, United States 20/Oct/2021:02:44:07 /travel/greece/meteora.html?s=tb
54.39.50.78 CA, Canada 20/Oct/2021:02:44:03 /travel/greece/meteora.html?s=tb
51.161.115.227 FR, France 20/Oct/2021:02:44:03 /travel/greece/meteora.html?s=tb
199.59.150.181 US, United States 20/Oct/2021:02:44:01 /travel/greece/meteora.html?s=tb
66.249.79.234 US, United States 20/Oct/2021:02:43:44 /text/reports/Pchechen.2.txt
50.96.150.144 US, United States 20/Oct/2021:02:43:29 /technical/dsl/
216.19.241.74 US, United States 20/Oct/2021:02:43:25 /open-source/xsane-invalid-argument.html
204.15.208.23 Unknown 20/Oct/2021:02:43:15 /turkish/verbs.html
74.119.119.42 US, United States 20/Oct/2021:02:42:40 /open-source/raspberry-pi/sdr-getting-started.html
74.119.118.51 US, United States 20/Oct/2021:02:42:27 /open-source/raspberry-pi/sdr-getting-started.html
3.235.179.111 US, United States 20/Oct/2021:02:42:13 /steampunk/
3.235.179.111 US, United States 20/Oct/2021:02:42:13 /robots.txt
118.96.62.76 ID, Indonesia 20/Oct/2021:02:42:02 /open-source/grub-vga-modes.html
184.72.115.35 US, United States 20/Oct/2021:02:41:55 /turkish/verbs.html
54.175.172.101 US, United States 20/Oct/2021:02:41:37 /open-source/raspberry-pi/sdr-getting-started.html
24.2.106.231 US, United States 20/Oct/2021:02:41:36 /open-source/raspberry-pi/sdr-getting-started.html
66.249.79.234 US, United States 20/Oct/2021:02:41:24 /
174.84.42.7 US, United States 20/Oct/2021:02:41:03 /open-source/rhel-oracle-centos-multimedia.html
103.14.140.18 NZ, New Zealand 20/Oct/2021:02:40:56 /networking/what-is-ipsec.html
198.148.27.45 US, United States 20/Oct/2021:02:40:18 /open-source/linux-pam-compliance/
198.148.27.37 US, United States 20/Oct/2021:02:40:17 /open-source/linux-pam-compliance/
184.170.175.197 US, United States 20/Oct/2021:02:40:08 /turkish/verbs.html
216.244.66.242 US, United States 20/Oct/2021:02:40:01 /travel/canada/ottawa/?s=tb
69.202.139.105 US, United States 20/Oct/2021:02:39:51 /open-source/
173.79.201.6 US, United States 20/Oct/2021:02:39:49 /turkish/verbs.html
69.202.139.105 US, United States 20/Oct/2021:02:39:46 /
65.93.207.247 CA, Canada 20/Oct/2021:02:39:27 /
69.202.139.105 US, United States 20/Oct/2021:02:38:52 /networking/
23.246.71.170 US, United States 20/Oct/2021:02:38:43 /radio/probes.html
69.171.231.5 US, United States 20/Oct/2021:02:38:41 /travel/athens-to-paris/athens-thessaloniki.html
66.102.8.164 US, United States 20/Oct/2021:02:38:18 /travel/france/detectives/?s=tb
107.178.231.224 US, United States 20/Oct/2021:02:38:17 /travel/france/detectives/
107.178.231.224 US, United States 20/Oct/2021:02:38:17 /travel/france/detectives/?s=tb
24.115.139.22 US, United States 20/Oct/2021:02:38:09 /
69.202.139.105 US, United States 20/Oct/2021:02:38:08 /radio/probes.html
24.115.139.22 US, United States 20/Oct/2021:02:37:59 /
88.98.119.252 ES, Spain 20/Oct/2021:02:37:58 /open-source/sysfs.html
88.98.119.252 ES, Spain 20/Oct/2021:02:37:58 /robots.txt
68.67.155.230 US, United States 20/Oct/2021:02:37:34 /ads.txt
69.202.139.105 US, United States 20/Oct/2021:02:37:31 /radio/
167.248.133.115 US, United States 20/Oct/2021:02:36:37 /
45.250.27.141 GB, United Kingdom 20/Oct/2021:02:35:58 /travel/japan/tokyo-asakusa/markets-and-streets.html?s=tb
108.26.241.227 US, United States 20/Oct/2021:02:34:48 /radio/copper-wire/
3.234.232.101 US, United States 20/Oct/2021:02:34:46 /radio/j-poles.html
216.244.66.242 US, United States 20/Oct/2021:02:34:41 /travel/latvia/?M=A
203.129.63.205 AU, Australia 20/Oct/2021:02:34:08 /open-source/ftp-howto.html
69.202.139.105 US, United States 20/Oct/2021:02:34:06 /cybersecurity/
54.89.128.195 US, United States 20/Oct/2021:02:33:37 /technical/bios.html
154.6.20.47 US, United States 20/Oct/2021:02:33:35 /technical/bios.html
64.137.96.196 US, United States 20/Oct/2021:02:33:17 /radio/j-poles.html
107.22.135.91 US, United States 20/Oct/2021:02:33:08 /radio/j-poles.html
72.140.109.235 CA, Canada 20/Oct/2021:02:33:05 /radio/j-poles.html
216.244.66.242 US, United States 20/Oct/2021:02:33:05 /oliver-cromwell/?D=D
40.77.167.64 US, United States 20/Oct/2021:02:32:51 /travel/france/seine-river-art-history-monet/la-roche-guyon.html
40.77.167.64 US, United States 20/Oct/2021:02:32:51 /travel/uk/scotland-isle-of-iona/iona.html
40.77.167.64 US, United States 20/Oct/2021:02:32:51 /travel/uk/skara-brae/
40.77.167.64 US, United States 20/Oct/2021:02:32:51 /travel/usa/new-york-hp-lovecraft/
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /travel/usa/new-york-roosevelts/
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /turkish/background.html
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /cybersecurity/root-password.html
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /cybersecurity/stack-hardening.html
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /open-source/multiboot-windows-openbsd/
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /open-source/sendmail-ssl.html
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /travel/athens-to-paris/gura-humorului-sighisoara.html
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /travel/backpack/
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /travel/belgium/bastogne-ardennes/ardennes-forest.html
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /travel/belgium/belgian-beers/absinthe-bar.html
40.77.167.64 US, United States 20/Oct/2021:02:32:50 /travel/canada/yukon/
40.77.167.64 US, United States 20/Oct/2021:02:32:49 /travel/china/
40.77.167.64 US, United States 20/Oct/2021:02:32:49 /travel/france/barbegal-les-baux-st-remy/
40.77.167.64 US, United States 20/Oct/2021:02:32:49 /travel/uk/orkney-sousterrain/
40.77.167.64 US, United States 20/Oct/2021:02:32:49 /travel/uk/glastonbury/wearyall-hill.html
40.77.167.64 US, United States 20/Oct/2021:02:32:49 /travel/uk/glastonbury/chalice-spring-tor.html
40.77.167.64 US, United States 20/Oct/2021:02:32:49 /travel/turkey/trains/
40.77.167.64 US, United States 20/Oct/2021:02:32:49 /fun/brilliant-movie-ideas/reality.html
51.91.209.130 FR, France 20/Oct/2021:02:32:45 /travel/france/detectives/?s=tb
40.77.167.8 US, United States 20/Oct/2021:02:32:43 /travel/uk/the-road-to-the-isles/glen-nevis-fort-william.html
40.77.167.8 US, United States 20/Oct/2021:02:32:43 /travel/usa/san-francisco-dashiell-hammett/
40.77.167.8 US, United States 20/Oct/2021:02:32:43 /open-source/keyboard-mouse.html
40.77.167.8 US, United States 20/Oct/2021:02:32:42 /travel/chile/valparaiso/
40.77.167.8 US, United States 20/Oct/2021:02:32:42 /cybersecurity/infosec-response.html
40.77.167.8 US, United States 20/Oct/2021:02:32:42 /cybersecurity/attack-study/
216.244.66.242 US, United States 20/Oct/2021:02:32:42 /travel/usa/new-york-sro-flophouses/white-house-tour.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/italy/umbria/
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/japan/ise/wedded-rocks.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/japan/katakana-hiragana/
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/japan/shinto-buddhism/shinto.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/mexico/teotihuacan.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/replace-sim-card/
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/usa/new-york-hunter-s-thompson/
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/usa/new-york-sro-flophouses/
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /turkish/
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /open-source/dev-random.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /open-source/getting-started.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /open-source/ipv6-comcast-surfboard.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /open-source/nginx-tls-1.3/
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /radio/copper-wire/
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/france/boat-trip-canal-lateral-a-la-loire/briare-to-beaulieu-sur-loire.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /cybersecurity/crypto/hash.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /cybersecurity/cipher-selection.html
207.46.13.150 US, United States 20/Oct/2021:02:32:24 /travel/uk/london-underground/
40.77.167.35 US, United States 20/Oct/2021:02:32:19 /open-source/linux-pam-compliance/
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /travel/france/normandy/omaha-beach.html
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /travel/france/normandy/reenactors.html
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /travel/uk/swingate-chain-home/
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /travel/usa/new-york-humphrey-bogart/
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /digsig/
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /fun/teaching/us-vs-britain-vs-france.html
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /technical/ata-ide-sata-usb-cable-pinouts.html
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /travel/france/budget-hotels/
207.46.13.15 US, United States 20/Oct/2021:02:32:16 /travel/uk/orkney-west-coast-walk/
42.190.15.18 MY, Malaysia 20/Oct/2021:02:32:13 /open-source/performance-tuning/tcp.html
40.77.167.35 US, United States 20/Oct/2021:02:31:59 /travel/egypt/giza.html
40.77.167.73 US, United States 20/Oct/2021:02:31:59 /travel/france/saumur-megaliths/
40.77.167.73 US, United States 20/Oct/2021:02:31:59 /travel/japan/tokyo-shinjuku/
40.77.167.73 US, United States 20/Oct/2021:02:31:59 /travel/poland/
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /travel/usa/new-york-black-chamber/
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /travel/usa/us-wash-masonic.html
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /open-source/lvm-rescue-boot.html
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /open-source/performance-tuning/file-systems.html
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /open-source/unix-tips.html
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /radio/frequencies.html
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /travel/belgium/bastogne-ardennes/
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /cybersecurity/
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /cybersecurity/comptia/
40.77.167.73 US, United States 20/Oct/2021:02:31:58 /cybersecurity/cloud.html
40.77.167.73 US, United States 20/Oct/2021:02:31:57 /cybersecurity/
40.77.167.73 US, United States 20/Oct/2021:02:31:57 /cybersecurity/
40.77.167.73 US, United States 20/Oct/2021:02:31:57 /cybersecurity/
40.77.167.73 US, United States 20/Oct/2021:02:31:57 /travel/uk/bletchley-park/
40.77.167.73 US, United States 20/Oct/2021:02:31:57 /travel/turkey/pamukkale/
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /travel/italy/driving.html
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /travel/japan/tokyo-shibuya/
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /travel/russia/sankt-peterburg.html
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /fun/requests-for-quotes/marlow-willard/
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /travel/usa/new-york-jewish-les/houston-clinton-norfolk.html
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /wshta/
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /travel/turkey/buses/
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /travel/turkey/hans/
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /travel/egypt/sinai.html
40.77.167.7 US, United States 20/Oct/2021:02:31:40 /open-source/samba-active-directory/freebsd-raspberry-pi.html
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /open-source/stig-compliance.html
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /radio/hfqrp.html
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /technical/search-engine-optimization-howto.html
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /travel/athens-to-paris/budapest-prague.html
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /travel/athens-to-paris/veliko-tarnovo-bucharest.html
40.77.167.35 US, United States 20/Oct/2021:02:31:39 /travel/estonia/
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /travel/belgium/art-nouveau-architecture/
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /fun/requests-for-quotes/bahrain/
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /brewing/brewing-log.html
40.77.167.7 US, United States 20/Oct/2021:02:31:39 /brewing/how-to-brew-mead.html
34.229.218.237 US, United States 20/Oct/2021:02:31:28 /travel/france/detectives/?s=tb
40.77.167.2 US, United States 20/Oct/2021:02:31:24 /travel/japan/kamakura/engaku-ji.html
40.77.167.2 US, United States 20/Oct/2021:02:31:23 /travel/romania/food/

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, 20.0.0.0/8 through 40.0.0.0/8 are orange shifting to yellow, 50.0.0.0/8 through 110.0.0.0/8 are shades of green, the /16 networks 130.0.0.0/16 through about 180.0.0.0/16 are shades of blue, then it's shades of purple into magenta for the /24 networks 192.0.0.0/24 and up through 223.255.255.0/24.

The HTML file on the server has a line where PHP uses passthru() to call the following shell script:

#!/bin/sh

# 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' |
	while read IP1 IP2 IP3 IP4 CLIENTIP TIMESTAMP URL
	do
		COUNTRY=$( geoiplookup $CLIENTIP |
				sed 's/.*Edition: //' |
				sed 's/IP Address not found/Unknown/' )
		echo $IP1 $IP2 $IP3 $IP4 $CLIENTIP $COUNTRY $TIMESTAMP $URL |
		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);
			}
			printf("</div>\n");
		}'
	done 

Other Pages