Instrumenting an Apache Web Server Using Container-Assisted Injection

If you are using the Apache web server 2.2.7 (and above), you can use the container substitution pattern to automatically inject the eG Real User Monitoring JavaScript agent into your web pages.  This allows you to enable the RUM functionality for your web pages without needing to make any code changes.

Note:

The table below lists the command to be run on each operating system to determine the version of the Apache server running on that system.

Operating System of Apache Server

Command for Determining Apache Version

Debian and Mac OS

apachectl -v

Red Hat Linux and Amazon's EC2 Linux

httpd -v or /usr/sbin/httpd -v

Other versions of Linux

apache2 -v or /usr/sbin/apache2 -v

If the aforesaid commands do not work, then it could be because the login user does not have permissions to execute the commands. In this case, use the sudo command to grant the required permissions to the login user and run either of the commands again.

Windows

"C:\Program Files\[Apache directories]\bin\httpd.exe" -v

This mechanism intercepts the response object as it is being returned and makes a string substitution containing the required JavaScript tag at the appropriate place in the HTML.

Note:

Container-assisted RUM script injection can be used to RUM-enable only those web servers that support the mod_substitute and mod_filter modules. If a web server does not support these modules or supports only one of them, then such web servers cannot be RUM-enabled using the container-based injection method.

The IBM HTTP server 8.x (and below) does not include the mod_substitute module. This means that the container-based injection method cannot be used to RUM-enable this server. You will hence have to use one of the alternate approaches depicted by Figure 1 to RUM-enable the IBM HTTP server 8.x (and below). In the case of the IBM HTTP server 9.x (and above) on the other hand, both the mod_substitute and mod_filter modules are supported. The container-based injection method can hence be used here. Use the procedure detailed in the Instrumenting an IBM HTTP Server v9.x (and above) Using Container-Assisted Injection topic to RUM-enable an IBM HTTP Server 9.x (and above).

