Angelo’s blog

A systems administrator’s diary
  • rss
  • Home
  • About me
  • Computers
  • Bibliography
  • Guides
    • IPSec VPN using FreeBSD
    • Setting up OpenVPN using radius on FreeBSD
    • Protect OWA using a reverse proxy
    • Monitoring a Windows machine with extended counters
  • Résumé

Graphing requests per second out of apache log files

March 19, 2009 | 11:00 am

I’ve been doing some analysis on some log files I got from a client. Since I have to propose an infrastructure that can support these web applications, I’d like to do some reconnaisance first, and see what the traffic is, and how many requests/sec are actually happening. Are we talking 10 req/s or 1000 req/s?

So, I wrote some scripts to graph out the requests/sec from an apache logfile, and I want to share this with you.

First of all, I want to merge the logfiles, so I get one big log file of all cluster nodes. For this, I use the logresolvemerge.pl script that comes with AWStats.

perl logresolvemerge.pl example.node1.log example.node2.log > example.log

Then basicly what I do, is I sort the log file (aparently apache log files are not really chronologic, probably because of the difference between the time a request is made, and the time a request is completed), then I run a script to get the number of requests per minute using this requests.rb script. I then create an rrd file, post all the information about the requests per minute into it, and then I export graphs :)

To sort the logfile, save this script as _sortlog.sh (you might want to use another location than ~/tmp as temporary sorting dir:

#!/bin/sh
if [ ! -f $1 ]; then
    echo "Usage: $0 "
    exit
fi
echo "Sorting $1"
sort -t ' ' -k 4.9,4.12n -k 4.5,4.7M -k 4.2,4.3n -k 4.14,4.15n -k 4.17,4.18n -k 4.20,4.21n -T ~/tmp $1 > $2

Here’s a complete script. Keep in mind I use FreeBSD, so on other *nix flavours you might have to change the script a bit (use expr instead of gexpr, etc). Requirements are the _sortlog.sh script and the requests.rb script mentioned above, and on FreeBSD the packages gexpr and rrdtool12 (or maybe rrdtool 1.3 wil word as well). The 4 timestamps mentioned in the script are for the exporting of the graphs. (My blog will replace straigt double quotes with the curly ones as well, you should replace them back):

#/bin/sh
#ERROR HANDLING
if [ $# -ne 1 ]; then
    echo "Usage: $0 "
    exit
fi
LOGFILENAME=`basename $1 .log`
TIMESTAMP_WEEK_BEGIN=1236654000
TIMESTAMP_WEEK_END=1237258800
TIMESTAMP_DAY_BEGIN=1237071600
TIMESTAMP_DAY_END=1237158000
echo "`date` started script for log $LOGFILENAME.log.."
#SORTING
echo `date` sorting log file "$LOGFILENAME".log to "$LOGFILENAME"_sorted.log..
sh _sortlog.sh "$LOGFILENAME".log "$LOGFILENAME"_sorted.log
#GETTING REQUESTS
echo `date` calculating requests per minute in file "$LOGFILENAME"_requests.txt..
cat "$LOGFILENAME"_sorted.log | ./requests.rb > "$LOGFILENAME"_requests.txt
#CREATING RRD
echo `date` making script "$LOGFILENAME"_createrrd.sh..
FIRSTTIMESTAMP=`head -n 1 "$LOGFILENAME"_requests.txt | awk '{print $1}'`
FIRSTTIMESTAMP=`gexpr "$FIRSTTIMESTAMP - 60"`
echo rrdtool create $LOGFILENAME.rrd \\ > "$LOGFILENAME"_createrrd.sh
echo --step 60  \\ >> "$LOGFILENAME"_createrrd.sh
echo --start $FIRSTTIMESTAMP \\ >> "$LOGFILENAME"_createrrd.sh
echo DS:requests:ABSOLUTE:60:0:U \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:AVERAGE:0.5:1:500 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:AVERAGE:0.5:1:600 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:AVERAGE:0.5:6:700 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:AVERAGE:0.5:24:775 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:AVERAGE:0.5:1440:3985 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MIN:0.5:1:600 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MIN:0.5:6:700 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MIN:0.5:24:775 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MIN:0.5:1440:3985 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MAX:0.5:1:500 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MAX:0.5:1:600 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MAX:0.5:6:700 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MAX:0.5:24:775 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:MAX:0.5:1440:3985 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:LAST:0.5:1:600 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:LAST:0.5:6:700 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:LAST:0.5:24:775 \\ >> "$LOGFILENAME"_createrrd.sh
echo RRA:LAST:0.5:1440:3985 >> "$LOGFILENAME"_createrrd.sh
echo `date` deleting "$LOGFILENAME".rrd..
rm "$LOGFILENAME".rrd
echo `date` executing script "$LOGFILENAME"_createrrd.sh..
sh "$LOGFILENAME"_createrrd.sh
 
#DO THE UPDATES
echo `date` making script "$LOGFILENAME"_updaterrd.sh..
rm "$LOGFILENAME"_updaterrd.sh
cat "$LOGFILENAME"_requests.txt | while read line; do
  AWKSTRING="{print \"rrdtool update $LOGFILENAME.rrd \" \$1 \":\" \$2}"
  echo `echo ${line} | awk "$AWKSTRING"` >> "$LOGFILENAME"_updaterrd.sh
done
echo `date` executing script "$LOGFILENAME"_updaterrd.sh..
sh "$LOGFILENAME"_updaterrd.sh
# MAKING GRAPH
echo `date` making script "$LOGFILENAME"_graph_week.sh..
echo /usr/local/bin/rrdtool graph "$LOGFILENAME"_week.png \\ >  "$LOGFILENAME"_graph_week.sh
echo --imgformat=PNG \\ >> "$LOGFILENAME"_graph_week.sh
echo --start=$TIMESTAMP_WEEK_BEGIN \\ >> "$LOGFILENAME"_graph_week.sh
echo --end=$TIMESTAMP_WEEK_END \\ >> "$LOGFILENAME"_graph_week.sh
echo --title=\"$LOGFILENAME requests\" \\ >> "$LOGFILENAME"_graph_week.sh
echo --rigid \\ >> "$LOGFILENAME"_graph_week.sh
echo --base=1000 \\ >> "$LOGFILENAME"_graph_week.sh
echo --height=120 \\ >> "$LOGFILENAME"_graph_week.sh
echo --width=500 \\ >> "$LOGFILENAME"_graph_week.sh
echo --alt-autoscale-max \\ >> "$LOGFILENAME"_graph_week.sh
echo --lower-limit=0 \\ >> "$LOGFILENAME"_graph_week.sh
echo --vertical-label=\"requests per second\" \\ >> "$LOGFILENAME"_graph_week.sh
echo --slope-mode \\ >> "$LOGFILENAME"_graph_week.sh
echo --font TITLE:9:/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \\ >> "$LOGFILENAME"_graph_week.sh
echo --font AXIS:7:/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \\ >> "$LOGFILENAME"_graph_week.sh
echo --font LEGEND:8:/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \\ >> "$LOGFILENAME"_graph_week.sh
echo --font UNIT:7:/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \\ >> "$LOGFILENAME"_graph_week.sh
echo DEF:a=\"$LOGFILENAME.rrd\":requests:AVERAGE \\ >> "$LOGFILENAME"_graph_week.sh
echo DEF:b=\"$LOGFILENAME.rrd\":requests:LAST \\ >> "$LOGFILENAME"_graph_week.sh
echo DEF:c=\"$LOGFILENAME.rrd\":requests:MIN \\ >> "$LOGFILENAME"_graph_week.sh
echo DEF:d=\"$LOGFILENAME.rrd\":requests:MAX \\ >> "$LOGFILENAME"_graph_week.sh
echo AREA:a#6EA1007F:\"HTTP Requests\"  \\ >> "$LOGFILENAME"_graph_week.sh
echo GPRINT:b:LAST:\"Current\\:%8.0lf\"  \\ >> "$LOGFILENAME"_graph_week.sh
echo GPRINT:a:AVERAGE:\"Average\\:%8.0lf\"  \\ >> "$LOGFILENAME"_graph_week.sh
echo GPRINT:d:MAX:\"Maximum\\:%8.0lf\"  \\ >> "$LOGFILENAME"_graph_week.sh
echo LINE1:a#6EA100FF:\"\" >> "$LOGFILENAME"_graph_week.sh
echo `date` executing script "$LOGFILENAME"_graph_week.sh..
sh "$LOGFILENAME"_graph_week.sh
 
echo `date` making script "$LOGFILENAME"_graph_day.sh..
echo /usr/local/bin/rrdtool graph "$LOGFILENAME"_day.png \\ >  "$LOGFILENAME"_graph_day.sh
echo --imgformat=PNG \\ >> "$LOGFILENAME"_graph_day.sh
echo --start=$TIMESTAMP_DAY_BEGIN \\ >> "$LOGFILENAME"_graph_day.sh
echo --end=$TIMESTAMP_DAY_END \\ >> "$LOGFILENAME"_graph_day.sh
echo --title=\"$LOGFILENAME requests\" \\ >> "$LOGFILENAME"_graph_day.sh
echo --rigid \\ >> "$LOGFILENAME"_graph_day.sh
echo --base=1000 \\ >> "$LOGFILENAME"_graph_day.sh
echo --height=120 \\ >> "$LOGFILENAME"_graph_day.sh
echo --width=500 \\ >> "$LOGFILENAME"_graph_day.sh
echo --alt-autoscale-max \\ >> "$LOGFILENAME"_graph_day.sh
echo --lower-limit=0 \\ >> "$LOGFILENAME"_graph_day.sh
echo --vertical-label=\"requests per second\" \\ >> "$LOGFILENAME"_graph_day.sh
echo --slope-mode \\ >> "$LOGFILENAME"_graph_day.sh
echo --font TITLE:9:/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \\ >> "$LOGFILENAME"_graph_day.sh
echo --font AXIS:7:/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \\ >> "$LOGFILENAME"_graph_day.sh
echo --font LEGEND:8:/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \\ >> "$LOGFILENAME"_graph_day.sh
echo --font UNIT:7:/usr/local/share/rrdtool/fonts/DejaVuSansMono-Roman.ttf \\ >> "$LOGFILENAME"_graph_day.sh
echo DEF:a=\"$LOGFILENAME.rrd\":requests:AVERAGE \\ >> "$LOGFILENAME"_graph_day.sh
echo DEF:b=\"$LOGFILENAME.rrd\":requests:LAST \\ >> "$LOGFILENAME"_graph_day.sh
echo DEF:c=\"$LOGFILENAME.rrd\":requests:MIN \\ >> "$LOGFILENAME"_graph_day.sh
echo DEF:d=\"$LOGFILENAME.rrd\":requests:MAX \\ >> "$LOGFILENAME"_graph_day.sh
echo AREA:a#6EA1007F:\"HTTP Requests\"  \\ >> "$LOGFILENAME"_graph_day.sh
echo GPRINT:b:LAST:\"Current\\:%8.0lf\"  \\ >> "$LOGFILENAME"_graph_day.sh
echo GPRINT:a:AVERAGE:\"Average\\:%8.0lf\"  \\ >> "$LOGFILENAME"_graph_day.sh
echo GPRINT:d:MAX:\"Maximum\\:%8.0lf\"  \\ >> "$LOGFILENAME"_graph_day.sh
echo LINE1:a#6EA100FF:\"\" >> "$LOGFILENAME"_graph_day.sh
echo `date` executing script "$LOGFILENAME"_graph_day.sh..
sh "$LOGFILENAME"_graph_day.sh
 
echo `date` done

You can run this script using the command:

$ ./go.sh example.log

And the output would look like:

Wed Mar 18 17:30:30 CET 2009 started script for log example.log..
Wed Mar 18 17:30:30 CET 2009 sorting log file example.log to example_sorted.log..
Sorting example.log
Wed Mar 18 17:54:23 CET 2009 calculating requests per minute in file example_requests.txt..
Thu Mar 19 03:22:42 CET 2009 making script example_createrrd.sh..
Thu Mar 19 03:22:42 CET 2009 deleting example.rrd..
rm: example.rrd: No such file or directory
Thu Mar 19 03:22:42 CET 2009 executing script example_createrrd.sh..
Thu Mar 19 03:22:42 CET 2009 making script example_updaterrd.sh..
rm: example_updaterrd.sh: No such file or directory
Thu Mar 19 03:23:10 CET 2009 executing script example_updaterrd.sh..
Thu Mar 19 03:23:27 CET 2009 making script example_graph_week.sh..
Thu Mar 19 03:23:27 CET 2009 executing script example_graph_week.sh..
595×199
Thu Mar 19 03:23:27 CET 2009 making script example_graph_day.sh..
Thu Mar 19 03:23:27 CET 2009 executing script example_graph_day.sh..
595×199
Thu Mar 19 03:23:27 CET 2009 done

Note the requests.rb file can take long, the above output was for an 18GB file. The graphs will perhaps look like this:

example_day
example_week

Comments
3 Comments »
Categories
Linux/Unix, Misc
Comments rss Comments rss
Trackback Trackback

Protect OWA using a reverse proxy

November 24, 2008 | 11:50 pm

Sometimes you just have a single public IP address (unfortunately ipv6 is not that widespread yet), and you still want to publish stuff like Outlook Web Access and other applications to the net in a secure way. If you want that, the easiest way to do so, is to just pass port 443 to the Exchange server. But this means that if you have other web apps, you have to run them on the Exchange server as well. And besides, not everybody wants to put an IIS machine directly out on the net..

One way to solve that, is by putting a reverse proxy like Apache or Squid in front of it. Read more ..

Comments
No Comments »
Categories
Linux/Unix, Microsoft, Security/privacy
Comments rss Comments rss
Trackback Trackback

TrueCrypt 5.0 released

February 6, 2008 | 4:25 pm

Quote from Slashdot:

1202285284.png“The popular open source privacy tool, TrueCrypt, has just received a major update. The most exciting new feature provides the ability to encrypt an entire drive, prompting the user for a password during boot up; this makes TrueCrypt the perfect tool for non-technical laptop users (the kind who are likely to lose all of that sensitive customer data). The Linux version receives a GUI and independence from the kernel internals, and a Mac version is at last available too.”

Comments
No Comments »
Categories
Linux/Unix, Mac, Security/privacy
Comments rss Comments rss
Trackback Trackback

FreeBSD running on CF card

December 6, 2007 | 9:10 am

hsz3060_com_d_en_sff.jpgMy firewall/asterisk/mail scanner is a Compaq Deskpro EN/SFF, a very small Pentium III 500 box, with 256MB RAM and a 13GB ATA disk. I am very happy with it, since it scans inbound and outbound email all day using amavisd-new, spamassassin and ClamAV, and at the same time I can call through asterisk without a glitch. And it also runs OpenVPN server, DHCP server, BIND, NTP daemon, IPv6 tunnel, PF firewall with QoS, etc. And all that with only 30W power consumption! On auction sites, they go for around 25-30 EUR a piece. You don’t get a Cisco router with that flexibility and features for that price :)

The thing that annoyed me, was the fact that the disk made an annoying high-pitch sound. I could replace it with another drive, perhaps a 2.5″ laptop harddisk, to reduce the noise, but eventually, I decided to go for a CF-card. The CF thing was kind of new to me, but after reading for a while, it looks like the CF card with an adapter just shows up as an IDE disk, and that’s it, bootable and all.So I went out and bought a CF to IDE adapter and an 8GB Sandisk CompactFlash Extreme III card. The adapter is quite cool, you can mount it in a floppy bay, or you can mount it at the back of you PC between the PCI slots, so you can just eject the card from the back or the front. (Well, looking up the product I bought on John’s site reveals more similar adapters to me, I think afterwards this adapter would have been cheaper, even though I’m not sure if it would fit in the small form factor PC.)

I installed the card, and after some fiddling with cables and jumpers, FreeBSD saw it as my second disk. I then stopped all network services, created a new slice on it and created partitions/labels with sysinstall. I then did a dump/restore to copy the partitions from the old disk to the new disk. After that was done (took quite a while, played some CoD4 while waiting), I rebooted the machine using only the CF card, fixed the missing /tmp filesystem, and rebooted again, and that’s it, the machine was op and running again! The only way to tell it’s running is the light on the front of the machine, because it’s now dead silent :)

