Monitoring Apache logs using Python

Posted by asanabria6910 on Mar 23, 2009 4:09 PM EDT
linuxdynasty.org; By Christopher Hahn
Mail this story
Print this story

Apache, among many other httpds, can be configured to log to an executable's STDIN instead of a file. But older Apaches, again like other httpds, won't let you pipe that programme's output to another's input, so you're limited to whatever the one was made to do.* httpd error logs often contain error conditions one wants to be alerted about, but for most people that means either monitoring it with some variant of tailf running on the host, or sshing to the host to run tail (or tail -f) on the log, piped to egrep, etcetera. This kind of set-up can work fine for one or two web servers, but gets cumbersome when you have more than just a few, and can become impracticable when dealing with many or when the error logs are being written to frequently.

Apache, among many other httpds, can be configured to log to an executable's STDIN instead of a file. But older Apaches, again like other httpds, won't let you pipe that programme's output to another's input, so you're limited to whatever the one was made to do.*

httpd error logs often contain error conditions one wants to be alerted about, but for most people that means either monitoring it with some variant of tailf running on the host, or sshing to the host to run tail (or tail -f) on the log, piped to egrep, etcetera. This kind of set-up can work fine for one or two web servers, but gets cumbersome when you have more than just a few, and can become impracticable when dealing with many or when the error logs are being written to frequently.

Well, I sometimes have to deal with six hundred or more. Screw ssh 'tailf | egrep' ...

This Python script/module (tailcast.py) will monitor a file or STDIN (a la tailf) and send UDP datagrams to a specified address. The datagrams can be restricted to only those input lines that match a regular expression, and every line of input still becomes a line of output. The result?

ErrorLog "| /usr/bin/python /usr/local/bin/tailcast.py -a 224.168.2.9 -p 5664 -r interestingerror|otherbadness | cronolog ..."

Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: Community, Linux

« Return to the newswire homepage

This topic does not have any threads posted yet!

You cannot post until you login.