Thefoggiest.dev

“Why yes, I do have the foggiest”

Counting visitors without WP Statistics

April 28, 2024

This blog has a few, mostly self-serving purposes. Still, it's nice to know if anybody is, in fact, reading what I'm writing, or, that the only thing this blog is used for is trying to break into my server. The line blow, for instance, looks like someone hasn't been paying attention to my writing, while still trying to get somewhere they're not supposed to be:

root@server ~# cat /path/to/access.log | grep "wp-login" | wc
 20337  436804 4026846i

Those are the number of times someone has requested the login page of my WordPress site. That's a lot more than the number of times someone requested the post announcing my new homebrew blogging engine:

root@server ~# cat /path/to/access.log | grep "homebrew" | wc
    135    2572   30118

Quick explainer: in unix (so also Linux) the |-symbol passes the output of the command to its left on to the command to its right. cat gets the content of the log, grep filters that, leaving out any line not containing the given string and wc will count how many lines are left.

Of course, next to (or before) the requests to my current blog, these access logs also include the requests to my old WordPress blog. This means they go a lot further back in time than that post in the line above. But I can also grep for "28/Apr/2024" and see that today, so far, three people requested that post and nine received a 404 Not found when trying to login to my no longer online WordPress instance.

On WordPress, I used, as one does, a growing number of plugins, one of which was called WP Statistics, a plugin that showed me nice aggregated graphs of visits, broken down into country, device, operating system, browser and such. It had a very nice look, but I hadn't the foggiest of what it did with requests that showed up in my logs like this one:

"\xAA\xAA\xAA\xAAUUUUUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\
xAAUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA
\xAA\xAAUUUU\xAA\xAA\xAA\xAAUUUU\xAA\xAA\xAA\xAA" 400 157 "-" "-"

By the way, these are always a reminder to keep looking at your logs, in case you thought aggregator and plugins are all you need.

Anyway, I want to keep things quite simple but a few coloured graphs would be nice. Grepping through logs won't give me those, so I found goaccess.

goaccess

Goaccess is a command line web server log statistics aggregator. Below the three panels visible in the screenshot above, there are twelve more with data on geo location, status codes, referring sites and more. Each panel can be expanded. It also has some vim key bindings for navigation, so using it feels natural and easy.

Also, considering the number of requests for my none existing .env-file, I have half a mind of just creating one and make it a nefarious executable. That would serve them right, I presume.

Categories: blog

Tags: wordpress, command-line

CC-BY-SA 2006-2024 thefoggiest.dev