And the performance is not as bad as I thought. I used diskinfo to do some simple and naive tests. The old disk (12407MB <Maxtor 91301U3 FA570480> at ata0-master UDMA33) has seeks time of up to 22ms, and a tranfer rate of up to 24MB/s. The new disk (7815MB <SanDisk SDCFX3-8192 HDX 4.03> at ata1-master WDMA2) had seek times of under 0.5ms, and a steady transfer rate of 15MB/s. The CF card feels fast and snappy as well, probably because of the low seek times..

Comments
No Comments »
Categories
Hardware, Linux/Unix
Comments rss Comments rss
Trackback Trackback

Apache2 local user authentication

November 16, 2007 | 1:03 pm

I was trying to get Apache2 to authenticate using the local user database, and I would expect it to be quite easy. I was wrong.

But thank god for blogs :) This user described a way to use pwauth and mod_athnz_external, that works like a charm for me:
http://blog.innerewut.de/2007/6/26/apache-2-2-authentication-with-mod_authnz_external

Thanks Jonathan!

Comments
No Comments »
Categories
Linux/Unix, Security/privacy
Comments rss Comments rss
Trackback Trackback

FreeBSD 7.0 branched!

October 12, 2007 | 3:28 pm

FreeBSD RELENG_7 was born on 2007-10-11 04:28:08 UTC. I wonder when the official announcement will be made.

