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 01/Apr/2020:16:22:49 /robots.txt CL, Chile 01/Apr/2020:16:21:38 /travel/chile/santiago/?s=tb US, United States 01/Apr/2020:16:21:29 /open-source/openbsd-qemu-windows-howto.html RU, Russian Federation 01/Apr/2020:16:21:04 /cybersecurity/monitoring.html US, United States 01/Apr/2020:16:20:46 /travel/latvia/?s=tb US, United States 01/Apr/2020:16:20:46 /travel/greece/greek-islands.html?s=tb BA, Bosnia and Herzegovina 01/Apr/2020:16:20:08 /technical/ata-ide-sata-usb-cable-pinouts.html FR, France 01/Apr/2020:16:20:07 /text/reports/5great.4.txt CN, China 01/Apr/2020:16:20:00 /robots.txt RU, Russian Federation 01/Apr/2020:16:19:52 /open-source/rpm-patch.html US, United States 01/Apr/2020:16:19:47 /travel/greece/ferries.html US, United States 01/Apr/2020:16:18:18 /travel/japan/kofun/empress-koken.html?s=tb US, United States 01/Apr/2020:16:18:09 /travel/france/school-lunch-menus/ AT, Austria 01/Apr/2020:16:18:01 /open-source/openbsd-qemu-windows-howto.html GB, United Kingdom 01/Apr/2020:16:17:52 /radio/ic-3220.html US, United States 01/Apr/2020:16:17:39 /open-source/raspberry-pi/openvas.html US, United States 01/Apr/2020:16:17:16 /travel/uk/scotland-grit-boxes/ US, United States 01/Apr/2020:16:16:43 /open-source/stig-compliance.html MY, Malaysia 01/Apr/2020:16:16:31 /technical/convert-youtube-to-xvid.html US, United States 01/Apr/2020:16:16:29 /travel/usa/new-york-mcgees/ US, United States 01/Apr/2020:16:16:23 /travel/usa/new-york-mcgees/ RU, Russian Federation 01/Apr/2020:16:16:22 /travel/canada/canada-vs-us/?s=tweetbot US, United States 01/Apr/2020:16:16:13 /travel/france/boat/ US, United States 01/Apr/2020:16:16:13 /open-source/pdf-not-authorized.html US, United States 01/Apr/2020:16:16:09 /turkish/nouns.html IE, Ireland 01/Apr/2020:16:15:45 /travel/poland/?s=tb IL, Israel 01/Apr/2020:16:15:13 /travel/japan/kofun/empress-koken.html?s=tb IL, Israel 01/Apr/2020:16:15:12 /travel/japan/kofun/empress-koken.html?s=tb US, United States 01/Apr/2020:16:14:58 /ads.txt MY, Malaysia 01/Apr/2020:16:14:08 /technical/convert-youtube-to-xvid.html US, United States 01/Apr/2020:16:14:05 /open-source/tar-and-ssh.html US, United States 01/Apr/2020:16:14:04 /open-source/linux-kernel.html RU, Russian Federation 01/Apr/2020:16:13:53 /open-source/ssh-3-user.html US, United States 01/Apr/2020:16:13:45 / US, United States 01/Apr/2020:16:13:32 /technical/dsl/ US, United States 01/Apr/2020:16:12:56 /technical/dsl/ HR, Croatia 01/Apr/2020:16:12:06 /turkish/verbs.html ES, Spain 01/Apr/2020:16:12:06 /radio/hf-short-dipoles.html US, United States 01/Apr/2020:16:11:35 /radio/tv-antenna.html US, United States 01/Apr/2020:16:11:29 /radio/ic-3220.html US, United States 01/Apr/2020:16:11:24 /radio/ic-3220.html US, United States 01/Apr/2020:16:11:24 /robots.txt KZ, Kazakhstan 01/Apr/2020:16:11:23 /turkish/turkish-nouns.pdf US, United States 01/Apr/2020:16:11:20 /radio/ic-3220.html KZ, Kazakhstan 01/Apr/2020:16:11:18 /turkish/nouns.html AU, Australia 01/Apr/2020:16:11:10 /travel/japan/tokyo-harajuku/omotesando.html?s=tb AU, Australia 01/Apr/2020:16:11:10 /travel/japan/tokyo-harajuku/omotesando.html?s=tb KZ, Kazakhstan 01/Apr/2020:16:11:03 /turkish/orthography.html KZ, Kazakhstan 01/Apr/2020:16:10:47 /turkish/background.html US, United States 01/Apr/2020:16:10:46 /site-map.html CA, Canada 01/Apr/2020:16:10:32 /technical/dsl/ US, United States 01/Apr/2020:16:10:24 /radio/probes.html US, United States 01/Apr/2020:16:10:16 /travel/japan/kofun/empress-koken.html?s=tb IN, India 01/Apr/2020:16:10:00 /travel/japan/kofun/empress-koken.html?s=tb FR, France 01/Apr/2020:16:09:52 /travel/japan/kofun/empress-koken.html?s=tb US, United States 01/Apr/2020:16:09:10 /travel/japan/kofun/empress-koken.html?s=tb US, United States 01/Apr/2020:16:09:10 /travel/japan/kofun/empress-koken.html?s=tb US, United States 01/Apr/2020:16:09:06 /travel/japan/kofun/empress-koken.html?s=tb CA, Canada 01/Apr/2020:16:09:04 /travel/japan/kofun/empress-koken.html?s=tb CA, Canada 01/Apr/2020:16:09:04 /travel/japan/kofun/empress-koken.html?s=tb US, United States 01/Apr/2020:16:09:01 /travel/japan/kofun/empress-koken.html?s=tb US, United States 01/Apr/2020:16:09:00 /travel/japan/kofun/empress-koken.html?s=tb US, United States 01/Apr/2020:16:08:21 /3d/histogram/ DE, Germany 01/Apr/2020:16:08:04 /cybersecurity/basics/Index.html DE, Germany 01/Apr/2020:16:08:02 /robots.txt US, United States 01/Apr/2020:16:07:52 /open-source/compiling-opencv-on-openbsd.html US, United States 01/Apr/2020:16:07:18 /travel/usa/montgomery-alabama/ GB, United Kingdom 01/Apr/2020:16:07:18 /technical/dsl/ GB, United Kingdom 01/Apr/2020:16:07:07 /technical/bios.html US, United States 01/Apr/2020:16:07:05 /travel/uk/swingate-chain-home/ FR, France 01/Apr/2020:16:07:01 /travel/france/boat/maintenance.html US, United States 01/Apr/2020:16:06:47 /travel/japan/katakana-hiragana/ CH, Switzerland 01/Apr/2020:16:06:44 /open-source/pdf-not-authorized.html US, United States 01/Apr/2020:16:06:31 /turkish/nouns.html US, United States 01/Apr/2020:16:05:55 /travel/france/normandy/utah-beach.html US, United States 01/Apr/2020:16:05:42 /travel/france/normandy/utah-beach.html FR, France 01/Apr/2020:16:05:36 /open-source/pdf-not-authorized.html CN, China 01/Apr/2020:16:05:31 /technical/dsl/Index.html RU, Russian Federation 01/Apr/2020:16:04:58 /3d/histogram/ CH, Switzerland 01/Apr/2020:16:04:43 /3d/histogram/ US, United States 01/Apr/2020:16:04:13 /cybersecurity/stack-hardening.html?ref=driverlayer.com US, United States 01/Apr/2020:16:03:43 /technical/dsl/ US, United States 01/Apr/2020:16:03:28 /open-source/microphone.html US, United States 01/Apr/2020:16:02:50 /open-source/rhel-centos-5-6-7-8/users-groups.html US, United States 01/Apr/2020:16:02:38 /travel/france/etretat-fecamp/ US, United States 01/Apr/2020:16:02:36 /open-source/rhel-centos-5-6-7-8/users-groups.html AU, Australia 01/Apr/2020:16:02:25 /fun/fingerbox/ US, United States 01/Apr/2020:16:01:43 /technical/dsl/ US, United States 01/Apr/2020:16:01:32 /3d/trilobite.html AT, Austria 01/Apr/2020:16:00:23 /open-source/migrate-rhel-to-centos.html US, United States 01/Apr/2020:15:59:53 /open-source/crashdumps.html GB, United Kingdom 01/Apr/2020:15:59:48 /cybersecurity/backdoors.html US, United States 01/Apr/2020:15:59:40 /open-source/linux-break-in-howto.html HU, Hungary 01/Apr/2020:15:59:21 /travel/italy/driving.html CZ, Czech Republic 01/Apr/2020:15:59:09 /robots.txt US, United States 01/Apr/2020:15:59:02 /open-source/rpm-patch.html US, United States 01/Apr/2020:15:59:00 /robots.txt US, United States 01/Apr/2020:15:58:59 /robots.txt CN, China 01/Apr/2020:15:58:56 /cybersecurity/pki-failures.html FR, France 01/Apr/2020:15:58:55 / GB, United Kingdom 01/Apr/2020:15:58:40 /technical/bios.html FR, France 01/Apr/2020:15:58:29 /radio/tek2445a.html US, United States 01/Apr/2020:15:58:13 /travel/france/boat/ US, United States 01/Apr/2020:15:57:53 /travel/usa/new-york-st-marks-place/1st-a-south.html US, United States 01/Apr/2020:15:57:47 /travel/usa/us-wash-masonic.html BE, Belgium 01/Apr/2020:15:57:34 /open-source/linux-kernel-details.html DE, Germany 01/Apr/2020:15:57:09 /open-source/samba-active-directory/deployment.html US, United States 01/Apr/2020:15:56:55 /radio/tv-antenna.html EU, Europe 01/Apr/2020:15:56:48 /open-source/samba-active-directory/freebsd-raspberry-pi.html VN, Vietnam 01/Apr/2020:15:56:47 /radio/probes.html GB, United Kingdom 01/Apr/2020:15:56:44 /open-source/canon-pixma-printer-scanner.html US, United States 01/Apr/2020:15:56:38 /technical/dsl/ US, United States 01/Apr/2020:15:55:22 /open-source/bluray.html US, United States 01/Apr/2020:15:55:15 /networking/wan-specs.html FI, Finland 01/Apr/2020:15:55:10 /open-source/pictures/Blu-ray_Disc.svg US, United States 01/Apr/2020:15:55:10 /technical/dsl/ FI, Finland 01/Apr/2020:15:55:09 /open-source/bluray.html US, United States 01/Apr/2020:15:55:06 /networking/wan-specs.html US, United States 01/Apr/2020:15:55:05 /robots.txt US, United States 01/Apr/2020:15:55:03 /networking/wan-specs.html US, United States 01/Apr/2020:15:55:02 /travel/belgium/belgian-beers/delirium-tremens.html PL, Poland 01/Apr/2020:15:54:48 / US, United States 01/Apr/2020:15:54:36 /travel/usa/us-wash-masonic.html RU, Russian Federation 01/Apr/2020:15:53:32 /open-source/tar-and-ssh.html US, United States 01/Apr/2020:15:52:48 /open-source/vim-word-count.html DE, Germany 01/Apr/2020:15:52:32 /technical/samsung-galaxy/linux.html GB, United Kingdom 01/Apr/2020:15:52:28 /technical/hdmi.html CN, China 01/Apr/2020:15:52:22 /cybersecurity/forensics.html US, United States 01/Apr/2020:15:52:22 /technical/dsl/ US, United States 01/Apr/2020:15:52:03 /technical/hdmi.html ID, Indonesia 01/Apr/2020:15:52:03 /technical/convert-youtube-to-xvid.html US, United States 01/Apr/2020:15:51:57 /travel/usa/detroit/detroit-part2.html US, United States 01/Apr/2020:15:51:51 /ads.txt US, United States 01/Apr/2020:15:51:51 /russian/cyrillic.sty GB, United Kingdom 01/Apr/2020:15:51:47 /technical/hdmi.html GB, United Kingdom 01/Apr/2020:15:51:40 /turkish/word-order.html US, United States 01/Apr/2020:15:51:13 /travel/uk/orkney-west-coast-walk/ US, United States 01/Apr/2020:15:50:56 /travel/france/aix-en-provence/ GB, United Kingdom 01/Apr/2020:15:50:29 /travel/france/aix-en-provence/ GB, United Kingdom 01/Apr/2020:15:50:28 /travel/france/aix-en-provence/ GB, United Kingdom 01/Apr/2020:15:50:28 /travel/france/aix-en-provence/ FR, France 01/Apr/2020:15:50:08 /travel/japan/shinto-buddhism/buddhism.html?s=tb KZ, Kazakhstan 01/Apr/2020:15:49:41 /turkish/ CH, Switzerland 01/Apr/2020:15:49:32 /3d/histogram/ GB, United Kingdom 01/Apr/2020:15:49:20 /travel/chile/santiago/ GB, United Kingdom 01/Apr/2020:15:49:19 /travel/chile/santiago/ GB, United Kingdom 01/Apr/2020:15:49:18 /travel/chile/santiago/ DE, Germany 01/Apr/2020:15:48:58 /open-source/grub-vga-modes.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.

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