The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

StatDB - Gives a object oriented interface to stat.pl's DBM files.

SYNOPSIS

    use StatDB;

    my $db = StatDB::new(
        timedb      => 'db/time.db',
        pagedb      => 'db/page.db',
        statusdb    => 'db/status.db',
        ipdb        => 'db/ip.db',
    );

    $db->startsession() or die $db->error(), "\n";
    print $db->idb_next_id(), "\n";
    $db->endsession();

DESCRIPTION

StatDB.pm gives a object oriented interface to stat.pl's DBM files.

METHODS

int startsession(StatDB statdb)

Open all databases and tie them to this object. Always run StatDB::endsession when finished.

int endsession(StatDB statdb)

Close all open databases.

tied create_session(StatDB statdb, string dbfile, string dbname)

Open a database and return reference to the tied hash. If new databases are added, it's important to add these to StatDB::endsession()

int tdb_next_id(StatDB statdb)

Find next availible id in the timestamp database.

int insert_new_timestamp(StatDB statdb, string timestamp)

Insert a new timestamp entry. Returns a new/existing id.

int insert_ip(StatDB statdb, string host/ip, string time, string server)

Insert a new ip entry.

int insert_page(StatDB statdb, string page, string time, string server int bytes)

Insert a new page entry.

int insert_status(StatDB statdb, int status, string time, string server)

Insert a new status entry.

string last_db_update(StatDB statdb)

Get the date and time from the last changed database file.

int b_to_kB(int bytes)

Convert bytes to kilobytes.

int b_to_MB(int bytes)

Convert bytes to megabytes.

int b_to_GB(int bytes)

Convert bytes to gigabytes.

int get_all_hits(StatDB statdb)

Return total hits on all pages in the pages database.

void test_limit_expr(hashref expr)

Check for invalid limit expressions, print a warning if any.

int get_id_from_timestamp(StatDB statdb, string timestamp)

Get the timestampdb id for a timestamp (if any)

string sprint_time(arrayref timeref)

Return a formatted timestamp string. i.e:

        my $timeref = get_arr_of_dates($timestamp);
        print sprint_time($timeref), "\n";
arrayref get_arr_of_dates(string timestamp)

Extract the elements from a timestamp and return a reference to an array with these elements.

DATABASES

The timestamp database

The timestamp database has two subdatabases:

byid: key=id value=timestamp, bytime: key=timestamp value=id

All entries in the other databases has a time field, which is the id of a timedb entry.

The pages database

The pages database has one entry for each hour, page and server. A page entry looks like this:

byid: key=page:time:server value=count:size

The count field is how many times this page is seen, on this server and in this hour. The size is the total traffic (in kB) this page has generated at $hour and $server.

The IP database

The IP database has one entry for each hour, ip and server. An IP entry looks like this:

byid: key=ip:time:server value=count

The Status database

The status database has one entry for each hour, http status code and server. An Status entry looks like this:

byid: key=http_status_code:time:server value=count

EXPORT

sprint_timeref($)
cmp_timestampref($$)
b_to_kB($)
b_to_MB($)
b_to_GB($)

AUTHOR

Ask Solem Hoel <ask@startsiden.no<gt>

SEE ALSO

perl, BerkeleyDB, http://www.startsiden.no