Mgstat is a utility written in C to analyze log file produced by mod_gzip (Apache module that compress both static and dynamic output).

DEMO: raport for this server generated by mgstat v.0.10 is here.

  • 24.09.2003 Win32 port prepared by joker from is ready to download. Thank you joker!
  • thanks to Markus Fischer for a patch (reading data from stdin)

  • Download: mgstat-0.12.tar.gz (source code - 33kB) - updated 03/05/2005. ChangeLog is here
    mgstat-0.11 for win32 (binary files - 626 kB). Small info how to run it.

    Platforms: program was tested under FreeBSD, OpenBSD, NetBSD and Linux on Intel platform. There were reports about successful compilation under Solaris
    Requirements: GD library. Without it mgstat will run but won't produce graphics.

    Important note:
    Since 0.5 version program displays statistics about all bytes sent and actual size of all objects, not just only compressable objects. Please note that if you use newer version ( > 0.4) with history file (mgstat.hist) produced by earlier version then generated statistics could be incomplete.
    WHAT'S NEW in 0.10
  • displays statistics about all bytes sent and actual size of all objects, not just only compressable objects.
  • new command line option: -f [b|k|m|q] to specify output data format (bytes, kilo, mega , giga)
  • fixed errx issues under Solaris
  • works with gd2
  • added -s command line options for server name

  • Description

    Mgstat produces html reports for years, months and days (with png or gif charts generated with GD library) that shows you how many bytes you saved by using this excellent free Apache module. It produces history files so you can rotate your logs without losing previous statistics.
    You can also run mgstat on the same log file and statistics won't be doubled because program will start from the place where previous processing ended. You can also run mgstat on totally unsorted (date order) log file (that were produced for example by merging various log files); program will run a little bit slower but will produce correct reports.


    mgstat -l /path/to/mod_gzip_log -d /path/to/output_dir [-s server_name] [-f b|k|m|g] [-q]

    mod_gzip_log - full path to a log file produced by mod_gzip.
    output_dir - directory where html, gif and history files are stored.
    server_name - server name to print on reports.
    -f - specify data count format (b - bytes, k - kilobytes, m - megabytes, g - gigabytes).
    -q - quiet: do not print messages.

    Log file

    If you have mod_gzip installed you should add following lines to your apache configuration file, to produce mod_gzip log that could be analyzed by mgstat:

    LogFormat "%h %l %u %t \"%V %r\" %>s %b mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n Out:%{mod_gzip_output_size}n:%{mod_gzip_compression_ratio}npct." common_with_mod_gzip_info2

    CustomLog /var/log/httpd/mod_gzip_log common_with_mod_gzip_info2

    To use mgstat, 5 items in your log file are necessary:
    1) %t
    2) %b
    3) mod_gzip: %{mod_gzip_result}n
    4) In:%{mod_gzip_input_size}n
    5) Out:%{mod_gzip_output_size}n

    Position and history files

    Mgstat creates 2 files in the 'output_dir':

  • mgstat.hist - binary file that contains previous statistics.
  • mgstat.pos - text file with last line processed and its offset in a log file.

  • mgstat.hist holds statistics from previous runs.
    mgstat.pos is needed to decide if a log file that will be analyzed in the current run was processed before or not, to avoid doubled statistics.
    If a log line saved in mgstat.pos matches line in a current log file at offset (counted from _beggining_) readed from mgstat.pos then current processing will skip already analyzed log entries. Unless you hadn't changed your log file manually you can run mgstat safely many times on the same log file, to update existing reports. Of course you can periodically run mgstat before deleting log file; mgstat.hist holds every information needed to generate summary reports. If you want to force mgstat to analyze log file from the beginning just delete mgstat.pos file.


    You're allowed to do whatever you like with this software (including re-distribution in any form, with or without modification), provided that credit is given where it is due and any modified versions are marked as such.

    There's absolutely no warranty.

    This software uses the gd graphics library, which is copyright by Quest Protein Database Center, Cold Spring Harbor Labs. Please see the documentation supplied with the library for additional information and license terms, or visit for the most recent version of the library and supporting documentation.


    Suggestions, bug reports, bug fixes send to mike(at)wizard(dot)ae(dot)krakow(dot)pl

    Back to home page