Ticket #2180 (closed malfunction: fixed)

Opened 2 years ago

Last modified 2 years ago

/var/log/ispcp/logdb doesn't get properly updated and is causing wrong statistics

Reported by: aseques Owned by: kilburn
Priority: major Milestone: ispCP ω 1.0.4
Component: Frontend (GUI) Version:
Severity: Medium Keywords:
Cc:

Description

After looking a bit more in depth the problems with stats we noted that the file keeping the pointers to the most recent logs is always properly updated. The proper solution it to update the logdb values just after reloading the apache in logrotate.d We are using this perl script (located in /var/www/ispcp/engine/traffic/update_logdb_apache) in the postrotate execution of logrotate.

It depends partly on #2097 because there's need to know how is the apache rotation handled

Attachments

update_logdb_apache Download (1.1 KB) - added by aseques 2 years ago.
Perl script to update logdb contents
apache2.logrotate Download (649 bytes) - added by aseques 2 years ago.
apache logrotate file to replace the distribution one
ispcp-vrl-traff.patch Download (10.3 KB) - added by kilburn 2 years ago.

Change History

Changed 2 years ago by aseques

Perl script to update logdb contents

Changed 2 years ago by aseques

apache logrotate file to replace the distribution one

comment:1 Changed 2 years ago by kilburn

I think that you misunderstood how does this "logdb" stuff work. As I understand it, this "db" stores the offset at where EOF was found in the previous execution. Therefore, on the next execution, the statistic parser reads this value, and:

If prev_offset < file_size, it assumes that it's the same logfile, seeks to offset and processes the remaining lines until the end of file.

If prev_offset > file_size, it assumes that the file has been rotated. Thus, it opens logfile.1 (the rotated log), seeks to offset, processes the lines until EOF *and* then opens the current (after-rotation) logfile and processes it to EOF.

Whatever the case, it ends up by storing the new offset in the logdb to be used on the following execution.

Now, which problem do you see in this approach?

comment:2 Changed 2 years ago by aseques

I just tested a case that causes problems. To reproduce:

.- The initial case is some logs for domain example.com and with the logdb part:

example.com-traf.log 1964

.- Force a rotation of the logs (without the patch in this thread). In debian it would be logrotate -f /etc/logrotate.d/apache2 , this would rotate both /var/log/apache2/example.com-combined.log and /var/log/apache2/example.com-traf.log

.- After the rotation both files (example.com-traf.log and example.com-combined.log) are empty, and the old version is in the *.1 file

.- You manually execute /var/www/ispcp/engine/traffic/ispcp-vrl-traff and this is the intersting part:

DEBUG: push_el() sub_name: gen_log_file(), msg: Taking the domain log positions from '/var/log/ispcp/logdb'...
DEBUG: push_el() sub_name: gen_log_file, msg: /var/log/ispcp/example.com-traf.log was rotated. Parsing begins at position 1964 in  /var/log/apache2/example.com-traf.log.1
DEBUG: push_el() sub_name: sys_command(), msg: Starting...
DEBUG: push_el() sub_name: sys_command('/bin/cp /var/log/apache2/example.com-traf.log.1 /var/log/ispcp/example.com-traf.log.1'), msg: Ending...
DEBUG: push_el() sub_name: del_file(), msg: Starting...
DEBUG: push_el() sub_name: del_file(), msg: Ending...
DEBUG: push_el() sub_name: sys_command(), msg: Starting...
DEBUG: push_el() sub_name: sys_command('/bin/mv /var/log/ispcp/example.com-traf.log /var/log/ispcp/example.com-traf.log.prev'), msg: Ending...
DEBUG: push_el() sub_name: gen_log_file(), msg: Saving new domain log positions in '/var/log/ispcp/logdb'...

.- The problem is that the relevant part of the logdb still remains the same:

example.com-traf.log 1964

So we should either fix this behavior or take care of logdb in the rotation scripts.

comment:3 Changed 2 years ago by kilburn

  • Owner set to kilburn
  • Status changed from new to assigned

Aseques, can you stress-test the patch that I've attached to the ticket? (Tested by myself against current trunk, so please test it without appliying your other patches)

Thx!

Changed 2 years ago by kilburn

comment:4 Changed 2 years ago by nuxwin

  • Severity changed from Don't know to Medium
  • Milestone changed from Working to ispCP ω 1.0.4

comment:5 Changed 2 years ago by kilburn

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed in r2551.

comment:6 Changed 2 years ago by kilburn

  • Status changed from closed to reopened
  • Resolution fixed deleted

comment:7 Changed 2 years ago by kilburn

Aseques found some situations where my patch was misbehaving. I'm looking into it...

comment:8 Changed 2 years ago by kilburn

  • Status changed from reopened to closed
  • Resolution set to fixed

Fixed in r2552 (thanks aseques!)

Note: See TracTickets for help on using tickets.