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?

Maybe...

First, let's look at the result, then the explanation comes later. Here are the 200 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.

54.204.185.160 US, United States 24/Jan/2017:11:14:23 /cybersecurity/physical.html
157.55.39.63 US, United States 24/Jan/2017:11:14:17 /linux/virtualbox-build.html
54.204.185.160 US, United States 24/Jan/2017:11:14:16 /travel/usa/new-york-mudd-club/Index.html
54.204.185.160 US, United States 24/Jan/2017:11:14:10 /cybersecurity/netusers/Index/bq
54.204.185.160 US, United States 24/Jan/2017:11:14:09 /robots.txt
72.21.217.97 US, United States 24/Jan/2017:11:14:03 /technical/html4-or-xhtml-to-html5.html
54.242.26.237 US, United States 24/Jan/2017:11:14:03 /technical/html4-or-xhtml-to-html5.html
93.108.247.117 PT, Portugal 24/Jan/2017:11:14:01 /technical/html4-or-xhtml-to-html5.html
90.36.96.47 FR, France 24/Jan/2017:11:13:59 /
90.36.96.47 FR, France 24/Jan/2017:11:13:58 /radio/probes.html
83.191.54.212 ES, Spain 24/Jan/2017:11:13:53 /turkish/language-reform.html
66.102.6.69 US, United States 24/Jan/2017:11:13:44 /linux/sysfs.html
189.48.111.35 BR, Brazil 24/Jan/2017:11:13:44 /cybersecurity/netusers/data/pt
98.15.34.244 US, United States 24/Jan/2017:11:13:42 /cybersecurity/ec2-secure-storage.html
46.242.9.241 Unknown 24/Jan/2017:11:13:28 /travel/usa/us-wash-masonic.html
217.70.211.10 NL, Netherlands 24/Jan/2017:11:13:17 /linux/performance-tuning/disks.html
83.191.54.212 ES, Spain 24/Jan/2017:11:12:42 /turkish/word-order.html
137.193.138.131 DE, Germany 24/Jan/2017:11:12:37 /cybersecurity/linux-hardening.html
35.157.93.202 US, United States 24/Jan/2017:11:12:05 /linux/linux-alpha.html
35.157.93.202 US, United States 24/Jan/2017:11:12:04 /robots.txt
178.255.215.98 Unknown 24/Jan/2017:11:11:37 /networking/protocols.html
46.242.9.241 Unknown 24/Jan/2017:11:11:24 /travel/usa/us-wash-masonic.html
109.96.154.154 Unknown 24/Jan/2017:11:10:50 /technical/samsung-galaxy/cyanogenmod.html
66.249.69.237 US, United States 24/Jan/2017:11:10:48 /
69.64.15.74 US, United States 24/Jan/2017:11:10:13 /3d/histogram/
66.146.250.45 US, United States 24/Jan/2017:11:09:43 /fun/requests-for-quotes/tongan-misdirection/
80.250.30.195 CZ, Czech Republic 24/Jan/2017:11:08:46 /technical/ata-ide-sata-usb-cable-pinouts.html
208.15.130.35 US, United States 24/Jan/2017:11:08:32 /russian/grammar.html
213.55.105.250 ET, Ethiopia 24/Jan/2017:11:07:04 /technical/ata-ide-sata-usb-cable-pinouts.html
209.190.95.34 US, United States 24/Jan/2017:11:06:48 /cybersecurity/password.html
37.220.24.178 Unknown 24/Jan/2017:11:05:57 /cybersecurity/root-password.html
66.249.69.128 US, United States 24/Jan/2017:11:05:56 /travel/usa/north-carolina/
60.50.94.63 MY, Malaysia 24/Jan/2017:11:05:35 /technical/dsl/
42.120.160.79 Unknown 24/Jan/2017:11:04:52 /cybersecurity/
103.16.183.246 Unknown 24/Jan/2017:11:04:22 /cybersecurity/monitoring.html
123.125.67.224 CN, China 24/Jan/2017:11:04:21 /robots.txt
52.23.205.66 US, United States 24/Jan/2017:11:04:20 /
68.180.228.158 US, United States 24/Jan/2017:11:04:07 /brewing/brewing-references.html
179.176.113.206 Unknown 24/Jan/2017:11:03:42 /
179.176.113.206 Unknown 24/Jan/2017:11:03:42 /radio/probes.html
149.71.207.12 US, United States 24/Jan/2017:11:03:05 /linux/digital-camera.html
98.250.32.13 US, United States 24/Jan/2017:11:01:45 /technical/samsung-galaxy/secret-code.html
123.126.68.103 CN, China 24/Jan/2017:11:01:37 /linux/openbsd-qemu-windows-howto.html
66.249.69.131 US, United States 24/Jan/2017:11:01:04 /travel/greece/mycenae.html
185.22.226.96 Unknown 24/Jan/2017:11:00:58 /travel/uk/dover/
95.120.61.210 Unknown 24/Jan/2017:10:59:57 /technical/samsung-galaxy/block-calls.html
123.126.68.103 CN, China 24/Jan/2017:10:59:13 /linux/openbsd-qemu-windows-howto.html
89.145.95.78 GB, United Kingdom 24/Jan/2017:10:59:08 /cybersecurity/netusers/Index/sa
54.236.1.11 US, United States 24/Jan/2017:10:58:59 /travel/egypt/luxor.html
64.202.160.92 US, United States 24/Jan/2017:10:58:22 /linux/rhel-centos-5-6-7/
64.202.160.92 US, United States 24/Jan/2017:10:58:21 /linux/rhel-centos-5-6-7/
141.0.12.198 DE, Germany 24/Jan/2017:10:58:08 /oliver-cromwell/crom-fu-fighting.html
89.98.174.202 NL, Netherlands 24/Jan/2017:10:58:06 /
85.116.200.16 DE, Germany 24/Jan/2017:10:57:51 /linux/rhel-centos-multimedia.html
201.134.170.15 MX, Mexico 24/Jan/2017:10:57:40 /cybersecurity/forensics.html
24.246.121.130 US, United States 24/Jan/2017:10:57:07 /travel/france/normandy/pegasus-bridge.html
37.220.24.178 Unknown 24/Jan/2017:10:56:23 /
66.249.69.131 US, United States 24/Jan/2017:10:56:12 /technical/convert-youtube-to-xvid.html
37.220.24.178 Unknown 24/Jan/2017:10:55:57 /
141.0.12.198 DE, Germany 24/Jan/2017:10:55:46 /oliver-cromwell/crom-fu-fighting.html
205.170.35.254 US, United States 24/Jan/2017:10:55:26 /3d/xray/film.html
141.0.12.198 DE, Germany 24/Jan/2017:10:55:25 /oliver-cromwell/crom-fu-fighting.html
52.91.184.26 US, United States 24/Jan/2017:10:55:09 /cybersecurity/netusers/Index/sa
54.205.167.47 US, United States 24/Jan/2017:10:55:07 /cybersecurity/netusers/Index/sa
72.21.217.83 US, United States 24/Jan/2017:10:55:05 /cybersecurity/netusers/Index/sa
66.249.91.67 US, United States 24/Jan/2017:10:55:05 /cybersecurity/netusers/Index/sa
72.21.217.159 US, United States 24/Jan/2017:10:55:04 /cybersecurity/netusers/Index/sa
72.21.217.131 US, United States 24/Jan/2017:10:55:03 /cybersecurity/netusers/Index/sa
174.52.182.203 US, United States 24/Jan/2017:10:55:03 /
174.52.182.203 US, United States 24/Jan/2017:10:55:02 /cybersecurity/netusers/Index/sa
72.21.217.77 US, United States 24/Jan/2017:10:54:48 /oliver-cromwell/crom-fu-fighting.html
141.0.12.198 DE, Germany 24/Jan/2017:10:54:43 /oliver-cromwell/crom-fu-fighting.html
149.71.205.9 US, United States 24/Jan/2017:10:54:37 /3d/xray/scanning.html
207.11.1.164 US, United States 24/Jan/2017:10:54:33 /linux/windows-path.html
123.30.175.170 VN, Vietnam 24/Jan/2017:10:54:07 /linux/openbsd-qemu-windows-howto.html
123.30.175.170 VN, Vietnam 24/Jan/2017:10:54:05 /
123.30.175.168 VN, Vietnam 24/Jan/2017:10:54:03 /robots.txt
192.12.184.6 US, United States 24/Jan/2017:10:53:39 /linux/rhel-centos-5-6-7/
213.92.157.74 PL, Poland 24/Jan/2017:10:53:13 /
213.92.157.74 PL, Poland 24/Jan/2017:10:53:13 /radio/probes.html
31.217.176.218 US, United States 24/Jan/2017:10:52:59 /
85.116.200.16 DE, Germany 24/Jan/2017:10:52:51 /linux/rhel-centos-multimedia.html
68.180.228.234 US, United States 24/Jan/2017:10:52:29 /travel/poland/
109.89.74.98 Unknown 24/Jan/2017:10:52:09 /travel/usa/us-wash-masonic.html
31.217.176.213 US, United States 24/Jan/2017:10:52:04 /
149.71.207.33 US, United States 24/Jan/2017:10:51:50 /networking/
212.47.223.17 EE, Estonia 24/Jan/2017:10:51:29 /cybersecurity/hacker-passwords.html
90.44.1.143 FR, France 24/Jan/2017:10:51:27 /travel/belgium/art-nouveau-architecture/
66.249.69.128 US, United States 24/Jan/2017:10:51:20 /technical/dct-2000.html
122.169.231.167 IN, India 24/Jan/2017:10:51:05 /
122.169.231.167 IN, India 24/Jan/2017:10:51:04 /radio/probes.html
90.44.1.143 FR, France 24/Jan/2017:10:50:42 /travel/belgium/art-nouveau-architecture/
136.243.75.15 DE, Germany 24/Jan/2017:10:50:40 /travel/belgium/art-nouveau-architecture/
138.162.0.42 US, United States 24/Jan/2017:10:50:35 /technical/dsl/
90.44.1.143 FR, France 24/Jan/2017:10:50:35 /travel/belgium/art-nouveau-architecture/
207.241.231.145 US, United States 24/Jan/2017:10:49:20 /cybersecurity/privacy-policy.html
90.91.205.39 FR, France 24/Jan/2017:10:49:01 /russian/grammar.html
54.236.1.11 US, United States 24/Jan/2017:10:48:39 /cybersecurity/history/uk-wwii.html
72.21.217.105 US, United States 24/Jan/2017:10:47:13 /cybersecurity/
180.245.198.5 Unknown 24/Jan/2017:10:47:06 /cybersecurity/
52.91.184.26 US, United States 24/Jan/2017:10:46:38 /travel/turkey/trains/
72.21.217.100 US, United States 24/Jan/2017:10:46:34 /travel/turkey/trains/
72.21.217.100 US, United States 24/Jan/2017:10:46:33 /robots.txt
72.21.217.105 US, United States 24/Jan/2017:10:46:32 /travel/turkey/trains/
72.21.217.109 US, United States 24/Jan/2017:10:46:32 /travel/turkey/trains/
66.249.69.128 US, United States 24/Jan/2017:10:46:29 /travel/turkey/trains/
68.180.228.158 US, United States 24/Jan/2017:10:44:43 /travel/poland/
38.68.201.200 US, United States 24/Jan/2017:10:44:13 /turkish/turkish-suffixes.html
52.91.182.1 US, United States 24/Jan/2017:10:44:11 /3d/
52.91.182.1 US, United States 24/Jan/2017:10:44:10 /robots.txt
154.241.151.247 Unknown 24/Jan/2017:10:42:36 /
154.241.151.247 Unknown 24/Jan/2017:10:42:34 /radio/probes.html
123.125.71.105 CN, China 24/Jan/2017:10:42:24 /robots.txt
66.249.69.128 US, United States 24/Jan/2017:10:41:37 /travel/belgium/art-nouveau-architecture/
216.54.18.98 US, United States 24/Jan/2017:10:41:28 /linux/system-administration.html
216.54.18.98 US, United States 24/Jan/2017:10:41:27 /linux/system-administration.html
123.126.113.167 CN, China 24/Jan/2017:10:41:22 /travel/uk/swingate-chain-home/
91.196.60.247 UA, Ukraine 24/Jan/2017:10:41:09 /radio/probes.html
52.3.127.144 US, United States 24/Jan/2017:10:40:53 /3d/xray/
123.201.91.158 IN, India 24/Jan/2017:10:40:51 /
123.201.91.158 IN, India 24/Jan/2017:10:40:50 /radio/probes.html
212.95.166.50 BG, Bulgaria 24/Jan/2017:10:40:20 /technical/ata-ide-sata-usb-cable-pinouts.html
54.198.106.253 US, United States 24/Jan/2017:10:39:39 /cybersecurity/hardware.html
180.76.15.20 Unknown 24/Jan/2017:10:39:29 /
52.3.127.144 US, United States 24/Jan/2017:10:39:13 /robots.txt
178.166.121.63 Unknown 24/Jan/2017:10:39:08 /
178.166.121.63 Unknown 24/Jan/2017:10:39:07 /radio/probes.html
180.76.15.162 Unknown 24/Jan/2017:10:38:28 /
207.246.97.178 US, United States 24/Jan/2017:10:38:12 /3d/xray/film.html
52.87.238.23 US, United States 24/Jan/2017:10:38:11 /travel/turkey/
72.21.217.71 US, United States 24/Jan/2017:10:38:10 /travel/turkey/
105.101.81.182 Unknown 24/Jan/2017:10:37:59 /turkish/verbs.html
90.176.88.1 CZ, Czech Republic 24/Jan/2017:10:37:37 /linux/openbsd-qemu-windows-howto.html
100.43.90.13 Unknown 24/Jan/2017:10:36:48 /robots.txt
2.107.219.146 Unknown 24/Jan/2017:10:36:45 /linux/openbsd-wireless-wpa2.html
66.249.69.131 US, United States 24/Jan/2017:10:36:45 /networking/wan-specs.html
68.180.228.158 US, United States 24/Jan/2017:10:35:53 /technical/
192.88.168.43 US, United States 24/Jan/2017:10:35:34 /networking/nat.html
200.61.32.254 AR, Argentina 24/Jan/2017:10:35:06 /linux/performance-tuning/nfs.html
66.130.101.89 CA, Canada 24/Jan/2017:10:32:53 /
66.130.101.89 CA, Canada 24/Jan/2017:10:32:52 /radio/probes.html
68.180.228.158 US, United States 24/Jan/2017:10:32:51 /travel/usa/philadelphia/
123.126.113.167 CN, China 24/Jan/2017:10:32:30 /travel/uk/swingate-chain-home/
149.71.254.27 US, United States 24/Jan/2017:10:32:20 /cybersecurity/root-password.html
66.249.69.131 US, United States 24/Jan/2017:10:31:53 /cybersecurity/stack-hardening.html
160.44.224.7 DE, Germany 24/Jan/2017:10:31:46 /linux/performance-tuning/file-systems.html
82.81.83.56 IL, Israel 24/Jan/2017:10:31:41 /linux/performance-tuning/file-systems.html
123.126.113.167 CN, China 24/Jan/2017:10:31:26 /technical/samsung-galaxy/linux.html
80.242.194.19 CH, Switzerland 24/Jan/2017:10:31:20 /networking/what-is-ipsec.html
72.21.217.97 US, United States 24/Jan/2017:10:31:17 /travel/france/thomas-jefferson/
72.21.217.153 US, United States 24/Jan/2017:10:31:16 /travel/france/thomas-jefferson/
50.73.106.93 Unknown 24/Jan/2017:10:31:15 /travel/france/thomas-jefferson/
220.181.108.144 CN, China 24/Jan/2017:10:31:04 /
54.89.94.226 US, United States 24/Jan/2017:10:30:19 /cybersecurity/netaudit.html
93.51.223.118 IT, Italy 24/Jan/2017:10:30:02 /radio/hf-short-dipoles.html
93.245.29.219 DE, Germany 24/Jan/2017:10:29:55 /

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, 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-xs-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