The instrumentation steps are as follows:

  1. First, add the web site (on the Apache web server) to be monitored as a Real User Monitor component, using the eG admin interface. When adding, you will find that the RUM code snippet that you need to use for instrumenting the Apache web server is displayed in the eG admin interface. Copy the code snippet.
  2. Open the global Apache httpd.conf file and search for the following commands:

    LoadModule substitute_module modules/mod_substitute.so

    LoadModule filter_module modules/mod_filter.so

  3. Once you find the commands, check if they are commented. If they are, then uncomment them. On the other hand, if they are already uncommented, leave them as is.
  4. Create a directory called egrum on the system hosting the Apache server.
  5. Create a file named egrum.conf in that directory. Enter the following in that file:

    <Location />

    AddOutputFilterByType SUBSTITUTE text/html

    substitute "s|</head>|

  6. Then, after the "s|</head>| tag in the above specification, paste the code snippet you copied from the eG admin interface in step 1 of this procedure. Make sure that you paste the snippet as a single line. The contents of the egrum.conf file will now look as shown below:

    <Location />

    AddOutputFilterByType SUBSTITUTE text/html

    substitute "s|</head>|<script charset='UTF-8' type='text/javascript'>

    window['egrum-start_time'] = new Date().getTime();

    window['Site_Name'] = '57bf9bbe-5712-40e9-929b-f75c5ab300e9-1606389009637';

    window['beacon-url'] = 'http://RUM_COLLECTOR_DOMAIN_NAME:PORT';

    if(!window['egrum-config']) window['egrum-config'] = {}; (function (config) {config.capture = { jsError:true, resourceDetails:true, ajax:true, ajaxCorrelation:false, overwriteBtmUName:false, excludeURLPattern:'none', ajaxExcludeURLPattern:'none', includeURLPattern:'*'};})(window['egrum-config']);

    </script>

    <script src='http://RUM_COLLECTOR_DOMAIN_NAME:PORT/rumcollector/egrum.js' async></script>

     

    After inserting the code snippet, take care to replace the area highlighted in Green, in the sample snippet above, with the exact domain name and port number of the RUM collector.

  1. Then, after the </script> tag highlighted in Red in the sample snippet above, type the following:

    </head>|inq"

    </Location>

  2. The complete contents of the egrum.conf file should look as shown below:

    <Location />

    AddOutputFilterByType SUBSTITUTE text/html

    substitute "s|</head>|<script charset='UTF-8' type='text/javascript'>

    window['egrum-start_time'] = new Date().getTime();

    window['Site_Name'] = '57bf9bbe-5712-40e9-929b-f75c5ab300e9-1606389009637';

    window['beacon-url'] = 'http://RUM_COLLECTOR_DOMAIN_NAME:PORT';

    if(!window['egrum-config']) window['egrum-config'] = {}; (function (config) {config.capture = { jsError:true, resourceDetails:true, ajax:true, ajaxCorrelation:false, overwriteBtmUName:false, excludeURLPattern:'none', ajaxExcludeURLPattern:'none', includeURLPattern:'*'};})(window['egrum-config']);

    </script>

    <script src='http://RUM_COLLECTOR_DOMAIN_NAME:PORT/rumcollector/egrum.js' async></script></head>|inq"

    </Location>

    In the sample contents above, the </head>tag highlighted in Red indicates that this code snippet looks for an exact </head> tag match. Alternatively, you can alter the code snippet to look for a <body> tag match, if required.

  3. Then, save the egrum.conf file.
  4. Next, add the location of the egrum.conf file to httpd.conf, as indicated below:

    Include [absolutePathTo]/egrum.conf

     

    For instance, if the egrum.conf file resides in the C:\egrum folder, then the above specification will be:

    Include C:\egrum\egrum.conf

  5. Finally, save the file and restart the Apache web server.

    Note:

    If Apache HTTP server is configured as a reverse proxy, you must use the Location directive based method , with the ProxyPass and ProxyPassReverse directives, as indicated in the code block below:

    <Location />

    ProxyPass http://mywebsite.index.net/

    ProxyPassReverse http://mywebsite.index.net/

    AddOutputFilterByType SUBSTITUTE text/html

    substitute "s|</head>|<script charset='UTF-8' type='text/javascript'>

    window['egrum-start_time'] = new Date().getTime();

    window['Site_Name'] = '57bf9bbe-5712-40e9-929b-f75c5ab300e9-1606389009637';

    window['beacon-url'] = 'http://RUM_COLLECTOR_DOMAIN_NAME:PORT';

    if(!window['egrum-config']) window['egrum-config'] = {}; (function (config) {config.capture = { jsError:true, resourceDetails:true, ajax:true, ajaxCorrelation:false, overwriteBtmUName:false, excludeURLPattern:'none', ajaxExcludeURLPattern:'none', includeURLPattern:'*'};})(window['egrum-config']);

    </script>

    <script src='http://RUM_COLLECTOR_DOMAIN_NAME:PORT/rumcollector/egrum.js' async></script></head>|inq"

    </Location>

Troubleshooting Tips:

The table below lists the command that you need to run on each operating system to check for syntax errors in changes you made in the configuration files (egrum.conf and httpd.conf). If no syntax errors are detected, then each of these commands will output a message to that effect.

Operating System of Apache Server

Command for checking whether any syntax errors exist in the configuration files

Debian and Mac OS

apachectl configtest

Red Hat Linux and Amazon's EC2 Linux

httpd -t or /usr/sbin/httpd -t

Other versions of Linux

apache2 -t or /usr/sbin/apache2 -t

If the aforesaid commands do not work, then it could be because the login user does not have permissions to execute the commands. In this case, use the sudo command to grant the required permissions to the login user and then run either of the commands again.

Windows

"C:\Program Files\[Apache directories]\bin\httpd.exe" -t