apachetop icon indicating copy to clipboard operation
apachetop copied to clipboard

added support for logfile-per-domain environments

Open the0ne opened this issue 1 year ago • 7 comments

Hosting environments often tend to use an individual log file for each domain. As the domain name isn't included in the URL, the name of the log file is the only clue on which domain a request was served for. In conjunction with the following command, a large number of log files can be handled by apachetop and the names of the log files can be shown to the user.

ls -t /var/log/apache2/logs/*.log | head -n 2000 | sed -e 's/^/-f /' | xargs -o apachetop

the0ne avatar Feb 12 '24 15:02 the0ne

Thanks for your contribution.

Hosting environments often tend to use an individual log file for each domain.

What exactly do you mean by that?

I would imagine they'd use something like this:

LogFormat "%v %h %u [%{%F %T}t.%{usec_frac}t %{%z}t] \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhosts

It does not include the host in the URL, but has a separate field. I don't know off the top of my head whether apachetop supports such a host field, since I have only maintained it and fixed a few bugs. I don't have the code in my head. After goaccess came out, I believe the usefulness of apachetop came to an end.

Wouldn't adding support for this make more sense? Although, if hosting providers don't add that field, it won't help.

Don't get me wrong, I am more than happy to merge your PR, but I'd still like to understand your use-case a bit better.

tessus avatar Feb 12 '24 19:02 tessus

No problem, I'm happy to explain. I realize I didn't find the right words initially, so I'll retry. Basically it seems to be common to not have one log file for all the (many) domains on one host. By using VirtualHost entries together with CustomLog and ErrorLog the log messages are split into individual files. By that, each domain on the system has it's own access and error log files.

Example for domain.tld

  <VirtualHost *:80>
      ServerAdmin [email protected]
      DocumentRoot /home/domain.tld/www
      ServerName domain.tld
      ServerAlias www.domain.tld
      CustomLog ${APACHE_LOG_DIR}/logs/domain.tld.log combinedio
      ErrorLog ${APACHE_LOG_DIR}/errors/domain.tld.log
  </VirtualHost>

With the LogFormat combinedio being

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O"   combinedio

There's several advantages of this approach.

  • Something like AwStats can be run on a per-domain basis.
  • No need to write the domain name into the log file over and over again.
  • The log can be made available to the user easily.
  • etc.

the0ne avatar Feb 12 '24 20:02 the0ne

Thanks for the clarification. Makes sense then. If they leave out the host field, this is basically the only viable solution.

I still have to review the code. Just by looking at it, I am missing some context, e.g. you never defined DISPLAY_FILES, but maybe it's been already defined. I'll have to check.

tessus avatar Feb 12 '24 20:02 tessus

e.g. you never defined DISPLAY_FILES, but maybe it's been already defined

100% true. It honestly looked to me as if somebody had already started exactly what I had needed, but had never finished implementing it.

the0ne avatar Feb 12 '24 20:02 the0ne

I will also have to check the workflow. It seems to me this is now active without being able to turn this off. This could be a problem then, because not all log file names contain the hostname.

I am currently busy with a few other things, but I should be able to look into this within the next few days.

Gruesse nach Oesterreich!

tessus avatar Feb 12 '24 20:02 tessus

Sorry, I still haven't got around to it yet, but at one point when I browsed through the changes I noticed that it might be necessary not to resuse DISPLAY_FILES. It think that might be used for something else already.

tessus avatar Mar 06 '24 23:03 tessus

Hi, when I checked the existing code before adding the feature, I had found that somebody had already started the new view. But it was never triggered anywhere to be included in the build.

I didn't find that define to be ever activated anywhere.

the0ne avatar Mar 07 '24 06:03 the0ne