<% /** * * Configuration options are at the bottom of the file * * * Copyright(c) 2001 David Rees. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ %> <% // Get the ball rollin! parseMain(); %>
Log file: <%= logFile %>
Total hits: <%= totalHits %>
Total data sent: <%= apacheOutBytes %> bytes (<%= getMB(apacheOutBytes) %> MB)
mod_gzip in data: <%= gzipInBytes %> bytes (<%= getMB(gzipInBytes) %> MB)
mod_gzip out data: <%= gzipOutBytes %> bytes (<%= getMB(gzipOutBytes) %> MB)
Total bandwidth saved: <%= gzipInBytes - gzipOutBytes %> bytes (<%= getMB(gzipInBytes-gzipOutBytes) %> MB, <%= nf.format(100.0 * (double)(gzipInBytes-gzipOutBytes)/apacheOutBytes) %>%)
Compression ratio: <%= nf.format(100.0 * (1.0 - (double)gzipOutBytes/gzipInBytes)) %>%
Processing time: <%= processingTime %> ms
Error Message: <%= errorMessage %>
<%@page import="java.io.*" isThreadSafe="false"%> <%! /** * Begin internal variables and functions */ private static final String FULL_VERSION = "$Id: mgstat.jsp.txt,v 1.1 2001/07/21 09:12:12 drees Exp $"; private static final String VERSION = "0.1"; private static final double MB = 1024 * 1024; private static long totalHits; private static long processingTime; private static String errorMessage; private static long gzipInBytes; private static long gzipOutBytes; private static long apacheOutBytes; private java.text.NumberFormat nf = java.text.NumberFormat.getInstance(); private String getMB(long l) { return nf.format((double)l/MB); } private void parseLine(String line) { java.util.StringTokenizer st = new java.util.StringTokenizer(line, " "); String gzipStatus = null; for (int i = 1; st.hasMoreElements(); i++) { String token = st.nextToken(); switch (i) { case gzipInField: // looks like this: In:1234 int idx = token.indexOf(":"); if (idx != -1) { token = token.substring(idx+1, token.length()); try { gzipInBytes += Integer.parseInt(token); } catch (NumberFormatException nfe) { } } break; case gzipOutField: // looks like this: Out:12345:99pct. int idx1, idx2; idx1 = token.indexOf(":"); if (idx1 != -1) { token = token.substring(idx1+1, token.length()); idx2 = token.indexOf(":"); if (idx2 != -1) { token = token.substring(0, idx2); try { gzipOutBytes += Integer.parseInt(token); } catch (NumberFormatException nfe) { } } } break; case apacheOutField: try { apacheOutBytes += Integer.parseInt(token); } catch (NumberFormatException nfe) { } break; default: // Don't need to do anything break; } } } private void parseFile(String filename) { try { long startTime = System.currentTimeMillis(); BufferedReader in = new BufferedReader(new FileReader(filename)); String line = null; while ((line = in.readLine()) != null) { totalHits++; parseLine(line); } log("totalHits: " + totalHits); in.close(); processingTime = System.currentTimeMillis() - startTime; } catch (IOException ioe) { errorMessage = ioe.getMessage(); } } private void initialize() { totalHits = 0; apacheOutBytes = 0; gzipInBytes = 0; gzipOutBytes = 0; errorMessage = ""; nf.setMaximumFractionDigits(2); } private void parseMain() { initialize(); parseFile(logFile); } /** * End internal functions */ %> <%! /** * User configurable variables */ // The log file you wish to parse private static final String logFile = "/home/drees/dev/public_html/mod_gzip/gzip_access_log"; // These field locations refer to where in a log file line // they appear. If you're using the common_with_mod_gzip_info2 // LogFormat, you'll need to subtract one from each value // because I've added an extra field to my log files. // Index of the apache sent data field ("123") private static final int apacheOutField = 11; // Index of the gzip In field ("In:12345") private static final int gzipInField = 14; // Index of the gzip Out field ("Out:123:99pct.") private static final int gzipOutField = 15; %>