#include #include #include #include #include #include #include #define MOD_GZIP_LOG "MOD_GZIP_LOG" char *gzip_ok[] = { "mod_gzip: OK", "mod_gzip: DECHUNK:OK", "mod_gzip: DECHUNK:TRANSMIT_ERROR:32" }; unsigned long long in, out, nr, tnr; void parse(char *s) { char *p, *t; int i, found = 0; unsigned int cin, cout; for(i = 0; i < sizeof gzip_ok/sizeof(char *); i++) { p = strstr(s, gzip_ok[i]); if(p) { found = 1; break; } } if(!found) return; t = strstr(p, "In:"); if(!t) return; t += 3; if(sscanf(t, "%d ", &cin) != 1) return; p = strstr(t, "Out:"); if(!p) return; p += 4; if(sscanf(p, "%d", &cout) != 1) return; in += cin; out += cout; nr++; } void header() { printf("Content-type: text/plain\n\n"); } void noenv() { printf("MOD_GZIP_LOG environment variable not set\n"); exit(0); } int main(int argc, char **argv) { char *mod_gzip_log; char buf[512]; struct timeval start, end; unsigned long long tmp; FILE *f; header(); mod_gzip_log = getenv(MOD_GZIP_LOG); if (mod_gzip_log == NULL) noenv(); f = fopen(mod_gzip_log, "r"); if (!f) { printf("Cannot open %s\n", mod_gzip_log); exit(0); } gettimeofday(&start, 0); if (!fgets(buf, sizeof buf, f)) { printf("File seems to be empty.\n"); exit(0); } if (!strstr(buf, "mod_gzip")) printf("\nHmm...it doesn't look like mod_gzip log, but continuing anyway...\n"); tnr++; parse(buf); while(fgets(buf, sizeof buf, f)) { tnr++; parse(buf); } fclose(f); gettimeofday(&end, 0); printf("\nNumber of all requests: %lld\n", tnr); printf("Number of requests that were compressed: %lld ", nr); if(tnr) printf("(%lld%%)\n", nr*100/tnr); printf("Without compression it would be: %lld mb (%lld kb -> %lld bytes)\n", in/(1024*1024), in/1024, in); printf("Effective amount of bytes sent: %lld mb (%lld kb -> %lld bytes)", out/(1024*1024), out/1024, out); if(in) printf("\n\nOnly %lld%% of real amount of bytes was sent to the clients.", out*100/in); tmp = in - out; printf("\nSaved bytes by mod_gzip: %lld mb (%lld kb -> %lld bytes)", tmp/(1024*1024), tmp/1024, tmp); printf("\n\n"); printf("Log was analyzed in %ld.%.06ld sec\n", end.tv_sec-start.tv_sec, end.tv_usec-start.tv_usec/1000); return 0; }