Cheatsheet: Apache Server (HTTPD) Monitoring: More Info

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Cheatsheet: Apache Server (httpd) Monitoring

Note:
ʒʒ Direct the curl commands to your server's IP address, e.g. curl localhost/server-status?auto
ʒʒ Windows users should download cURL to use the commands below
ʒʒ To query these metrics, mod_status and ExtendedStatus must be enabled (more info here)
ʒʒ For more info on Apache monitoring, visit dtdg.co/monitor-apache

Throughput and latency metrics—more info Useful commands (Linux)


METRIC DESCRIPTION COMMAND ACTION DEBIAN/UBUNTU RHEL/CENTOS
Total requests* curl -s localhost/server-status?auto | grep 'Total Accesses' Check version of Apache apachectl -v httpd -v

Total kilobytes served* curl -s localhost/server-status?auto | grep 'Total kBytes' Check which modules are loaded apachectl -M httpd -t -D DUMP_MODULES

Total requests served/sec* curl -s localhost/server-status?auto | grep 'ReqPerSec' Enable a module* sudo a2enmod <MODULE_NAME> Uncomment or add the module to the config file
curl -s localhost/server-status?auto | grep 'BytesPerSec'
(/etc/httpd/conf.modules.d/00-base.conf )
Total bytes served/sec*
Disable a module* sudo a2dismod <MODULE_NAME> Comment out or remove the module from the config file
(/etc/httpd/conf.modules.d/00-base.conf )
*Calculated over the server's entire lifetime
Update the MPM* (mpm_worker, Disable the current MPM module: Comment out LoadModule for current MPM module &
mpm_prefork, or mpm_event) sudo a2dismod <MPM_NAME> uncomment desired module in
and then enable the desired MPM module: /etc/httpd/conf.modules.d/00-mpm.conf
sudo a2enmod <MPM_NAME>
Resource utilization and activity metrics—more info Check config file syntax apachectl -t httpd -t
METRIC DESCRIPTION COMMAND Restart Apache sudo apachectl restart sudo service httpd restart
CPU utilization (over the server's lifetime) curl -s localhost/server-status?auto | grep 'CPULoad'
Gracefully restart Apache sudo apachectl graceful sudo service httpd graceful
Busy workers curl -s localhost/server-status?auto | grep 'BusyWorkers'

Idle workers curl -s localhost/server-status?auto | grep 'IdleWorkers' *Requires a restart to take effect
Asynchronous connections: writing* curl -s localhost/server-status?auto | grep 'ConnsAsyncWriting'

Asynchronous connections: keep-alive* curl -s localhost/server-status?auto | grep 'ConnsAsyncKeepAlive'

Asynchronous connections: closing* curl -s localhost/server-status?auto | grep 'ConnsAsyncClosing' Access log variables—more info
To update your log config:
*Only available for event MPM users ʒʒ RHEL/CentOS: Update <IfModule log_config_module> within your main config file (/etc/httpd/conf/httpd.conf)
ʒʒ Debian/Ubuntu: Update CustomLog line within Virtual Host file (within /etc/apache2/sites-enabled directory)
Combined LogFormat: "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
Common LogFormat: "%h %l %u %t \"%r\" %>s %b"
Default directories and config locations (Linux)
INFORMATION DEBIAN/UBUNTU RHEL/CENTOS VARIABLE DEFINITION
%h Remote hostname
Main configuration file /etc/apache2/apache2.conf /etc/httpd/conf/httpd.conf
%l Remote logname
Error and access logs /var/log/apache2 /var/log/httpd
%u Remote user
MPM configuration file /etc/apache2/mods-enabled/<MPM_NAME>.conf Add/edit the <IfModule MPM_NAME> directive in main
config file (location above) %t Time Apache received the request, formatted as [16/Jun/2017:15:59:09 -0400] with last number as
time zone offset from GMT
mod_status permissions /etc/apache2/mods-enabled/status.conf Edit the <Location /server-status> directive in
main config file (location above) \"%r\" First line of the request in quotes (e.g. "GET /server-status?auto HTTP/1.1")
%>s Final HTTP status of request
%b Size of response (bytes)
\"%{Referer}i\" Referer: address of the referring web page
\"%{User-agent}i\" User-Agent: web browser or agent issuing the client request
Cheatsheet: Apache Server (httpd) Monitoring with Datadog
Note:
ʒʒ To collect these metrics, your servers must have mod_status and ExtendedStatus enabled (more info here)
ʒʒ For metric descriptions and more info: dtdg.co/monitor-apache

Useful commands (Linux)


ACTION DEBIAN/UBUNTU RHEL/CENTOS
Check version of Apache apachectl -v httpd -v

Check which modules are loaded apachectl -M httpd -t -D DUMP_MODULES

Enable a module* sudo a2enmod <MODULE_NAME> Uncomment or add the module to the config file
(/etc/httpd/conf.modules.d/00-base.conf )
Disable a module* sudo a2dismod <MODULE_NAME> Comment out or remove the module from the config file
(/etc/httpd/conf.modules.d/00-base.conf )
Update the MPM* (mpm_worker, Disable the current MPM module: Comment out LoadModule for current MPM module &
mpm_prefork, or mpm_event) sudo a2dismod <MPM_NAME> uncomment desired module in
and then enable the desired MPM module: /etc/httpd/conf.modules.d/00-mpm.conf
sudo a2enmod <MPM_NAME>
Check config file syntax apachectl -t httpd -t

Restart Apache sudo apachectl restart sudo service httpd restart

Gracefully restart Apache sudo apachectl graceful sudo service httpd graceful

*Requires a restart to take effect

Access log variables—more info


Datadog's out-of-the-box screenboard for monitoring Apache. To update your log config:
ʒʒ RHEL/CentOS: Update <IfModule log_config_module> within your main config file (/etc/httpd/conf/httpd.conf)
ʒʒ Debian/Ubuntu: Update CustomLog line within Virtual Host file (within /etc/apache2/sites-enabled directory)
Combined LogFormat: "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
Throughput metrics—more info Common LogFormat: "%h %l %u %t \"%r\" %>s %b"
METRIC DESCRIPTION DATADOG METRIC NAME VARIABLE DEFINITION
Total requests over the server’s lifetime apache.net.hits %h Remote hostname
Total bytes served over the server’s lifetime apache.net.bytes %l Remote logname
Requests served/sec* apache.net.request_per_s %u Remote user
Bytes served/sec* apache.net.bytes_per_s %t Time Apache received the request, formatted as [16/Jun/2017:15:59:09 -0400] with last number as
time zone offset from GMT
*Calculated for each collection period (15–20 seconds) \"%r\" First line of the request in quotes (e.g. "GET /server-status?auto HTTP/1.1")
%>s Final HTTP status of request
%b Size of response (bytes)
Resource utilization and activity metrics—more info \"%{Referer}i\" Referer: address of the referring web page
METRIC DESCRIPTION DATADOG METRIC NAME \"%{User-agent}i\" User-Agent: web browser or agent issuing the client request
CPU utilization (%) system.cpu.system

Busy workers apache.performance.busy_workers

Idle workers apache.performance.idle_workers

Asynchronous connections: writing* apache.conns_async_writing

Asynchronous connections: keep-alive* apache.conns_async_keep_alive

Asynchronous connections: closing* apache.conns_async_closing

*Only available for event MPM users

Default directories and config locations (Linux)


INFORMATION DEBIAN/UBUNTU RHEL/CENTOS
Main configuration file /etc/apache2/apache2.conf /etc/httpd/conf/httpd.conf

Error and access logs /var/log/apache2 /var/log/httpd

MPM configuration file /etc/apache2/mods-enabled/<MPM_NAME>.conf Add/edit the <IfModule MPM_NAME> directive in main
config file (location above)
mod_status permissions /etc/apache2/mods-enabled/status.conf Edit the <Location /server-status> directive in
main config file (location above)

You might also like