http://lists.freebsd.org/pipermail/cvs-src/2007-October/082249.html

Update: http://lists.freebsd.org/pipermail/freebsd-current/2007-October/078172.html

A message from Ken Smith, stating that this was done for development reasons, and in a few days, it’ll get beta status, and there will be a schedule for going stable. I hope they go stable soon!

Comments
1 Comment »
Categories
Linux/Unix
Comments rss Comments rss
Trackback Trackback

Talking storage systems with Sun’s ZFS team

| 10:51 am

Quote from original article: “The inventors of Sun Microsystems’ ZFS, Jeff Bonwick, distinguished engineer and storage CTO, and Bill Moore, hardware/software architect, tell me what was behind coming up with ZFS. It’s a file system. That sounds boring, right? But it’s not, since this technology is used in many of the world’s datacenters to keep files safely stored even when bad things happen. The conversation takes us all over the place, since these guys are experts on storage systems. Hard drives and all that. What does ZFS stand for? Zettabyte File System.”

Comments
No Comments »
Categories
Linux/Unix
Comments rss Comments rss
Trackback Trackback

Setting up OpenVPN using radius on FreeBSD

August 20, 2007 | 4:38 pm

I’ve got a MS ISA 2004 server, and some colleagues that connect to the office remotely, using the built-in windows PPTP client.

