Apache 2 monitored
Introduction
Already written many posts on the Internet, on monitoring the Apache web server. When entering phrases like “load monitoring apache” in the Google search bar, the search results point to the most useful mod_status module. And also about the even greater usefulness of this module in combination with perl-extensions. And if you also patch these perl extensions a little bit, then generally a super system is obtained. But having set up such a system - the system administrator does not usually stop at this, he already needs a load history for the server as a whole, then for each host, and then with the accuracy of the script. And so it was possible to compare, and how it used to be, and how now the load is distributed.
And here the module for the Apache web server -
mod_performance can come to the
rescue .
')
And so, we proceed to the consideration
What this module is. This is a common Apache 2.x module for Linux. From the
documentation for it:
- the module is designed to collect and accumulate statistics on the use of resources (CPU and memory, script execution time) by the Apache 2.2 web server;
- The module allows you to analyze the collected data.
What does all of this mean? And the fact that it allows you to keep track of how many resources consumed by the incoming web server request. Each time saving the following information:
- virtual host that received the request;
- the file that is requested;
- Request URI;
- CPU load in%;
- memory usage in%;
- request processing time.
And the accumulated statistics allows you to analyze. SQLite is used as a database for saving and analysis.
As a resource utilization analyzer, not a scoreboard is used, as in mod_status and perl extensions, but glibtop.
The module allows you to track absolutely all requests, as well as specific ones, filtered by the rule using regular expressions. More precisely, it will be said that the module ALWAYS processes only those requests that match the filter containing the regular expression.
How to view accumulated data
The module provides two interfaces for viewing and analyzing data: 1) global; 2) the so-called per-host.
Each interface is attached to the handler:
user-status - per-host
performance-status - globalAccess to interfaces is configured as in the mod_status module, ie:
<Location / perf-status>
Order allow, deny
SetHandler performance-status
Allow from 1.1.1.1
</ Location>
The global interface allows you to view and analyze the accumulated data on all virtual hosts, while the per-host interface displays and analyzes only the information on the host to which the interface is attached, for example, if you call the host
test.test.test / user-status , then all output statistics will only concern this host. Statistics for other hosts will not be displayed.
The global module management interface looks like the one below:

In the main form, in the picture you can see the fields:
Mode - data display mode.
Period - days, the period for displaying or analyzing data, starting from the beginning of the current day.
Period begin - the beginning of the period specified in the format YYYY-MM-DD hh: mm: ss.
Period end - the end of the period specified in the format YYYY-MM-DD hh: mm: ss.
If Period begin is set, Period end - in this case data limited by these parameters are displayed, and the Period field is ignored. Otherwise, the analyzed area is set by the Period parameter.
Hostname (SQL) - filter, output data only on the specified host. Call syntax is similar to the like construct in SQL. Those. if you specify "% test", then all hosts that end in "test" will be selected.
Script name (SQL) is similar to the previous parameter, only the name of the script being called is analyzed.
URI (SQL) is similar to the previous parameter, only the request URI is analyzed.
Graph Mode (Y / N) - display graphics or text.
The approximate data output looks like this:

The host shown in the example in the picture is absolutely test, if it coincides with the real one - I apologize.
A graphic display mode is shown in the figure below:

Analysis Modes
Show output without analytics - display the collected information without analysis, filtered by host, script and URI (graphic and text mode).
Maximal% CPU - display only entries with the maximum value of% CPU (including filtering).
Maximal memory% - display only records with the maximum value of% memory (including filtering).
Maximal execution request time - display the most long-running script.
Host requests statistics — show statistics of calls to hosts with sorting in descending order (in% of the total, including filters).
Execution history screen (use Period begin) - allows you to calculate a list of running queries for a specified time.
Number of requests per domain - show statistics of calls to hosts with sorting in descending order (not in percents but in numbers).
Average usage per host — print the average server load by each host (% CPU sum,% MEMORY sum, script execution amount, average CPU% for a period, average memory usage%, average script execution time).
I will not go into details and leave some modes without attention.
How to install the module
Here I give an example installation for rpm-systems. All actions must be performed under the root user.
1) install the necessary packages for the assembly:
yum install httpd-devel apr-devel libgtop2-devel sqlite-devel gd-devel
2) create a temporary paku for source codes:
mkdir ~ / my_tmp
cd ~ / my_tmp
3) download the source code of the module and unpack the archive and go to the unpacked folder:
wget http://lexvit.dn.ua/utils/getfile.php?file_name=mod_performance_tar201104233487.gz -O mod_performance.tar.gz
tar zxvf mod_performance.tar.gz
cd mod_performance /
4) we assemble the module:
make
5) warning not to pay attention. The main thing is that there is no error. If everything is ok, then:
make install
or
cp .libs / mod_performance.so <path to copy>
Configuring Apache
The configuration will be performed for the standard Apache installation, that is, the modules are located in the / etc / httpd / modules directory, the /etc/httpd/conf.d/ directory exists and it is connected to /ect/httpd/conf/httpd.conf.
1) create a module configuration file:
touch /etc/httpd/conf.d/mod_performance.conf
2) insert into it:
LoadModule performance_module modules / mod_performance.so
<IfModule mod_performance.c>
PerformanceHistory 5
PerformanceEnabled On
PerformanceMaxThreads 80
PerformanceScript \ .php
PerformanceStackSize 1
PerformanceUseCanonical On
<Location / admin-status>
Order allow, deny
SetHandler performance-status
Allow from 1.1.1.1
</ Location>
</ IfModule>
3) save the file and restart Apache:
service httpd restart
The configuration file serves only as an example. All parameters must be selected for a specific server.
The above module configuration allows you to track requests for php scripts.
A description of all configuration parameters can be found in the module documentation.
Attention, currently, the module cannot track requests for Apache + mod_fcgid, Apache + mod_cgid server configurations or configurations, where the request is processed by a separate daemon.This completes the module review.