I'm confused. Surely this is simply a case of requiring a single line entry per session noting the start and stop times, as indexes within a database, ie:
start_time , stop_time , userid 20020901101111 , 20021002121201 , fred 20020904102010 , NULL , johnwhoneverlogsoff
With such a table, indexed appropriately, the query:
select count(*) from sessions where start_time < $end_of_segment and ( +stop_time > $start_of_segment || stop_time IS NULL);
Should give you the count, and quickly too since the database can make good use of its indexes in that instance.

I would have thought such a table would be a common part of an ISP setup, but if it isn't, you may find the table advantageous for other kinds of session related data as well.

In either case, the only task left is to take your logs and shunt them into a database table of the above format (matching as it goes the appropriate stops with starts, although I am told that since the session time is included in the stop message, you could also just scan stops and calculate the start time from that), something that could be done once per hour, per day, or on demand as necessary. A bit of intelligence in the parser will allow it to continue parsing from where it left off last time, resulting in little CPU burn to get up to date. Hope that helps.


In reply to Re: How to do session times The Right Way by PhiRatE
in thread How to do session times The Right Way by strider corinth

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.