After using Microsoft’s PPTP server for about 6 years, I’ve totally had it. I’m tired and sick of problems with networking infrastructue (passing GRE through firewalls), the lack of easy error reporting functionality, etc. Every now and then connections don’t work, and rebooting a firewall here and there usually solves the problem.

After thinking about it for a while, I decided to ditch the MS PPTP server, and implement an OpenVPN server for my collegues on the road. I’ve been using OpenVPN for a while now as well, and I’m a big fan.. I’ve hooked up several data centres and remote locations using OpenVPN, and it has always been a rock solid solution. It can get a little complex at times, but it’s definitly worth the effort.

read more

Comments
No Comments »
Categories
Linux/Unix, Security/privacy
Comments rss Comments rss
Trackback Trackback

Benchmarking

May 15, 2007 | 11:03 am

At work, we have some workstations varying in age between 4 years and 4 months. But when is a workstation written off? We have the default policy of writing a PC off after 3 years, but what if the PC is still working like a charm?

 To have some extra numbers to take into consideration, I wanted to create a speed rating that would define the performance of a PC in a single number. I searched for quite some time to find a decent benchmark that would run on any PC (or server), and eventually, I cooked something up.

I downloaded the knoppix cd to boot from in text mode (type ‘knoppix 2′ at the boot screen) on each PC, download the script below, and run it.

