Menu

#882 Support nginx $gzip_ratio

open
nobody
None
1
2015-03-27
2014-02-07
rhi
No

AWStats currently supports these gzip/deflate field formats:

%gzipin mod_gzip compression input bytes: In:XXX
%gzipout mod_gzip compression output bytes & ratio: Out:YYY:ZZpct.
%gzipratio mod_gzip compression ratio: ZZpct.
%deflateratio mod_deflate compression ratio with format: (ZZ)

However, nginx only provides:

$gzip_ratio – achieved compression ratio, computed as the ratio between the original and compressed response sizes.

For instance, a log entry like

my.vhost ip.address - [07/Feb/2014:20:51:40 +0100] "GET /my-url HTTP/1.1" 200 3021 "-" "Mozilla/5.0 (WhatsMyIP.org HTTP_Compression_Test) whatsmyip.org/ua" 2.96

means:

Uncompressed Page Size: 8.7 KB
Compressed Page Size: 2.9 KB
Savings: 66.2%

So the gzip_ratio = uncompressed/compressed = 8.7/2.9 = 2.96

Please provide this ratio as an AWStats field so that nginx gzip compression can be analyzed correctly.

Discussion

  • Rodney Hester

    Rodney Hester - 2015-03-27

    Try the attached patch against AWStats 7.3 awstats.pl.

    gzip_ratio can be quoted in nginx.conf:

    # add compression ratio to combined log format
    log_format main '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent" '
                    '"$gzip_ratio"';
    

    or unquoted:

    # add compression ratio to combined log format
    log_format main '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent" '
                    '$gzip_ratio';
    

    and should be referred to as 'gzipngx' in awstats.conf:

    #   %gzipngx          ngx_http_gzip_module compression ratio: "3.26"
    LogFormat = "%host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot %gzipngx"
    

    Note that any log entries not containing the gzip ratio (i.e. where you are using a different log_format but the same log file) will be considered corrupt by AWStats, so careful with your server log definitions!

     

    Last edit: Rodney Hester 2015-03-27
    • rhi

      rhi - 2015-03-28

      Thanks, seems to work fine here! :)

      I had $gzip_ratio interpreted as %other before, so the log file format didn't change, but thanks for the hint.

       

Log in to post a comment.