Apache server-status – better looking

Apache provides a module to see the server-status. However the page is not too good looking. So, if you want to see a better looking information page, then you can download :

http://sourceforge.net/projects/pimpapachestat/

More details from the readme file of the project:

 

REQUIREMENTS
* On the system you want to install the pimped Apache status:
– any webserver with php 5 (with curl; no database is needed)
* On all webservers you want to monitor:
– apache 2.x
– installed module mod_status and ExtendedStatus On
– permission for the monitoring server to request the the
alias /server-status (see below)

And tehn for installation:

INSTALL
1. Extract the files somewhere below webroot on your webserver. You
can put to any subdirectory. It is not a must to have it in the
webroot.
— OR —
checkout sources with svn client:
cd [webroot-directory]
svn checkout http://svn.code.sf.net/p/pimpapachestat/code/trunk apachestatus
2. Allow your server to access the server-status page on the systems
you want to monitor
<Location /server-status>
SetHandler server-status
order deny, allow
allow from 127.0.0.1
allow from 192.168.123.4 # enter ip of your monitoring system
deny from all
</Location>
3. Open http://localhost/apachestatus/ in your webbrowser.
4. In ./conf/ directory: open config_user.php and setup the systems you want
to monitor. See config_default.php to see other thing you could override

Note: If you are using latest apache version then the <Location> entry should be :

<Location /server-info>
SetHandler server-info
Require all granted
</Location>

 
CUSTOMIZATION
* change or add language: see readme in subdirectory ./lang/
* change theme:
– make copy ./templates/default/
– make changes in style.css and out_html.php in your copy
– set skin in ./conf/config_user.php:
$aUserCfg = array(
‘skin’ => ‘name_of_subdir’,
);

If you have a language or a theme to share then send it to me.

 

Apache server stats with small and useful bash script.

Just copy this script to your web-server cgi-bin directory and enjoy.

The script with show the common errors like 404 Error, Internal Server Error and others. It will show the User agent distribution using simple commands like grep, uniq, awk and so on.

You would need to change the tfile – which is temporary file and also the access.log path in the next line.

Just re-direct the output to some file with html extenstion. You could even put this in the cron which re-directs the output to some html in server document root.

#!/bin/bash
tfile=/tmp/apache.log
sudo grep $(date '+%d/%b/%Y') /var/log/apache2/access.log >$tfile
thits=$(grep -c . $tfile)
echo "Content-type: text/html"
echo ""
echo "Report for $(date '+%d/%b/%Y')

Report for $(hostname) on $(date ‘+%d/%b/%Y’)

"

echo "Total hits :: $thits"
echo ""
echo "User agent distribution :: "
#awk -F" '{print $6}' $tfile  | sort | uniq -c | sort -fr

awk -F" '{print $6}' $tfile | sed 's/(([^;]+; [^;]+)[^)]*)/(1)/' |sort |uniq -c|sort -fr

echo "
User response code: "
awk 'BEGIN{
a[200]="OK";
a[206]="Partial Content";
a[301]="Moved Permanently";
a[302]="Found";
a[304]="Not Modified";
a[401]="Unauthorised (password required)";
a[403]="Forbidden";
a[404]="Not Found";
a[500]="Internal Server Error";
}
{print $9 " => "a[$9]""}' $tfile | sort | uniq -c | sort -nr

echo "
404 Error Summary::"
awk '($9 ~ /404/)' $tfile | awk '{print $9,$7}' | sort | uniq -c|sort -nr|head -5

echo "
IP Visit counts :: "
awk '{print $1}' $tfile | grep -o "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" | sort -n | uniq -c | sort -nr|while read count ip
do
	name=$(echo $ip|/usr/bin/logresolve)
	printf "%5st%-15st%sn" $count $ip $name
done

# cat $tfile |grep -o "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}" | sort -nr | uniq -c | sort -n

echo "
Top Agents :: "
cat $tfile | awk -F" '{print $6}'| sort -n | uniq -c | sort -nr |head -5 

echo "
Top urls ::"
cat $tfile  | awk -F" '{print $2}'| sort -n | uniq -c | sort -nr |head -5

echo -n "
Total Bytes ::: "
cat $tfile | awk '{ sum += $10 } END { if ( sum > 1024*1024) {print sum/(1024*1024)"Mb"}else if ( sum > 1024) {print sum/1024"Kb";}else print sum }'

echo -n "
Total Seconds :: "
cat $tfile  | awk '{ sum += $13 } END { print sum }'
# sed 's/.*GET (.*) HTTP.*/1/g' $tfile|awk -F/ '{if ( NF > 3 ) print $2"/"$3"/"$4; else print $2;}'|sort|uniq -c

Apache Server Stats – Download the script in zip file format.

And here is a sample ::

Report for <server> on <date>

Total hits :: 

User agent distribution :: 

User response code: 

404 Error Summary::

IP Visit counts :: 

Top Agents :: 

Top urls ::

Total Bytes ::: 

Total Seconds ::

Hope that it will be useful.

Enhanced by Zemanta