It downloads and compiles ubench and seeker. Ubench is a tool that does some mathematical calculations, and benchmarks the CPU and memory. I then use hdparm to get the maximum sequential read in MB/s, then I run seeker to get the number of seeks per second, and the average access time in milliseconds. I run all these tests 3 times, to make sure one isn’t off.

I enter all data in an Excel sheet, and create a rating for the disk, by averaging the 3 disk numbers (using the PERCENTRANK function to place them on a scale from very bad to very good). I then create a average between the scaled CPU/Mem rating (60% weighed) and disk rating (40% weighed) to create a final ranking score on a scale from 0 to 100. Still have to find out the exact weights though, but the rating gives a global idea of the system’s performance.

# angelo@hongens.nl 2007/5/14
#SET VARIABLE TO CORRECT DISK!
DISK=/dev/sda

#download and compile ubench
cd ~
wget http://www.phystech.com/ftp/ubench-0.32.tar.gz
tar xzf ubench-0.32.tar.gz
cd ~/ubench-0.32
./configure
make

#download and compile seeker
wget -O ~/seeker.c http://www.linuxinsight.com/files/seeker.c.txt
gcc -O2 ~/seeker.c -o ~/seeker
rm ~/seeker.c

~/ubench-0.32/ubench
hdparm -t $DISK
~/seeker $DISK

