Monitoring Apache

Configure the Server Density agent to monitor your Apache server to:

• Collect important metrics, such as requests, CPU usage & busy workers
• Identify overall server slowdowns caused by the web server

Monitored metrics

  • Busy workers
  • Requests per second
  • Idle workers
  • CPU Load
  • Uptime
  • Bytes per Second
  • Bytes
  • Hits

Installing the Apache plugin package

Install the Apache plugin on Debian/Ubuntu:

sudo apt-get install sd-agent-apache

Install the Apache plugin on RHEL/CentOS:

sudo yum install sd-agent-apache

Read more about agent plugins.

Configuring the agent to monitor Apache

1. Ensure the mod_status module is installed. This is usually compiled in by default but you may need to uncomment a line in your httpd.conf file:

#LoadModule status_module modules/mod_status.so
  • Removing the # will uncomment the line and enable mod_status.

On packaged Ubuntu Apache installations you can enable the mod_status module by using the a2enmod command:

sudo a2enmod status

2. Adding the following line to your httpd.conf file will enable the mod_status output.

ExtendedStatus On
  • If you restart Apache after adding this line and get an error, check that mod_status has been installed correctly. Look in your Apache error_log for details.

You then need to add in the following lines to set up the location from which the status output can be parsed by the agent:

<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from localhost
</Location>

This will allow the status output to be accessed from http://localhost/server-status (localhost only works on the server itself - replace localhost with your server IP and it will be accessible externally to the IPs you specify in the Allow list, see below).

  • You will now need to restart your Apache web server to allow the changes to take effect.

3. Configure /etc/sd-agent/conf.d/apache.yaml

init_config:
instances:
- apache_status_url: http://localhost/server-status?auto
  • If you have password protected the status page, you should configure the username and password for the authorized user:
apache_user: serverdensity
apache_password: supersecretpassword

4. Restart the agent

sudo /etc/init.d/sd-agent restart

Verifying the configuration
Execute info to verify the configuration with the following:

sudo /etc/init.d/sd-agent info 

If the agent has been configured correctly you’ll see an output such as:

apache
-----
- instance #0 [OK]
- Collected 8 metrics & 0 events

You can also check the metrics that the check is returning with the following command

sudo -u sd-agent /usr/share/python/sd-agent/agent.py check apache

Error: server-status not found
If you get a 404 error or a different page loads when you access the server status, you may have some .htaccess rewrite rules that are preventing Apache from handling the request. You can use this rewrite conditional to ensure requests get processed correctly. This goes above the rewrite rule that is catching the request to server-status

RewriteCond %{REQUEST_URI} !=/server-status

Configuring Graphs
Click the name of your server from the Devices list in your Server Density account then go to the Metrics tab. Click the + Graph button on the right then choose the Apache metrics to display the graphs. The metrics will also be available to select when building dashboard graphs.

Further Reading

We have a detailed blog post on how to monitor Apache.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

  • Avatar
    Richard Howes

    There is an error on this page, at least for Ubuntu 14.04.

    You need to use "127.0.0.1" in both the apache config and the SD config files. You cannot interchange this and "localhost" otherwise you will get a 403 error.

    Edited by Richard Howes
  • Avatar
    Steve Hurley

    Hi Richard,

    Thanks for pointing this out, we've gone ahead and updated the article so that only localhost is used.

Monday  —  Friday.

10am  —  6pm UK.

Dedicated Support.