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/Oct/2022:10:19:22 /robots.txt CN, China 01/Oct/2022:10:18:44 /open-source/kodi/ US, United States 01/Oct/2022:10:17:23 /ads.txt CN, China 01/Oct/2022:10:17:20 /cybersecurity/hostile/mydoom.m.html US, United States 01/Oct/2022:10:17:11 /radio/probes.html US, United States 01/Oct/2022:10:17:08 /radio/probes.html FR, France 01/Oct/2022:10:16:54 /fun/sarah-palin-baby-name-generator-reloaded.html US, United States 01/Oct/2022:10:16:07 /travel/japan/kamakura/tokei-ji.html DE, Germany 01/Oct/2022:10:16:02 /open-source/performance-tuning/tcp.html CN, China 01/Oct/2022:10:15:55 /travel/chile/constitucion/?s=tb US, United States 01/Oct/2022:10:15:54 /travel/japan/kamakura/ US, United States 01/Oct/2022:10:15:42 /travel/belgium/belgian-beers/absinthe-bar.html CN, China 01/Oct/2022:10:14:05 /travel/greece/?s=tb IN, India 01/Oct/2022:10:13:56 /open-source/rhel-oracle-centos-6-7-8-9/networking.html Unknown 01/Oct/2022:10:13:49 /cybersecurity/isc2-ccsp/ DE, Germany 01/Oct/2022:10:13:46 / MA, Morocco 01/Oct/2022:10:13:21 /travel/morocco/tangier/medina.html?infolinks=no IE, Ireland 01/Oct/2022:10:13:16 / US, United States 01/Oct/2022:10:13:12 / CN, China 01/Oct/2022:10:12:39 /travel/france/marseille/notre-dame-de-la-garde.html?s=tb CA, Canada 01/Oct/2022:10:12:17 /cybersecurity/isc2-ccsp/ US, United States 01/Oct/2022:10:11:08 /radio/rhombic-antennas.html US, United States 01/Oct/2022:10:11:00 /cybersecurity/isc2-ccsp/ CA, Canada 01/Oct/2022:10:10:47 /cybersecurity/isc2-ccsp/ US, United States 01/Oct/2022:10:09:53 /travel/uk/glastonbury/chalice-spring-tor.html US, United States 01/Oct/2022:10:09:52 /open-source/samba-active-directory/ US, United States 01/Oct/2022:10:09:43 /open-source/rhel-oracle-centos-6-7-8-9/networking.html FI, Finland 01/Oct/2022:10:09:04 /radio/mwdx.html GB, United Kingdom 01/Oct/2022:10:08:33 /travel/uk/glastonbury/chalice-spring-tor.html US, United States 01/Oct/2022:10:08:25 /open-source/rhel-oracle-centos-6-7-8-9/networking.html CN, China 01/Oct/2022:10:08:00 /cybersecurity/cyberwar/qatar.html US, United States 01/Oct/2022:10:07:52 /open-source/rhel-oracle-centos-6-7-8-9/networking.html MY, Malaysia 01/Oct/2022:10:07:35 /cybersecurity/isc2-ccsp/ SG, Singapore 01/Oct/2022:10:07:28 /open-source/rhel-oracle-centos-6-7-8-9/networking.html UA, Ukraine 01/Oct/2022:10:07:21 /open-source/samba-active-directory/ US, United States 01/Oct/2022:10:07:09 /open-source/google-freebsd-tls/apache-http2-php.html US, United States 01/Oct/2022:10:06:49 /open-source/rhel-oracle-centos-6-7-8-9/networking.html IN, India 01/Oct/2022:10:06:47 /open-source/rhel-oracle-centos-6-7-8-9/networking.html DE, Germany 01/Oct/2022:10:06:41 /ads.txt CN, China 01/Oct/2022:10:06:38 /cybersecurity/cyberwar/ US, United States 01/Oct/2022:10:06:13 / CN, China 01/Oct/2022:10:05:11 /travel/turkey/hatusas/ US, United States 01/Oct/2022:10:05:01 /travel/usa/detroit/ US, United States 01/Oct/2022:10:05:01 /travel/turkey/nemrut-dagi/ US, United States 01/Oct/2022:10:05:00 /travel/uk/stonehenge/ FR, France 01/Oct/2022:10:04:56 /travel/japan/kyoto/ CN, China 01/Oct/2022:10:03:47 /turkish/ CZ, Czech Republic 01/Oct/2022:10:02:50 /robots.txt CN, China 01/Oct/2022:10:01:58 /travel/belgium/comic-book-art/ US, United States 01/Oct/2022:10:01:04 /travel/france/avignon/chateauneuf-du-pape.html?s=tb HU, Hungary 01/Oct/2022:10:00:43 /technical/samsung-galaxy/linux.html US, United States 01/Oct/2022:10:00:29 /travel/france/detectives/ ES, Spain 01/Oct/2022:10:00:28 /travel/france/seine-river-art-history-monet/giverny.html US, United States 01/Oct/2022:10:00:12 /travel/replace-sim-card/ NL, Netherlands 01/Oct/2022:10:00:02 /travel/uk/orkney-sousterrain/ MN, Mongolia 01/Oct/2022:09:59:37 /open-source/rpm-patch.html FR, France 01/Oct/2022:09:59:13 /cybersecurity/comptia/domain-2-answers.html AT, Austria 01/Oct/2022:09:58:40 /networking/switch-programming.html AT, Austria 01/Oct/2022:09:58:29 /networking/switch-programming.html CN, China 01/Oct/2022:09:57:18 /travel/japan/tokyo-akihabara/ AT, Austria 01/Oct/2022:09:57:10 /networking/switch-programming.html CA, Canada 01/Oct/2022:09:56:43 /travel/uk/glen-nevis/ RU, Russian Federation 01/Oct/2022:09:56:00 /open-source/raspberry-pi/sdr-getting-started.html CN, China 01/Oct/2022:09:55:52 /travel/japan/forty-seven-ronin/ US, United States 01/Oct/2022:09:55:45 /travel/morocco/tangier/medina.html?infolinks=no US, United States 01/Oct/2022:09:55:27 /open-source/rhel-oracle-centos-6-7-8-9/storage.html US, United States 01/Oct/2022:09:55:26 /travel/turkey/aphrodisias/ US, United States 01/Oct/2022:09:55:09 /travel/france/avignon/avignon-papacy.html?s=tb US, United States 01/Oct/2022:09:54:09 / FR, France 01/Oct/2022:09:53:55 /radio/ic-3220.html US, United States 01/Oct/2022:09:53:47 /travel/morocco/tangier/medina.html MA, Morocco 01/Oct/2022:09:53:46 /travel/morocco/tangier/medina.html?infolinks=no US, United States 01/Oct/2022:09:53:19 /travel/china/yangshuo.html CN, China 01/Oct/2022:09:53:08 /travel/france/budget-hotels/?s=tb US, United States 01/Oct/2022:09:53:02 /robots.txt US, United States 01/Oct/2022:09:53:01 /robots.txt US, United States 01/Oct/2022:09:51:36 /travel/ US, United States 01/Oct/2022:09:51:27 /travel/france/boat/canal-selection-and-logs.html RU, Russian Federation 01/Oct/2022:09:51:19 /open-source/google-freebsd-tls/tls-certificate.html US, United States 01/Oct/2022:09:50:27 /travel/mexico/cholula-puebla.html?s=tb CA, Canada 01/Oct/2022:09:50:18 /travel/france/avignon/chateauneuf-du-pape.html?s=tb CN, China 01/Oct/2022:09:49:50 /travel/france/normandy/arromanches.html US, United States 01/Oct/2022:09:49:48 /travel/usa/venice-california/ IL, Israel 01/Oct/2022:09:49:45 /travel/france/avignon/chateauneuf-du-pape.html?s=tb IL, Israel 01/Oct/2022:09:49:45 /travel/france/avignon/chateauneuf-du-pape.html?s=tb IL, Israel 01/Oct/2022:09:49:44 /travel/france/avignon/chateauneuf-du-pape.html?s=tb IL, Israel 01/Oct/2022:09:49:44 /travel/france/avignon/chateauneuf-du-pape.html?s=tb NL, Netherlands 01/Oct/2022:09:49:29 /technical/samsung-galaxy/linux.html US, United States 01/Oct/2022:09:49:22 /robots.txt US, United States 01/Oct/2022:09:49:20 /turkish/nouns.html FI, Finland 01/Oct/2022:09:49:16 /travel/france/avignon/chateauneuf-du-pape.html?s=tb FI, Finland 01/Oct/2022:09:49:16 /robots.txt US, United States 01/Oct/2022:09:49:10 /travel/france/avignon/chateauneuf-du-pape.html?s=tb US, United States 01/Oct/2022:09:49:09 /robots.txt US, United States 01/Oct/2022:09:49:08 /travel/france/avignon/chateauneuf-du-pape.html?s=tb US, United States 01/Oct/2022:09:49:07 /travel/france/avignon/chateauneuf-du-pape.html?s=tb US, United States 01/Oct/2022:09:49:06 /robots.txt FR, France 01/Oct/2022:09:49:05 / FR, France 01/Oct/2022:09:49:05 /travel/france/avignon/chateauneuf-du-pape.html?s=tb FR, France 01/Oct/2022:09:49:05 /travel/france/avignon/chateauneuf-du-pape.html?s=tb DE, Germany 01/Oct/2022:09:49:05 /travel/france/avignon/chateauneuf-du-pape.html DE, Germany 01/Oct/2022:09:49:05 /travel/france/avignon/chateauneuf-du-pape.html FR, France 01/Oct/2022:09:48:52 /travel/france/seine-river-art-history-monet/ DK, Denmark 01/Oct/2022:09:48:45 /travel/uk/oxford-lewis-tolkien/ GB, United Kingdom 01/Oct/2022:09:48:37 /open-source/raspberry-pi/sdr-getting-started.html CN, China 01/Oct/2022:09:48:28 /open-source/nginx-tls-1.3/security-performance-nginx.html US, United States 01/Oct/2022:09:48:15 /travel/morocco/tangier/medina.html FR, France 01/Oct/2022:09:47:35 /turkish/nouns.html FR, France 01/Oct/2022:09:47:35 /turkish/nouns.html GB, United Kingdom 01/Oct/2022:09:47:19 /turkish/orthography.html DE, Germany 01/Oct/2022:09:47:08 /travel/japan/kamakura/engaku-ji.html CN, China 01/Oct/2022:09:47:06 /travel/japan/koyasan/kongo-sanmai-in.html FR, France 01/Oct/2022:09:46:37 /travel/france/seine-river-art-history-monet/la-roche-guyon.html US, United States 01/Oct/2022:09:46:08 /travel/france/seine-river-art-history-monet/la-roche-guyon.html FI, Finland 01/Oct/2022:09:46:06 /travel/turkey/ephesus/walk.html ES, Spain 01/Oct/2022:09:45:45 /travel/france/seine-river-art-history-monet/la-roche-guyon.html US, United States 01/Oct/2022:09:45:27 /travel/morocco/tangier/medina.html CN, China 01/Oct/2022:09:45:15 /cybersecurity/ EU, Europe 01/Oct/2022:09:45:10 /open-source/rhel-oracle-centos-multimedia.html DE, Germany 01/Oct/2022:09:44:37 /travel/uk/lee-ho-fook/ FR, France 01/Oct/2022:09:43:55 /travel/uk/orkney-neolithic/ring-of-brodgar.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