Everyone knows what Apache web server is and that the Internet basically runs on it, but few know how to effectively monitor and graph statistics of Apache. Most people just check whether the website is available and leave it at that. The cross your fingers and hope it works solution is not acceptable for Enterprise level of monitoring.Apache has a great tool to allow you to monitor your web server, mod_status. You can monitor such things as Total kBytes served, Total Uptime, Requests/Second, and much more.
However, when you enable this module, it only presents the data on a local machine. This can get very frustrating and annoying for the sysadmin who has many web servers to monitor. You would have to load up each web page on each server that presents the stats. How annoying, now you have great statistics, but no reasonable way to view them across your multiple web-servers.
Monitis (https://www.monitis.com/), a hosted statistics and monitoring provider, offers a very simple solution to add these monitors in your Custom Dashboard. Once you have these statistics available in your Dashboard, you will be able to easily get an overview of your Apache web servers and analyze the traffic that is on your web site. Be sure to get an account for Monitis here: https://www.monitis.com/free_signup.jsp before continuing.
First you need to ensure that you have mod_status enabled:
Then you need to configure Extended Status in your status module configuration:
<IfModule mod_status.c> ExtendedStatus On <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from localhost ip6-localhost </Location> </IfModule>
Now you are able to access http://localhost/server-status from the same machine. The server-status page has many useful statistics about apache currently running, and has an easier to parse version at http://localhost/server-status?auto
We will setup a Custom Monitor using a script downloadable free from github open source repository.
This script can be run like this to create a monitor that will store the information found on the server-status page:
./API/monitis_create_monitor.sh -n "Apache Monitor" -m apacheMonitor -r "Accesses:Total Accesses:count:2;kBytes:Total kBytes:kBytes:2;CPULoad:CPU Load:load:2;Uptime:Uptime:secs:2;ReqPerSec:Avg Requests per Sec:requests:2;BytesPerSec:Avg Bytes Per Sec:bytes:2;BusyWorkers:Busy Workers:count:2;IdleWorkers:Idle Workers:count:2;" -a API_Key -s Secret_Key
We will not store the Scoreboard. To populate the Custom Monitor we just created, we will use another script: monitis_apache_stats.sh. This script will collect the stats from the server-status page and then send them to Monitis. Be sure to update the script with the proper locations of the server-status page. You will also need another script downloaded from:monitis_add_data.sh in order to send the data to the Custom Monitor.
Now you can place the apache stats script in a crontab and gather the statistics automatically:
*/5 * * * * /path/to/monitis_apache_stats.sh #Gather stats every 5 mins
Say we also want to monitor the stopping, starting and reloading of Apache web server in our Custom Dashboard also. This will allow you to see that a website has been restarted, even though the sysadmin keeps telling you that it was not restarted. It will also allow you to see if issues are being caused by automated processes restarting Apache.
In order to monitor the starting and stopping of Apache we will use the same Custom Monitor creation script:monitis_create_monitor.sh to create our Custom Monitor:
./API/monitis_create_monitor.sh -n "Apache Monitor" -m apacheMonitor -r "action:Action:action:3;action_val:Action Value:value:2" -a API_Key -s Secret_Key
Now we can use the add data script:monitis_add_data.sh to send data to the Custom Monitor. In order to do this we will modify the Start/Stop commands in the Apache init script:
case $1 in start) … /path/to/monitis_add_data.sh -m apacheStartStopMonitor -r "action:$1;action_val:1" -a API_Key -s Secret_Key > /dev/null ;; stop) … /path/to/monitis_add_data.sh -m apacheStartStopMonitor -r "action:$1;action_val:0" -a API_Key -s Secret_Key > /dev/null ;;
And so on and so forth, for each case statement that you want to monitor the action on. The action_val is for graphing the results or for notification rules, any value can be placed in there, it may also be omitted completely. The most useful case for this monitor is so that you can be alerted if someone “accidentally” stops the Apache service. You can do this by setting up Custom Monitors Notifications. From within the monitor, you can choose the Edit Icon in the upper right corner, and a screen will popup where you choose, Notification Rules:
Here you can setup a rule based on the action_val value. For instance, if you want an alert each time your Apache is stopped – you will create an action when action_val = 0.
Now you are able to easily and efficiently monitor your Apache status, something that most organizations leave up to chance. This will allow you to analyze your web servers and know if you need to add another one or not. The graphs available to you will also show you your busy times versus your downtimes, allowing better planning and implementation strategies. The benefits to monitoring your Apache statistics in one easy to view Dashboard are vast. And you have it all in one place, easily accessible and easily graphed because you signed up for a Monitis account and utilized the Custom Monitoring features: https://www.monitis.com/free_signup.jsp
External Links for further information:
25 Apache Performance Tuning Tips