~/ubench-0.32/ubench
hdparm -t $DISK
~/seeker $DISK

~/ubench-0.32/ubench
hdparm -t $DISK
~/seeker $DISK
Comments
No Comments »
Categories
Hardware, Linux/Unix
Comments rss Comments rss
Trackback Trackback

Novell’s version of the Get A Mac ads

March 25, 2007 | 8:16 am

Three Mac-ad spoofs from Novell:

Links to the Hi-Res Novell Videos

  1. Meet Linux (.mpg) (.ogg)
  2. New Duds (.mpg) (.ogg)
  3. Running Linux (.mpg) (.ogg)
Comments
No Comments »
Categories
Linux/Unix
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Pages

  • Guides
    • IPSec VPN using FreeBSD
    • Monitoring a Windows machine with extended counters
    • Protect OWA using a reverse proxy
    • Setting up OpenVPN using radius on FreeBSD

Categories

  • Games
  • Hardware
  • Linux/Unix
  • Mac
  • Microsoft
  • Misc
  • Security/privacy
  • Virtualization

Archives

  • February 2010
  • March 2009
  • November 2008
  • June 2008
  • February 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • May 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • October 2006

Friends' sites

  • ErwinK’s site
  • Jef’s site
  • Judith’s site

Work

  • NetMatch
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox