📜 ⬆️ ⬇️

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

Often there is a situation when you need to quickly assess what your web server does. Sometimes to calm "like him". When there is one apache on the server, one site, the load is small - there are no problems. Came in, looked top. / server-status looked, tail -f did logs, meditated - and usually everything is clear. However, there is a situation when there are many, many apache sites themselves (almost all OSs now are able to raise several apache web servers out of the box, but for some reason they rarely use this). There is a situation when apache already cannot answer. As it would be good, at least to estimate approximately what the Apache workers do (or have already done). Imagine - you do ps -aux , and you have there - who requests which URLs, how wide the channel is, what the speed of work is nya!

I have been using the apache patch for quite a long time, which after parsing the query string, writes the name of the IP program, where the query came from, what came in the Host header and the query string 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, many (I have found at least two in five minutes) varieties of modules for those purposes, for newer versions of Apache, have appeared. However, over time, I just didn’t have enough query strings. And ... I wrote my module.

Doctor, where do you get these pictures from?


At first, I suffered from the lack of developer documentation for Apache. We had to look for the necessary hooks by rereading the entire source code. Not when you are already writing the 10th module, it can be excellent, and when the first and maybe the last one 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 thirsty to cram as many cool statistics as possible into the string. 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 hinders and left only the bitrate and requests per second.
')
The most important innovation of the module are the values ​​of Complete and Incomplete Listen Queue Lenght. This is when we write BackLog into httpd.conf to the prototypes, requests that the server does not have time to receive are piling up in this queue. And when the queue is filled - begin to be discarded. Usually this happens when habraeffekt for example, or if the site accesses a third-party resource, and that is "lying" or blocked (such as recently github). And this is where the eye in the listen queue and the figure qps are very helpful to our eye.

How bad is this in your Linux?


Suddenly it turned out that the module can be written only for FreeBSD with minor victims. To change the name of the program, there is a setproctitle () function, and you can see the Complete and Incomplete Listen Queue Lenght via 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 add it separately (FreeBSD does this automatically). This is necessary because the vast majority of rc scripts use a name that lights in ps for startup / restart purposes.

For Linux, it was not easy and the values ​​of Listen Queue to find. So far, I see the option of working with netlink (7). But the details slip away.

Join in


For FreeBSD + Apache 2.4, the module is completely functional. You can try it on other versions of Apache. Can and should be helped to port it to Linux.

The module is distributed in source code and you can do whatever you want with it:
github.com/schors/mod_proctitle

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

Source: https://habr.com/ru/post/240767/


All Articles