Realtime Webserver Access Monitoring For Linux Users

For my arduino project i needed to find a way of monitoring webserver requests in realtime.

This is how it works:

On the server side i start a script that monitors the apache access log. The script just pipes useful lines into ncat to send them to connected client. <a href="">ncat</a> is similar to netcat but it allows multiple connections. ncat is included in the nmap package. You can also use netcat but this would limit you to one client connection. The stdbuf command is very important since it changes the output buffering. Otherwise you would receive big chucks of data instead of discrete lines.

On the server side:

tail -f -n 20 $LOG | stdbuf -oL awk '{print $7 " "  $9}'  | stdbuf -oL  grep "/?p" |  ncat -l 2222 -m 20 -k

On the client side you need the following script:

On the client side a script is used that connects to the ncat server and reads the piped lines. Those lines are then passed to the notify-send command which is a neat small command that displays a notification message on your desktop. I don’t recommend that you open the port 2222 to access it from the internet. Instead you could use openvpn to keep a open connection to your server or use ssh port forward.

nc yourwebserver 2222 | while read line  ; do
  echo $line
  notify-send "Blog: $line"