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. SE, Sweden 27/Jul/2021:10:42:52 /open-source/performance-tuning/nfs.html ZA, South Africa 27/Jul/2021:10:42:40 /open-source/performance-tuning/ ZA, South Africa 27/Jul/2021:10:42:39 /open-source/performance-tuning/tcp.html JP, Japan 27/Jul/2021:10:42:31 /open-source/rpm-patch.html JP, Japan 27/Jul/2021:10:42:29 /open-source/rpm-patch.html FR, France 27/Jul/2021:10:41:21 /travel/japan/wwii-cryptanalysis/ US, United States 27/Jul/2021:10:41:16 /travel/greece/trains.html US, United States 27/Jul/2021:10:41:15 /travel/latvia/ IT, Italy 27/Jul/2021:10:41:13 /travel/greece/trains.html US, United States 27/Jul/2021:10:40:54 /text/reports/0tramp.1.txt FR, France 27/Jul/2021:10:40:49 /travel/france/saumur-megaliths/ MD, Moldova, Republic of 27/Jul/2021:10:40:32 /travel/japan/ US, United States 27/Jul/2021:10:39:17 /technical/ata-ide-sata-usb-cable-pinouts.html US, United States 27/Jul/2021:10:39:09 /cybersecurity/cloud-survey.html US, United States 27/Jul/2021:10:39:09 /robots.txt DE, Germany 27/Jul/2021:10:39:08 /technical/hp-printer-ready-message.html UA, Ukraine 27/Jul/2021:10:38:42 /open-source/performance-tuning/ethernet.html US, United States 27/Jul/2021:10:38:38 /turkish/verbs.html CN, China 27/Jul/2021:10:38:23 /travel/turkey/temple-of-artemis/ DE, Germany 27/Jul/2021:10:38:17 /open-source/performance-tuning/nfs.html FI, Finland 27/Jul/2021:10:38:00 /open-source/rpm-patch.html DE, Germany 27/Jul/2021:10:37:53 /travel/france/school-lunch-menus/?s=tb DE, Germany 27/Jul/2021:10:37:53 /robots.txt MD, Moldova, Republic of 27/Jul/2021:10:35:59 /technical/samsung-galaxy/rip-cyanogenmod.html US, United States 27/Jul/2021:10:35:31 /travel/chile/rancagua/ US, United States 27/Jul/2021:10:35:30 /travel/chile/rancagua/?s=tb US, United States 27/Jul/2021:10:35:18 / US, United States 27/Jul/2021:10:34:53 /open-source/rpm-patch.html FR, France 27/Jul/2021:10:34:52 /travel/uk/ben-nevis/ US, United States 27/Jul/2021:10:34:50 /turkish/ US, United States 27/Jul/2021:10:34:37 /open-source/rpm-patch.html FR, France 27/Jul/2021:10:34:22 /cybersecurity/comptia/domain-1.html US, United States 27/Jul/2021:10:34:12 /cybersecurity/telecom-outages.html MD, Moldova, Republic of 27/Jul/2021:10:34:06 /cybersecurity/isc2-ccsp/ SE, Sweden 27/Jul/2021:10:33:51 /radio/9-1-unun/ US, United States 27/Jul/2021:10:33:32 /cybersecurity/telecom-outages.html US, United States 27/Jul/2021:10:33:29 /cybersecurity/telecom-outages.html ZA, South Africa 27/Jul/2021:10:33:14 /cybersecurity/telecom-outages.html PH, Philippines 27/Jul/2021:10:33:04 /travel/france/marseille/vieux-port.html US, United States 27/Jul/2021:10:32:44 /cybersecurity/isc2-ccsp/ RU, Russian Federation 27/Jul/2021:10:32:34 /robots.txt US, United States 27/Jul/2021:10:31:43 /cybersecurity/yubikey/pam_pkcs11.html GB, United Kingdom 27/Jul/2021:10:31:12 /networking/nat.html IN, India 27/Jul/2021:10:30:10 /open-source/windows-path.html FR, France 27/Jul/2021:10:29:49 /travel/uk/glastonbury/chalice-spring-tor.html US, United States 27/Jul/2021:10:29:17 /travel/uk/glastonbury/chalice-spring-tor.html GB, United Kingdom 27/Jul/2021:10:29:09 /travel/uk/glastonbury/chalice-spring-tor.html FR, France 27/Jul/2021:10:28:28 /open-source/rhel-centos-oracle-5-6-7-8/logging.html CN, China 27/Jul/2021:10:28:11 /travel/usa/new-york-hunter-s-thompson/ US, United States 27/Jul/2021:10:27:44 /travel/greece/mykonos.html CH, Switzerland 27/Jul/2021:10:27:34 /travel/greece/mykonos.html IE, Ireland 27/Jul/2021:10:27:25 /open-source/ssh-2-access-control.html US, United States 27/Jul/2021:10:27:04 /cybersecurity/comptia/ US, United States 27/Jul/2021:10:26:57 /cybersecurity/comptia/ RU, Russian Federation 27/Jul/2021:10:26:57 /cybersecurity/ssl-tls.html CZ, Czech Republic 27/Jul/2021:10:26:52 /travel/uk/hadrians-wall/ CZ, Czech Republic 27/Jul/2021:10:26:51 /networking/ip-addresses-and-subnets.html CZ, Czech Republic 27/Jul/2021:10:26:50 /technical/samsung-galaxy/sim-unlocking.html CZ, Czech Republic 27/Jul/2021:10:26:49 /robots.txt US, United States 27/Jul/2021:10:26:33 /travel/usa/new-york-phone-booths/ HK, Hong Kong 27/Jul/2021:10:26:17 /cybersecurity/hostile/mirai.html CN, China 27/Jul/2021:10:26:06 /travel/turkey/konya/?s=tb US, United States 27/Jul/2021:10:25:52 /travel/canada/ottawa/?s=tb HK, Hong Kong 27/Jul/2021:10:25:31 /cybersecurity/hostile/mirai.html US, United States 27/Jul/2021:10:25:17 /open-source/qemu-unix.html US, United States 27/Jul/2021:10:25:15 /open-source/font-config-warnings.html MD, Moldova, Republic of 27/Jul/2021:10:24:49 /cybersecurity/attack-study/ DE, Germany 27/Jul/2021:10:23:50 /open-source/ssh-2-access-control.html CN, China 27/Jul/2021:10:23:48 /travel/trinidad/port-of-spain.html FR, France 27/Jul/2021:10:23:30 /open-source/performance-tuning/file-systems.html US, United States 27/Jul/2021:10:22:46 /travel/japan/nikko/other-sites.html?s=tb TR, Turkey 27/Jul/2021:10:22:41 /contact.html TR, Turkey 27/Jul/2021:10:22:40 /travel/usa/new-york-roosevelts/ FR, France 27/Jul/2021:10:22:35 /cybersecurity/comptia/domain-4.html US, United States 27/Jul/2021:10:22:23 /open-source/performance-tuning/tcp.html CN, China 27/Jul/2021:10:22:18 /travel/japan/nagasaki/temples-in-the-rain.html FR, France 27/Jul/2021:10:22:14 /cybersecurity/root-password.html FI, Finland 27/Jul/2021:10:22:00 /cybersecurity/root-password.html RU, Russian Federation 27/Jul/2021:10:21:44 /cybersecurity/exam-prep.html AU, Australia 27/Jul/2021:10:20:17 /open-source/performance-tuning/disks.html AU, Australia 27/Jul/2021:10:19:51 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:51 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:51 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:51 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:51 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:51 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:51 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:51 /open-source/samba-active-directory/samba.html Unknown 27/Jul/2021:10:19:50 /cybersecurity/root-password.html AU, Australia 27/Jul/2021:10:19:43 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:43 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:43 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:43 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:43 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:43 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:43 /open-source/samba-active-directory/samba.html AU, Australia 27/Jul/2021:10:19:43 /open-source/samba-active-directory/samba.html GB, United Kingdom 27/Jul/2021:10:19:38 /technical/dsl/ CN, China 27/Jul/2021:10:19:34 /travel/chile/rancagua/?s=tb US, United States 27/Jul/2021:10:19:29 /open-source/qemu-unix.html AT, Austria 27/Jul/2021:10:19:24 /open-source/qemu-unix.html US, United States 27/Jul/2021:10:19:02 /travel/usa/new-york-marvel/?s=tb US, United States 27/Jul/2021:10:19:01 /travel/usa/new-york-marvel/?s=tb US, United States 27/Jul/2021:10:18:57 /travel/usa/new-york-marvel/?s=tb CA, Canada 27/Jul/2021:10:18:56 /open-source/linux-kernel.html US, United States 27/Jul/2021:10:18:47 /cybersecurity/comptia/initial-answers.html US, United States 27/Jul/2021:10:18:45 /cybersecurity/comptia/initial-answers.html US, United States 27/Jul/2021:10:18:27 /cybersecurity/crypto/reading.html?s=tb CN, China 27/Jul/2021:10:17:58 /travel/japan/kamakura/kencho-ji.html ES, Spain 27/Jul/2021:10:17:20 /networking/class-a-nets.html US, United States 27/Jul/2021:10:17:17 /cybersecurity/root-password.html US, United States 27/Jul/2021:10:17:00 /open-source/performance-tuning/tcp.html RU, Russian Federation 27/Jul/2021:10:16:05 /travel/usa/new-york-st-marks-place/ FR, France 27/Jul/2021:10:16:02 /travel/uk/glastonbury/king-arthur.html CN, China 27/Jul/2021:10:14:32 /open-source/raspberry-pi/sdr-ads-b-piaware-and-fr24feed.html RS, Serbia 27/Jul/2021:10:14:19 /turkish/verbs.html CN, China 27/Jul/2021:10:14:02 /networking/sdn.html FR, France 27/Jul/2021:10:13:14 /open-source/performance-tuning/tcp.html CN, China 27/Jul/2021:10:13:13 /oliver-cromwell/ CN, China 27/Jul/2021:10:13:10 /open-source/vim-word-count.html US, United States 27/Jul/2021:10:12:41 /networking/netstat-s.html US, United States 27/Jul/2021:10:12:41 /travel/trinidad/port-of-spain.html US, United States 27/Jul/2021:10:12:10 /travel/ US, United States 27/Jul/2021:10:12:09 /radio/ US, United States 27/Jul/2021:10:12:09 /3d/ US, United States 27/Jul/2021:10:12:09 /turkish/

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.

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