aggregated thinking

mashed bits that go well with coffee, code, and servers

How to count instances of an IP address in a log file

I was looking for a quick and painless way to determine what IP addresses used our web app the most and stumbled across this excellent post. I got reminded of the power of the command-line interface and that often, I underestimate the way these commands are supposed to make a sysad's life easier.

So here's a quick tip for counting unique visitors to your web app. Locate your web app's log file and do a quick scan of the last few lines. In my case, this is what I saw:

112.198.79.223 - - [10/Jul/2010:00:57:29 -0400] "POST /v2/api/execute.php?method=upload_time&ver=win1.1.15 HTTP/1.1" 200 116 "-" "Mozilla/5.0"
117.241.112.254 - - [10/Jul/2010:00:57:30 -0400] "POST /v2/api/execute.php?method=timestat&ver=win1.1.15 HTTP/1.1" 200 288 "-" "Mozilla/5.0"
80.249.84.105 - - [10/Jul/2010:00:57:29 -0400] "POST /v2/api/execute.php?method=offtime&ver=win1.1.15 HTTP/1.1" 200 19 "-" "Mozilla/5.0"
117.241.112.254 - - [10/Jul/2010:00:57:32 -0400] "POST /v2/api/execute.php?method=get_defaults&ver=win1.1.15 HTTP/1.1" 200 77 "-" "Mozilla/5.0"

In this log format, the IP address appears first, so we will only need to get the first set of characters, separated by a space. In order to count instances of an IP address, we sort the IP addresses so similar IP addresses are grouped together, then count them. Then we sort them again so that the sums are arranged. The number of unique IPs may give you pages of standard output, so optionally, if you only want to see which IP addresses accessed the web app the most, we look at the top results only.

So these are the commands used, piped one after the other, with the output:

[root@server2 ~]# cat /var/log/httpd/access_ssl.log | awk '{print $1}' | sort | uniq -c | sort -nr | head

71612 216.157.78.237
34094 120.28.205.244
30091 119.93.97.54
25078 120.28.214.104
18949 120.28.195.151
17929 58.107.64.40
14877 212.98.174.235
14752 117.241.112.143
14429 120.28.247.74
12864 117.241.113.183
[root@server2 ~]#

Happy counting, err reporting!

Posted 5 days ago
Loading mentions Retweet

The things Miguel does on a usual day

In a month or so he'll be too big to fit in his laundry basket. He has his eye on the bigger hamper in our room.

He runs around and does the "happy feet". He also likes running while on top of the air bed, but I can't get any video of that yet as I'm too busy going after him lest he bounce too hard and hit the wall.

And he demands his time for "computer work". :)

Posted 5 days ago
Loading mentions Retweet

Ever wondered how I look like after pulling an all-nighter?

Posted 20 days ago
Loading mentions Retweet

Putty on my phone FTW! ISP was acting up and was able to get Apache to work sometime past 3pm. Post-mortem shortly.

Posted 1 month ago
Loading mentions Retweet

Being a Systems Administrator @37signals (Podcast)

 I use Basecamp a lot. Kudos to these guys for making my job as a Systems Administrator more bearable than usual. :p

Episode #12: Being a Systems Administrator at 37signals

Time: 22:50 | 04/13/2010 | Download MP3 | Link to this episode

Mark, Joshua, and John on life as a 37signals Sys Admin

The Sys Admin team discusses hosting the 37signals apps, working with programmers, helping support, telecommuting, dealing with vendors, improving speeds in Europe, and more. Related links:

 

Posted 1 month ago
Loading mentions Retweet

How big is a Yottabyte? - Holy Kaw!

And I got a long way to go. My next step doesn't happen in the next couple of months, and that's when I purchase a terabyte external hard drive for storage purposes.

Remember back in the 1970s when 200MB was the size of a tire? Now we live in a world of gigbytes and terabytes, and the future will bring zettabytes and yottabytes in everyday life. Hello, future!

k to view large

Download full size (80 KB)

Via Digital Kamera.

Tons of tech.

 

Posted 1 month ago
Loading mentions Retweet

New theme, needs more work

I'm doing some major cosmetic changes with this blog; and I'm sort of working off this to-do: 1. come up with a manageable set of tags 2. update posts with appropriate tags 3. look for any form of twitter integration Yes, I think I'll be blogging more now. More than anything else, I need the writing exercise.
Posted 2 months ago
Loading mentions Retweet

After a busy afternoon of play, Ate Kysa attended to her brother and shared a meal with him.

Posted 2 months ago
Loading mentions Retweet

Miguel's first giddyap!

Spur of the moment thing. I was never really good with "anticipation" so didn't take a better recording gadget with us. We didn't think Miguel was going to point at the carousel since he would normally ignore this. I guess he's starting to appreciate things around him more, now that he's walking...and running...and stumbling.

Posted 2 months ago
Loading mentions Retweet

Kickstarter - Decentralize the web with Diaspora

http://kck.st/9QC2zk

IMO, this is the answer to all your privacy-related concerns on Facebook. Can’t wait til it launches.

Posted 2 months ago
Loading mentions Retweet