*** getstats.12.c.dist Sat Aug 28 09:46:59 1999 --- getstats.12.c Sat Aug 28 09:43:28 1999 *************** *** 60,66 **** ** "CERN", "NCSA", "PLEXUS", "GN", "MAC", or "GOPHER". */ #ifndef COMMON ! #define COMMON 0 #endif /* Overridden by -M option. ** If your log file is in the "common" format, define COMMON as --- 60,66 ---- ** "CERN", "NCSA", "PLEXUS", "GN", "MAC", or "GOPHER". */ #ifndef COMMON ! #define COMMON 1 #endif /* Overridden by -M option. ** If your log file is in the "common" format, define COMMON as *************** *** 445,451 **** /** End of user-definable options **/ #define PROGNAME "getstats" ! #define VERSION "1.2" #define DOCURL "http://www.eit.com/software/getstats/getstats.html" #define PLEXURL "http://www.bsdi.com/server/doc/plexus.html" #define GNURL "http://hopf.math.nwu.edu/" --- 445,451 ---- /** End of user-definable options **/ #define PROGNAME "getstats" ! #define VERSION "1.2pl3" #define DOCURL "http://www.eit.com/software/getstats/getstats.html" #define PLEXURL "http://www.bsdi.com/server/doc/plexus.html" #define GNURL "http://hopf.math.nwu.edu/" *************** *** 454,460 **** #define MACURL "http://www.uth.tmc.edu/mac_info/machttp_info.html" #define GOPHURL "gopher://boombox.micro.umn.edu" ! #define MAXLINE 1000 #define HASHLINE 200 #define ADDRLEN 80 #define DATELEN 25 --- 454,460 ---- #define MACURL "http://www.uth.tmc.edu/mac_info/machttp_info.html" #define GOPHURL "gopher://boombox.micro.umn.edu" ! #define MAXLINE 2048 #define HASHLINE 200 #define ADDRLEN 80 #define DATELEN 25 *************** *** 473,479 **** #define FLAGLEN 5 #define BREAKLEN 46 #define LONGDATELEN 80 ! #define SHORTDATELEN 9 #define DATENOTZLEN 19 #define TZLEN 3 #define DATEARGLEN 10 --- 473,479 ---- #define FLAGLEN 5 #define BREAKLEN 46 #define LONGDATELEN 80 ! #define SHORTDATELEN 11 #define DATENOTZLEN 19 #define TZLEN 3 #define DATEARGLEN 10 *************** *** 763,768 **** --- 763,770 ---- isfirstline, domainlevels, highhour, lowhour, lowday, highday, errors, allreports, showprogress, common; static int htmldocnum, scriptnum, assetnum, lastweeksrequests; + int statuscode; + static int client_errors, server_errors; long starttime, stoptime, nowtime, longdate, filesize, bytecount; static struct tm *currenttime; FILE *fp, *fperr; *************** *** 1016,1023 **** nowtime = starttime = getthetime(); currenttime = localtime((time_t *) &nowtime); ! sprintf(newshortdate, "%02d/%02d/%02d", currenttime->tm_mon + 1, ! currenttime->tm_mday, currenttime->tm_year); if (strcmp(addrmask, "NONE")) removespaces(addrmask); --- 1018,1025 ---- nowtime = starttime = getthetime(); currenttime = localtime((time_t *) &nowtime); ! sprintf(newshortdate, "%02d/%02d/%04d", currenttime->tm_mon + 1, ! currenttime->tm_mday, currenttime->tm_year + CENTURY); if (strcmp(addrmask, "NONE")) removespaces(addrmask); *************** *** 1152,1159 **** updateprogress(i++); if ((*serverfunction)(logline, date, address, request, ! &filesize) == 0) { ! errors++; errorreport = (struct errorlist *) adderror(errorreport, logline); continue; --- 1154,1166 ---- updateprogress(i++); if ((*serverfunction)(logline, date, address, request, ! &statuscode, &filesize) == 0) { ! if (statuscode >= 400 && statuscode <= 499) ! client_errors++; ! else if (statuscode >= 500 && statuscode <= 599) ! server_errors++; ! else ! errors++; errorreport = (struct errorlist *) adderror(errorreport, logline); continue; *************** *** 1267,1273 **** if (strcmp(error_report, "NONE") && !errors) errorreport = (struct errorlist *) ! adderror(errorreport, "No malformed requests reported."); if (fperr != NULL) { printerrors(errorreport, fperr); --- 1274,1280 ---- if (strcmp(error_report, "NONE") && !errors) errorreport = (struct errorlist *) ! adderror(errorreport, "No malformed error requests reported."); if (fperr != NULL) { printerrors(errorreport, fperr); *************** *** 1320,1326 **** if (printhtml) putchar('\n'); printstats(lastweeksrequests, htmldocnum, scriptnum, assetnum, ! bytecount, errors); if (htmldocnum || scriptnum || assetnum) printdates(firstdate, lastdate, htmldocnum + scriptnum + assetnum + errors, bytecount); --- 1327,1333 ---- if (printhtml) putchar('\n'); printstats(lastweeksrequests, htmldocnum, scriptnum, assetnum, ! bytecount, errors, client_errors, server_errors); if (htmldocnum || scriptnum || assetnum) printdates(firstdate, lastdate, htmldocnum + scriptnum + assetnum + errors, bytecount); *************** *** 1891,1913 **** } } void printstats(lastweeksrequests, htmldocnum, scriptnum, assetnum, bytecount, errors) int lastweeksrequests; int htmldocnum; int scriptnum; int assetnum; long int bytecount; int errors; { printf("Requests last 7 days: %d\n", lastweeksrequests); printf("New unique hosts last 7 days: %d\n", lastweekshosts); printf("Total unique hosts: %d\n", uniquehostnum); ! printf("Number of HTML requests: %d\n", htmldocnum); ! printf("Number of script requests: %d\n", scriptnum); ! printf("Number of non-HTML requests: %d\n", assetnum); ! printf("Number of malformed requests (all dates): %d\n", errors); printf("Total number of all requests/errors: %d\n", htmldocnum + ! scriptnum + assetnum + errors); if (printbytes) printf("Total number of bytes requested: %d\n", bytecount); } --- 1898,1939 ---- } } + /* void printstats(lastweeksrequests, htmldocnum, scriptnum, assetnum, bytecount, errors) + */ + void printstats(lastweeksrequests, htmldocnum, scriptnum, assetnum, bytecount, errors, client_errors, server_errors) int lastweeksrequests; int htmldocnum; int scriptnum; int assetnum; long int bytecount; int errors; + int client_errors; + int server_errors; { + int total = htmldocnum + scriptnum + assetnum + + errors + client_errors + server_errors; + printf("Requests last 7 days: %d\n", lastweeksrequests); printf("New unique hosts last 7 days: %d\n", lastweekshosts); printf("Total unique hosts: %d\n", uniquehostnum); ! printf("Number of HTML requests: %d (%.1f%%)\n", ! htmldocnum, ((float) htmldocnum / (float) total) * 100); ! printf("Number of script requests: %d (%.1f%%)\n", ! scriptnum, ((float) scriptnum / (float) total) * 100); ! printf("Number of non-HTML requests: %d (%.1f%%)\n", ! assetnum, ((float) assetnum / (float) total) * 100); ! printf("Number of malformed error requests (all dates): %d (%.1f%%)\n", ! errors, ((float) errors / (float) total) * 100); ! printf("Number of client error (4xx) requests (all dates): %d (%.1f%%)\n", ! client_errors, ((float) client_errors / (float) total) * 100); ! printf("Number of server error (5xx) requests (all dates): %d (%.1f%%)\n", ! server_errors, ((float) server_errors / (float) total) * 100); ! /* printf("Total number of all requests/errors: %d\n", htmldocnum + ! scriptnum + assetnum + errors + client_errors + server_errors); ! */ ! printf("Total number of all requests/errors: %d\n", total); if (printbytes) printf("Total number of bytes requested: %d\n", bytecount); } *************** *** 2261,2274 **** (hour > 12) ? hour - 12 : hour, (hour > 12) ? "pm" : "am"); } ! int getcommondateaddress(logline, date, address, request, filesize) char *logline; char *date; char *address; char *request; long *filesize; { int i, j, status, size; char *c, tmpdate[COMMONDATELEN]; if (!isvalidreq(logline)) --- 2287,2302 ---- (hour > 12) ? hour - 12 : hour, (hour > 12) ? "pm" : "am"); } ! int getcommondateaddress(logline, date, address, request, statuscode, filesize) char *logline; char *date; char *address; char *request; + int *statuscode; long *filesize; { int i, j, status, size; + int client_errors, server_errors; char *c, tmpdate[COMMONDATELEN]; if (!isvalidreq(logline)) *************** *** 2330,2343 **** if (!i || !strcmp(request, "/")) strcpy(request, HOMEPAGE); ! c = (char *) strrchr(logline, '"') + 2; if (*c != '-') { status = 0; while (isdigit(*c)) { status = (status * 10) + (*c - '0'); c++; } ! if (status < 200 || status > 299) return 0; c++; } --- 2358,2380 ---- if (!i || !strcmp(request, "/")) strcpy(request, HOMEPAGE); ! if ((c = (char *) strstr(logline, " HTTP/0.9\" ")) != NULL) ! c += 11; ! else if ((c = (char *) strstr(logline, " HTTP/1.0\" ")) != NULL) ! c += 11; ! else if ((c = (char *) strstr(logline, " HTTP/1.1\" ")) != NULL) ! c += 11; ! else if ((c = (char *) strstr(logline, "\" ")) != NULL) ! c += 2; ! if (*c != '-') { status = 0; while (isdigit(*c)) { status = (status * 10) + (*c - '0'); c++; } ! *statuscode = (int) status; ! if (status < 200 || status > 399) return 0; c++; } *************** *** 2744,2750 **** monshortdate[SHORTDATELEN], sunshortdate[SHORTDATELEN]; int monmonth, monday, monyear, sunmonth, sunday, sunyear; ! sprintf(shortdate, "%02d/%02d/%02d", month, day, year); strcpy(monshortdate, getshortdate(shortdate, 1)); strcpy(sunshortdate, getshortdate(shortdate, 0)); --- 2781,2787 ---- monshortdate[SHORTDATELEN], sunshortdate[SHORTDATELEN]; int monmonth, monday, monyear, sunmonth, sunday, sunyear; ! sprintf(shortdate, "%02d/%02d/%04d", month, day, year); strcpy(monshortdate, getshortdate(shortdate, 1)); strcpy(sunshortdate, getshortdate(shortdate, 0)); *************** *** 2767,2774 **** for (i = 0; strstr(date, months[i]) == NULL; i++) ; month = i + 1; ! sprintf(shortdate, "%02d/%c%c/%c%c", month, (date[8] == ' ') ? ! '0' : date[8], date[9], date[22], date[23]); } char *convtoeurodate(shortdate) --- 2804,2811 ---- for (i = 0; strstr(date, months[i]) == NULL; i++) ; month = i + 1; ! sprintf(shortdate, "%02d/%c%c/%c%c%c%c", month, (date[8] == ' ') ? ! '0' : date[8], date[9], date[20], date[21], date[22], date[23]); } char *convtoeurodate(shortdate) *************** *** 3187,3192 **** --- 3224,3231 ---- e->date = date; e->requestsize += filesize; e->requestnum += 1; + if (filesize > 0) + e->filesize = filesize; } return e; *************** *** 3484,3490 **** printgraph(11, hoursumstats[i], HOURSUMMARK, MARK, largenum); if (printbytes) { ! printf(" bytes : "); printgraph(11, hoursumstats[i + 24], HOURSUMBYTEMARK, BYTEMARK, largenum); } --- 3523,3529 ---- printgraph(11, hoursumstats[i], HOURSUMMARK, MARK, largenum); if (printbytes) { ! printf(" bytes : "); printgraph(11, hoursumstats[i + 24], HOURSUMBYTEMARK, BYTEMARK, largenum); } *************** *** 3514,3520 **** printgraph(16, n->requests, MONTHMARK, MARK, largestmonthnum); if (printbytes && n->filesize >= 0) { ! printf(" bytes : "); printgraph(16, n->filesize, MONTHBYTEMARK, BYTEMARK, largestmonthnum); } --- 3553,3559 ---- printgraph(16, n->requests, MONTHMARK, MARK, largestmonthnum); if (printbytes && n->filesize >= 0) { ! printf(" bytes : "); printgraph(16, n->filesize, MONTHBYTEMARK, BYTEMARK, largestmonthnum); } *************** *** 3527,3533 **** printgraph(18, n->requests, WEEKMARK, MARK, largestweeknum); if (printbytes && n->filesize >= 0) { ! printf(" bytes : "); printgraph(18, n->filesize, WEEKBYTEMARK, BYTEMARK, largestweeknum); } --- 3566,3572 ---- printgraph(18, n->requests, WEEKMARK, MARK, largestweeknum); if (printbytes && n->filesize >= 0) { ! printf(" bytes : "); printgraph(18, n->filesize, WEEKBYTEMARK, BYTEMARK, largestweeknum); } *************** *** 3541,3547 **** printgraph(16, n->requests, DAYMARK, MARK, largestdaynum); if (printbytes && n->filesize >= 0) { ! printf(" bytes : "); printgraph(16, n->filesize, DAYBYTEMARK, BYTEMARK, largestdaynum); } --- 3580,3586 ---- printgraph(16, n->requests, DAYMARK, MARK, largestdaynum); if (printbytes && n->filesize >= 0) { ! printf(" bytes : "); printgraph(16, n->filesize, DAYBYTEMARK, BYTEMARK, largestdaynum); } *************** *** 3557,3563 **** printgraph(11, n->requests, HOURMARK, MARK, largesthournum); if (printbytes && n->filesize >= 0) { ! printf(" bytes : "); printgraph(11, n->filesize, HOURBYTEMARK, BYTEMARK, largesthournum); } --- 3596,3602 ---- printgraph(11, n->requests, HOURMARK, MARK, largesthournum); if (printbytes && n->filesize >= 0) { ! printf(" bytes : "); printgraph(11, n->filesize, HOURBYTEMARK, BYTEMARK, largesthournum); } *************** *** 3991,3997 **** int mn, dy, yr, n1, n2; sscanf(shortdate, "%d/%d/%d", &mn, &dy, &yr); ! yr += CENTURY; if (mn < 3) { mn += 12; --- 4030,4036 ---- int mn, dy, yr, n1, n2; sscanf(shortdate, "%d/%d/%d", &mn, &dy, &yr); ! /* yr += CENTURY; */ if (mn < 3) { mn += 12; *************** *** 4027,4033 **** int month, day, year; sscanf(shortdate, "%d/%d/%d", &month, &day, &year); ! year += CENTURY; for (yearday = i = 0; i < month - 1; i++) { if (i == 1 && IS_LEAP(year)) --- 4066,4072 ---- int month, day, year; sscanf(shortdate, "%d/%d/%d", &month, &day, &year); ! /* year += CENTURY; */ for (yearday = i = 0; i < month - 1; i++) { if (i == 1 && IS_LEAP(year)) *************** *** 4084,4094 **** days[getnweekday(month + 1, day, year)], months[month], day, hours, minutes, yearsecs, year); else if (type == 2) ! sprintf(date, "%02d/%02d/%02d %02d:%02d:%02d", ! month + 1, day, year - CENTURY, hours, minutes, yearsecs); else if (type == 3) ! sprintf(date, "%02d/%02d/%02d", ! month + 1, day, year - CENTURY); else if (type == 4) sprintf(date, "%s %d, %d", months[month], day, year); #else --- 4123,4133 ---- days[getnweekday(month + 1, day, year)], months[month], day, hours, minutes, yearsecs, year); else if (type == 2) ! sprintf(date, "%02d/%02d/%04d %02d:%02d:%02d", ! month + 1, day, year, hours, minutes, yearsecs); else if (type == 3) ! sprintf(date, "%02d/%02d/%04d", ! month + 1, day, year); else if (type == 4) sprintf(date, "%s %d, %d", months[month], day, year); #else *************** *** 4097,4107 **** days[getnweekday(month + 1, day, year)], day, months[month], hours, minutes, yearsecs, year); else if (type == 2) ! sprintf(date, "%02d/%02d/%02d %02d:%02d:%02d", ! day, month + 1, year - CENTURY, hours, minutes, yearsecs); else if (type == 3) ! sprintf(date, "%02d/%02d/%02d", ! day, month + 1, year - CENTURY); else if (type == 4) sprintf(date, "%d %s, %d", day, months[month], year); #endif --- 4136,4146 ---- days[getnweekday(month + 1, day, year)], day, months[month], hours, minutes, yearsecs, year); else if (type == 2) ! sprintf(date, "%02d/%02d/%04d %02d:%02d:%02d", ! day, month + 1, year, hours, minutes, yearsecs); else if (type == 3) ! sprintf(date, "%02d/%02d/%04d", ! day, month + 1, year); else if (type == 4) sprintf(date, "%d %s, %d", day, months[month], year); #endif *************** *** 4117,4123 **** strcpy(tmpshortdate, shortdate); sscanf(tmpshortdate, "%d/%d/%d", &month, &day, &year); ! year += CENTURY; for (yearday = i = 0; i < month - 1; i++) { if (i == 1 && IS_LEAP(year)) yearday++; --- 4156,4162 ---- strcpy(tmpshortdate, shortdate); sscanf(tmpshortdate, "%d/%d/%d", &month, &day, &year); ! /* year += CENTURY; */ for (yearday = i = 0; i < month - 1; i++) { if (i == 1 && IS_LEAP(year)) yearday++; *************** *** 4134,4140 **** int month, day, year, yearday, weekday, mondayday; sscanf(shortdate, "%d/%d/%d", &month, &day, &year); ! year += CENTURY; yearday = getyearday(shortdate); weekday = getweekday(shortdate); --- 4173,4179 ---- int month, day, year, yearday, weekday, mondayday; sscanf(shortdate, "%d/%d/%d", &month, &day, &year); ! /* year += CENTURY; */ yearday = getyearday(shortdate); weekday = getweekday(shortdate); *************** *** 4160,4166 **** static char newshortdate[SHORTDATELEN]; sscanf(shortdate, "%d/%d/%d", &month, &day, &year); ! year += CENTURY; yearday = getyearday(shortdate); weekday = getweekday(shortdate); --- 4199,4205 ---- static char newshortdate[SHORTDATELEN]; sscanf(shortdate, "%d/%d/%d", &month, &day, &year); ! /* year += CENTURY; */ yearday = getyearday(shortdate); weekday = getweekday(shortdate); *************** *** 4200,4206 **** break; } ! sprintf(newshortdate, "%02d/%02d/%02d", i + 1, yearday, year - CENTURY); return newshortdate; } --- 4239,4245 ---- break; } ! sprintf(newshortdate, "%02d/%02d/%04d", i + 1, yearday, year); return newshortdate; } *************** *** 4232,4245 **** char *request; { return (strstr(request, "GET") || strstr(request, "HEAD") || ! strstr(request, "POST")); } int ishtmlrequest(request) char *request; { ! return (strstr(request, ".html") || strstr(request, "GET") || ! strstr(request, "HEAD")); } int isscriptrequest(request) --- 4271,4285 ---- char *request; { return (strstr(request, "GET") || strstr(request, "HEAD") || ! strstr(request, "POST") || strstr(request, "CONNECT")); } int ishtmlrequest(request) char *request; { ! return (strstr(request, ".html") || strstr(request, ".htm") || ! strstr(request, "GET") || strstr(request, "HEAD") || ! strstr(request, "CONNECT")); } int isscriptrequest(request) *************** *** 4260,4265 **** --- 4300,4307 ---- return (c + 4); else if ((c = (char *) strstr(request, "POST")) != NULL) return (c + 4); + else if ((c = (char *) strstr(request, "CONNECT")) != NULL) + return (c + 7); return NULL; }