MVC::Neaf::X::ServerStat - server request/performance statistics.


This module provides a simple interface to gather request timing statistics.

Despite being a part of Neaf (Not Even A Framework), it does not depend on the rest of it and can be used se[parately.



new( %args )

Valid options:

  • on_write = CODEREF - a sub that will be executed when it's time to flush data.

    CODEREF is a function that receiver an arrayref containing arrayrefs with the following data: script_name(), http status, time spent in controller, total time spent, and Unix time when request came in. E.g.

            [ "/path/to/app", 200, 0.01, 0.02, 10444555333 ]

    This format MAY be extended in the future.

    iitem * write_thresh_count (n) - how many records may be accumulated before writing.

  • write_thresh_time (n.nn) - for how much time (in seconds) the data may be accumulated.

    Set either to -1 to ensure EVERY record flushes immediately.

No checks are done whatsoever, but this MAY change in the future.


Start motinoring a request.

record_controller( $req->script_name )

When the controller is done, make the first record.

EXPERIMENTAL. The name may change in the future.

record_finish( $status [, $req] )

Finish monitoring request, possible flushing the data via on_write.

If 2nd argument is given, use it to postpone recording data. This is done so to avoid delaying the request being served.

If 2nd argument is missing, data is flushed immediately if either threshold (see new()) has been exceeded.

do_write( [[ ... ], ... ] )

If this method is implemented in a subclass, it will be used instead of on_write callback if no such callback provided.

The first argument is the stat object itself, the second one is the same as for on_write.