|
|
1.1 ! root 1: # an awk script ! 2: # an NNTP log summary report generator ! 3: # ! 4: # NOTE: for systems that are not as yet using the new 4.3 BSD syslog ! 5: # (and therefore have nntp messages lumped with everything else), it ! 6: # would be best to invoke this script thusly: ! 7: # ! 8: # egrep nntp syslog.old | awk -f nntp_awk > report_of_the_week ! 9: # ! 10: # because this script will include in the report all messages in the log ! 11: # that it does not recognize (on the assumption that they are errors to ! 12: # be dealt with by a human). ! 13: # ! 14: # Erik E. Fair <[email protected]> ! 15: # May 17, 1986 - Norwegian Independence Day ! 16: # ! 17: # Recognize some new things - February 22, 1987 ! 18: # Erik E. Fair <[email protected]> ! 19: # ! 20: # fix "xmt is not an array" bug - March 11, 1987 ! 21: # Change Elapsed/CPU fields to break out time values, HH:MM:SS ! 22: # Erik E. Fair <[email protected]> ! 23: # ! 24: # Add reporting for newnews commands - August 27, 1987 ! 25: # Erik E. Fair <[email protected]> ! 26: # ! 27: BEGIN{ ! 28: readers = 0; ! 29: transmit = 0; ! 30: receive = 0; ! 31: polled = 0; ! 32: } ! 33: ### Skip stderr reports from rnews ! 34: { ! 35: n = split($6, path, "/"); ! 36: if (path[n] == "rnews:") next; ! 37: n = split($7, path, "/"); ! 38: if (path[n] == "rnews") next; ! 39: host = $6; ! 40: } ! 41: $7 == "group" { ! 42: readers = 1; ! 43: ng[$8]++; ! 44: next; ! 45: } ! 46: $7 == "ihave" { ! 47: receive = 1; ! 48: rec[host]++; ! 49: if ($9 == "accepted") { ! 50: rec_accept[host]++; ! 51: if ($10 == "failed") rec_failed[host]++; ! 52: } else if ($9 == "rejected") rec_refuse[host]++; ! 53: next; ! 54: } ! 55: # this is from version 1.4 of nntpd ! 56: $7 == "ihave_stats" { ! 57: receive = 1; ! 58: rec[host] += $9 + $11 + $13; ! 59: rec_accept[host] += $9; ! 60: rec_refuse[host] += $11; ! 61: rec_failed[host] += $13; ! 62: next; ! 63: } ! 64: $7 == "connect" { ! 65: systems[host]++; ! 66: next; ! 67: } ! 68: $7 == "exit" { ! 69: if ($8 > 0) readers = 1; ! 70: articles[host] += $8; ! 71: groups[host] += $10; ! 72: next; ! 73: } ! 74: $7 == "xmit" { ! 75: xmt_cpu[host] += $9 + $11; ! 76: xmt_ela[host] += $13; ! 77: next; ! 78: } ! 79: $7 == "times" { ! 80: cpu[host] += $9 + $11; ! 81: ela[host] += $13; ! 82: next; ! 83: } ! 84: $7 == "stats" { ! 85: transmit = 1; ! 86: xmt[host] += $8; ! 87: xmt_accept[host] += $10; ! 88: xmt_refuse[host] += $12; ! 89: xmt_failed[host] += $14; ! 90: next; ! 91: } ! 92: # ! 93: # For the Nth time, I wish awk had two dimensional associative ! 94: # arrays. I assume that the last request is the same as all the ! 95: # others in this section of logfile. ! 96: # ! 97: $7 == "newnews" { ! 98: polled = 1; ! 99: poll[host] ++; ! 100: poll_asked[host] = $8; ! 101: next; ! 102: } ! 103: $7 == "newnews_stats" { ! 104: poll_offered[host] += $9; ! 105: poll_took[host] += $11; ! 106: next; ! 107: } ! 108: $7 == "post" { ! 109: readers = 1; ! 110: post[host]++; ! 111: next; ! 112: } ! 113: $7 == "timeout" { ! 114: timeout[host]++; ! 115: timeouts = 1; ! 116: next; ! 117: } ! 118: $7 == "unrecognized" { ! 119: unknown[host] = 1; ! 120: curious = 1; ! 121: } ! 122: ### Print anything that we don't recognize in the report ! 123: { ! 124: print; ! 125: } ! 126: END{ ! 127: printf("\n"); ! 128: ############################################################################### ! 129: ### Article Exchange With Peers (other servers) Statistics ### ! 130: ############################################################################### ! 131: if (transmit || receive || polled) ! 132: printf("NNTP peer article transfers\n\n"); ! 133: ! 134: if (polled) for(s in poll) servers[s]++; ! 135: if (receive) for(s in rec) servers[s]++; ! 136: if (transmit) for(s in xmt) servers[s]++; ! 137: ! 138: if (receive) { ! 139: printf("Article Reception (they contact us)\n"); ! 140: printf("System Offered Took Toss Fail Toss Elapsed CPU Pct\n"); ! 141: for(s in rec) { ! 142: ! 143: nrec += rec[s]; ! 144: nrec_accept += rec_accept[s]; ! 145: nrec_refuse += rec_refuse[s]; ! 146: nrec_failed += rec_failed[s]; ! 147: nrec_cpu += cpu[s]; ! 148: nrec_ela += ela[s]; ! 149: ! 150: they_offered = rec[s]; ! 151: if (they_offered == 0) they_offered = 1; ! 152: we_toss = (rec_refuse[s] / they_offered) * 100 + 0.5; ! 153: ! 154: e_hours = ela[s] / 3600; ! 155: e_sec = ela[s] % 3600; ! 156: e_min = e_sec / 60; ! 157: e_sec %= 60; ! 158: ! 159: c_hours = cpu[s] / 3600; ! 160: c_sec = cpu[s] % 3600; ! 161: c_min = c_sec / 60; ! 162: c_sec %= 60; ! 163: ! 164: tmp = ela[s]; ! 165: if (tmp == 0) tmp = 1; ! 166: pct = ((cpu[s] / tmp) * 100.0 + 0.5); ! 167: ! 168: printf("%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, rec[s], rec_accept[s], rec_refuse[s], rec_failed[s], we_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct); ! 169: } ! 170: ! 171: e_hours = nrec_ela / 3600; ! 172: e_sec = nrec_ela % 3600; ! 173: e_min = e_sec / 60; ! 174: e_sec %= 60; ! 175: ! 176: c_hours = nrec_cpu / 3600; ! 177: c_sec = nrec_cpu % 3600; ! 178: c_min = c_sec / 60; ! 179: c_sec %= 60; ! 180: ! 181: they_offered = nrec; ! 182: if (they_offered == 0) they_offered = 1; ! 183: we_toss = (nrec_refuse / they_offered) * 100 + 0.5; ! 184: ! 185: if (nrec_ela == 0) nrec_ela = 1; ! 186: pct = ((nrec_cpu / nrec_ela) * 100.0 + 0.5); ! 187: ! 188: printf("\n%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nrec, nrec_accept, nrec_refuse, nrec_failed, we_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct); ! 189: } ! 190: ! 191: ############################################################################### ! 192: if (polled) { ! 193: printf("Article Transmission (they poll us)\n"); ! 194: printf("System Conn Offrd Took Elapsed CPU Pct Groups\n"); ! 195: npoll = 0; ! 196: npoll_offered = 0; ! 197: npoll_took = 0; ! 198: npoll_cpu = 0; ! 199: npoll_ela = 0; ! 200: ! 201: for(s in poll) { ! 202: npoll += poll[s]; ! 203: npoll_offered += poll_offered[s]; ! 204: npoll_took += poll_took[s]; ! 205: ! 206: if (rec[s]) { ! 207: printf("%-25s %5d %5d %5d (see Article Reception) %s\n", s, poll[s], poll_offered[s], poll_took[s], poll_asked[s]); ! 208: } else { ! 209: npoll_ela += ela[s]; ! 210: npoll_cpu += cpu[s]; ! 211: ! 212: e_hours = ela[s] / 3600; ! 213: e_sec = ela[s] % 3600; ! 214: e_min = e_sec / 60; ! 215: e_sec %= 60; ! 216: ! 217: c_hours = cpu[s] / 3600; ! 218: c_sec = cpu[s] % 3600; ! 219: c_min = c_sec / 60; ! 220: c_sec %= 60; ! 221: ! 222: tmp = ela[s]; ! 223: if (tmp == 0) tmp = 1; ! 224: pct = ((cpu[s] / tmp) * 100.0 + 0.5); ! 225: ! 226: printf("%-25s %5d %5d %5d %3d:%02d:%02d %3d:%02d:%02d %3d%% %s\n", s, poll[s], poll_offered[s], poll_took[s], e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct, poll_asked[s]); ! 227: } ! 228: } ! 229: printf("\n%-25s %5d %5d %5d", "TOTALS", npoll, npoll_offered, npoll_took); ! 230: if (npoll_ela > 0 && npoll_cpu > 0) { ! 231: ! 232: e_hours = npoll_ela / 3600; ! 233: e_sec = npoll_ela % 3600; ! 234: e_min = e_sec / 60; ! 235: e_sec %= 60; ! 236: ! 237: c_hours = npoll_cpu / 3600; ! 238: c_sec = npoll_cpu % 3600; ! 239: c_min = c_sec / 60; ! 240: c_sec %= 60; ! 241: ! 242: tmp = npoll_ela; ! 243: if (tmp == 0) tmp = 1; ! 244: pct = ((npoll_cpu / tmp) * 100.0 + 0.5); ! 245: ! 246: printf(" %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct); ! 247: } else ! 248: printf("\n\n"); ! 249: } ! 250: ! 251: ############################################################################### ! 252: if (transmit) { ! 253: printf("Article Transmission (we contact them)\n"); ! 254: printf("System Offrd Took Toss Fail Pct Elapsed CPU Pct\n"); ! 255: for(s in xmt) { ! 256: ! 257: nxmt += xmt[s]; ! 258: nxmt_accept += xmt_accept[s]; ! 259: nxmt_refuse += xmt_refuse[s]; ! 260: nxmt_failed += xmt_failed[s]; ! 261: nxmt_ela += xmt_ela[s]; ! 262: nxmt_cpu += xmt_cpu[s]; ! 263: ! 264: we_offered = xmt[s]; ! 265: if (we_offered == 0) we_offered = 1; ! 266: they_toss = (xmt_refuse[s] / we_offered) * 100 + 0.5; ! 267: ! 268: e_hours = xmt_ela[s] / 3600; ! 269: e_sec = xmt_ela[s] % 3600; ! 270: e_min = e_sec / 60; ! 271: e_sec %= 60; ! 272: ! 273: c_hours = xmt_cpu[s] / 3600; ! 274: c_sec = xmt_cpu[s] % 3600; ! 275: c_min = c_sec / 60; ! 276: c_sec %= 60; ! 277: ! 278: elapsed = xmt_ela[s]; ! 279: if (elapsed == 0) elapsed = 1; ! 280: pct = ((xmt_cpu[s] / elapsed) * 100.0 + 0.5); ! 281: ! 282: printf("%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, xmt[s], xmt_accept[s], xmt_refuse[s], xmt_failed[s], they_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct); ! 283: } ! 284: ! 285: we_offered = nxmt; ! 286: if (we_offered == 0) we_offered = 1; ! 287: they_toss = (nxmt_refuse / we_offered) * 100 + 0.5; ! 288: ! 289: e_hours = nxmt_ela / 3600; ! 290: e_sec = nxmt_ela % 3600; ! 291: e_min = e_sec / 60; ! 292: e_sec %= 60; ! 293: ! 294: c_hours = nxmt_cpu / 3600; ! 295: c_sec = nxmt_cpu % 3600; ! 296: c_min = c_sec / 60; ! 297: c_sec %= 60; ! 298: ! 299: if (nxmt_ela == 0) nxmt_ela = 1; ! 300: pct = ((nxmt_cpu / nxmt_ela) * 100.0 + 0.5); ! 301: ! 302: printf("\n%-25s %5d %5d %5d %5d %3d%% %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nxmt, nxmt_accept, nxmt_refuse, nxmt_failed, they_toss, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct); ! 303: } ! 304: ! 305: ############################################################################### ! 306: ### Article Readership Statistics ### ! 307: ############################################################################### ! 308: ! 309: if (readers) { ! 310: printf("NNTP readership statistics\n"); ! 311: printf("System Conn Articles Groups Post Elapsed CPU Pct\n"); ! 312: for(s in systems) { ! 313: ### ! 314: ### servers are different animals; they don't belong in this part of the report ! 315: ### ! 316: if (servers[s] > 0 && groups[s] == 0 && articles[s] == 0) ! 317: continue; ! 318: ### ! 319: ### report the curious server pokers elsewhere ! 320: ### ! 321: if (groups[s] == 0 && articles[s] == 0 && post[s] == 0) { ! 322: unknown[s] += systems[s]; ! 323: curious = 1; ! 324: continue; ! 325: } ! 326: ! 327: nconn += systems[s]; ! 328: nart += articles[s]; ! 329: ngrp += groups[s]; ! 330: npost += post[s]; ! 331: ncpu += cpu[s]; ! 332: nela += ela[s]; ! 333: ! 334: e_hours = ela[s] / 3600; ! 335: e_sec = ela[s] % 3600; ! 336: e_min = e_sec / 60; ! 337: e_sec %= 60; ! 338: ! 339: c_hours = cpu[s] / 3600; ! 340: c_sec = cpu[s] % 3600; ! 341: c_min = c_sec / 60; ! 342: c_sec %= 60; ! 343: ! 344: elapsed = ela[s]; ! 345: if (elapsed == 0) elapsed = 1; ! 346: pct = ((cpu[s] / elapsed) * 100 + 0.5); ! 347: ! 348: printf("%-25s %5d %8d %6d %4d %3d:%02d:%02d %3d:%02d:%02d %3d%%\n", s, systems[s], articles[s], groups[s], post[s], e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct); ! 349: } ! 350: ! 351: e_hours = nela / 3600; ! 352: e_sec = nela % 3600; ! 353: e_min = e_sec / 60; ! 354: e_sec %= 60; ! 355: ! 356: c_hours = ncpu / 3600; ! 357: c_sec = ncpu % 3600; ! 358: c_min = c_sec / 60; ! 359: c_sec %= 60; ! 360: ! 361: if (nela == 0) nela = 1; ! 362: pct = ((ncpu / nela) * 100 + 0.5); ! 363: ! 364: printf("\n%-25s %5d %8d %6d %4d %3d:%02d:%02d %3d:%02d:%02d %3d%%\n\n", "TOTALS", nconn, nart, ngrp, npost, e_hours, e_min, e_sec, c_hours, c_min, c_sec, pct); ! 365: } ! 366: ! 367: ############################################################################### ! 368: if (curious) { ! 369: printf("Unknown NNTP server explorers\nSystem Conn\n"); ! 370: for(s in unknown) { ! 371: printf("%-25s %5d\n", s, unknown[s]); ! 372: } ! 373: printf("\n"); ! 374: } ! 375: ############################################################################### ! 376: if (timeouts) { ! 377: printf("Server timeouts\n"); ! 378: for(s in timeout) { ! 379: printf("%-25s %5d\n", s, timeout[s]); ! 380: } ! 381: printf("\n"); ! 382: } ! 383: ############################################################################### ! 384: if (readers) { ! 385: for(g in ng) { ! 386: x = length(g); ! 387: if (x > max) max = x; ! 388: ! 389: i = index(g, "."); ! 390: if (i > 0) top = substr(g, 1, i - 1); ! 391: else top = g; ! 392: category[top] += ng[g]; ! 393: } ! 394: fmt = sprintf("%%-%ds %%5d\n", max); ! 395: ! 396: printf("Newsgroup Request Counts (by category)\n"); ! 397: for(g in category) printf(fmt, g, category[g]); ! 398: ! 399: printf("\nNewsgroup Request Counts (by newsgroup)\n"); ! 400: for(g in ng) printf(fmt, g, ng[g]); ! 401: printf("\n"); ! 402: } ! 403: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.