Monitoring Apache on Instances
Overview#
Apache Server’s monitoring involves monitoring of the following elements:
Apache Access Logs
Apache Error Logs
Apache Server Health
Pre-requisites#
Ensure Apache access logs are in format expected by sfAgent parser.
Edit configuration file and set log format as follows:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D"combined  CustomLog "logs/access_log" combined After configuring log format, the expected log entry would be:
45.112.52.50 - - [28/Jun/2020:23:34:10 -0700] "GET / HTTP/1.1" 302 242 "-" "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36" 271 Apache configuration file can be found in these paths:
- Ubuntu:
/etc/apache2/mods-enabled/status.conf  - Centos:
/etc/httpd/conf/httpd.conf
- Ubuntu:
Check if Apache status module is enabled
This is required to monitor Apache server health
Apache web server exposes metrics through its status module, mod_status. If apache server is running and mod_status is enabled, apache server’s status page should be available at http://127.0.0.1/server-status. Or http://localhost/server-status. 
Alternatively, you can check is mod_status is enabled by running the following commands:
Ubuntu(or Debian based systems):
sudo apache2ctl -M | grep status_module Centos/RHEL/Fedora
sudo httpd -M | grep status_module if output of above command is 
status_module , then apache status module is enabled. If mod_status is not enabled , follow next step to enable itEnable Apache status module
In order to enable mod_status ,  edit the status module’s configuration file (on Debian platforms), or your main Apache configuration file (all other Unix-like platforms). 
Debian users can find the status module’s configuration file in 
/etc/apache2/mods-enabled/status.conf Users of other platforms (such as Red Hat–based systems) will find their main configuration file in
/etc/apache2/apache2.conf, /etc/httpd/conf/httpd.conf, or /etc/apache2/httpd.conf.  In the main configuration file, allow access from local or from a specific ip address as shown below:  
   <Location /server-status>         SetHandler server-status         Require local   #     Require all granted         Require ip x.x.x.x     </Location> Check your configuration file for errors with the following command:
apachectl configtest  Perform a graceful restart to apply the changes without interrupting live connections:
(apachectl -k graceful or service apache2 graceful) After enabling mod_status and restarting Apache, status page is accessible at http://localhost/server-status  or http://ipaddress/server-status.
Configuration#
sfAgent section provides steps to install and automatically generate plugin configurations. User can also manually add the configuration shown below to config.yaml under /opt/sfagent/ directory
key: <profile key> generate_name: true tags: Name: <unique instance name or will be generated from IP> appName: <add application name> projectName: <add project name> metrics: plugins: - name: nginx enabled: true interval: 300 config: port: 80 secure: false location: ‘stats’ logging: plugins: - name: nginx-access enabled: true config: geo_info: true log_path: /var/log/nginx/access.log, /var/log/nginx/access_log ua_parser: true - name: nginx-error enabled: true config: log_level: - emerg - alert - error log_path: /var/log/nginx/error.log, /var/log/nginx/error_log Viewing data and dashboards#
Data generated by plugin can be viewed in browse data page inside the respective application under plugin=jvm and documentType=jvm
Dashboard for this data can be instantiated by Importing dashboard template JVM to the application dashboard.