mod_proctitle - Apache module for displaying requests and brief statistics in the program name (top and ps output)

    Often there is a situation when you need to quickly assess what your web server is doing. Sometimes, to reassure, "it seems he is not." When the server has one Apache, one site, the load is small - there are no problems. He went in, top looked. / server-status looked, tail -f did the logs, meditated - and usually everything is clear. However, there is a situation where there are many, many apache sites themselves (almost all operating systems can now lift several apache web servers out of the box, but this is rarely used for some reason). There is a situation where apache cannot even answer. It would be nice, at least roughly to estimate what Apache workers do (or have already done). Imagine - you are doing ps -aux , and you have there - who asks what URLs, how wide the channel is busy, what is the speed - nya!

    I have been using a patch for apache for a long time, which, after parsing the request line, writes to the IP program name, where the request came from, what came in the Host header and the request line itself. But this two-line patch was written 12 years ago for Apache version 1.3. And then the hands did not reach. Moreover, since that time there have been many (I found at least two in five minutes) varieties of modules for those purposes, for newer versions of Apache. However, over time, it became not enough for me to simply query lines. And ... I wrote my module.

    Doctor, where did you get such pictures?

    At first, I was tormented by the lack of documentation for developers at Apache. I had to look for the necessary hooks by re-reading the entire source code. Not when you are already writing the 10th module, it can be fine, but when the first and maybe the last is a problem.

    When I managed to find the ap_hook_monitor () hook, which is called from the apache root process every 20 requests or every 1 second, I was overwhelmed with the thirst to push as much cool statistics into the string as possible. I tried all sorts of statuses, quantities, loading in 10 seconds, 1 minute, 5 minutes, uptime ... But looking at the result, I realized that this tinsel only interferes and left only bitrate and requests per second.

    The most important innovation in the module is the Complete and Incomplete Listen Queue Lenght values. This is when we write BackLog to httpd.conf in some places, the requests that the server does not have time to accept are accumulated in this queue. And when the queue is full - they begin to be discarded. Usually this happens with the habraeffect, for example, or if the site accesses a third-party resource, and the site is “lying” or blocked (for example, recently github). And here the digit in the listen queue and the qps digit are very helpful to our eye.

    How all is bad in these your Linux

    It suddenly turned out that with small victims the module can only be written under FreeBSD. To change the name of the program there is a setproctitle () function, and you can see Complete and Incomplete Listen Queue Lenght through the getsockopt () call with the SO_LISTENQLEN and SO_LISTENINCQLEN parameters.

    For Linux, everything is more complicated. It is required to take the name of the executable file and always append it separately (FreeBSD does this automatically). This is necessary to remember that the vast majority of rc scripts use the name that shines in ps in order to start / restart.

    For Linux, it turned out to be difficult and the values ​​of Listen Queue can be found. So far, I see an option for working with netlink (7). But the details slip away.

    Pour in

    For FreeBSD + Apache 2.4, the module is fully functional. You can try it on other versions of Apache. It is possible and necessary to help port it to Linux.

    The module is distributed in the source code and you can do whatever you want with it:

    PS Nekstati, I want to supplement it with the function of periodically resetting statistics on UDP somewhere. A little more complete.

    Also popular now: