Article View: news.software.nntp
Article #35992Re: news.groups reorganization
From: Richard Michael Todd
Date: Wed, 17 Mar 1999 00:00
Date: Wed, 17 Mar 1999 00:00
210 lines
7251 bytes
7251 bytes
Russ Allbery <rra@stanford.edu> writes:
> The thing that I could definitely use for the INET stuff, and which would
> also come in handy for all sorts of other things, is a news server that
> carries the entire Big Eight and for every post and every newsgroup,
> tracks the following pieces of information:
>
> * How many posts to each newsgroup.
> * How many posts to each newsgroup which aren't later cancelled.
> * How many posts solely to each newsgroup, and more generally some way
> of counting crossposted articles less. Or at least separating
> crossposted from non-crossposted traffic.
> * A byte count of traffic per newsgroup over some time span.
>
Except for tracking which posts are later cancelled (which would be
difficult to do in a channel feed), I've got a couple simple perl scripts
that do this. One, newstally20.pl, runs as a channel feed and dumps info
into a database. The other, newstallsumm.pl, dumps what's in the database.
For each newsgroup, it prints out the number of bytes, number of articles,
and number of articles that were crossposted to other groups, as well as
# of bytes/hour, articles/hour, and a crossposting percentage (fraction of
articles in the group that are crossposts.)
You'll want to change the reference to /var/netnews/lib/innshellvars.pl to
point to wherever it is on your inn installation. And if you ever figure out
a good way to implement the bit on tracking how many articles from each group
were later canceled or otherwise nuked (NoCeM, etc.), I'd like to know. :-)
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# newstallsumm.pl
# newstally20.pl
#
echo x - newstallsumm.pl
sed 's/^X//' >newstallsumm.pl << 'END-of-newstallsumm.pl'
X#!/usr/local/bin/perl
X# Dump the database created by newstally 2.0
X
Xuse DB_File;
X
Xrequire '/var/netnews/lib/innshellvars.pl';
X
Xrequire 'getopts.pl';
X
X$opt_d = 0; # default depth.
X&Getopts("d:");
X
X$grpdepth = $opt_d;
X
X$dbname = "$inn'pathdb/newstally.db";
Xtie %stats, 'DB_File', $dbname , O_RDONLY , 0, $DB_HASH|| die "dbcreate $dbname $!";
X
Xprint "NG\tBytes\tArts\tCPArts\tBytes/hr\tArts/hr\n";
X
X$curtime = $stats{".lasttime"};
X$lentime = $curtime - $stats{".starttime"};
X
X$hr = 3600;
X
Xwhile (($ng, $val) = each %stats) {
X next if ($ng eq ".starttime");
X next if ($ng eq ".lasttime");
X
X @foo = split(/@/, $val);
X next if (3 != @foo);
X
X $bytes = $foo[0];
X $arts = $foo[1];
X $cparts = $foo[2];
X $ngtrunc = &truncngname($ng, $grpdepth);
X &addinfo($ngtrunc,$bytes,$arts,$cparts);
X}
X
X
Xwhile (($ng, $val) = each %tempstats) {
X @foo = split(/@/, $val);
X# next if (3 != @foo);
X
X $bytes = $foo[0];
X $arts = $foo[1];
X $cparts = $foo[2];
X
X printf("%s %d %d %d %.2f %.2f %.1f\n", $ng, $bytes, $arts, $cparts,
X ($bytes/$lentime)*$hr, ($arts/$lentime)*$hr,
X ($arts ? 100*($cparts)/$arts : 0));
X}
X
Xuntie(%stats);
Xexit(0);
X
Xsub truncngname {
X my($ng,$depth) = @_;
X my(@foo);
X
X if ($depth == 0) {
X return $ng;
X }
X @foo = split(/\./,$ng);
X return join(".",@foo[0..$depth-1]);
X}
X
Xsub addinfo {
X my($grp,$bytes,$arts,$cparts) = @_;
X my(@curgrpstats);
X
X if (defined $tempstats{$grp}) {
X @curgrpstats = split(/@/,$tempstats{$grp});
X if (3 != @curgrpstats) {
X @curgrpstats = (0, 0, 0); # totbytes, tot arts, tot crossposted arts.
X }
X } else {
X @curgrpstats = (0, 0, 0); # totbytes, tot arts, tot crossposted arts.
X }
X $curgrpstats[0] += $bytes;
X $curgrpstats[1] += $arts;
X $curgrpstats[2] += $cparts;
X $tempstats{$grp} = join("@", @curgrpstats);
X}
END-of-newstallsumm.pl
echo x - newstally20.pl
sed 's/^X//' >newstally20.pl << 'END-of-newstally20.pl'
X#!/usr/local/bin/perl
X# News stats gathering program, vaguely inspired by Dan Brown's old 'newstally'
X# program.
X# Gathers stats feed by a "Tc,WsR" entry in newsfeeds.
X
Xuse DB_File;
Xrequire '/var/netnews/lib/innshellvars.pl';
X
Xsub LOCK_SH {1}
Xsub LOCK_EX { 2 }
Xsub LOCK_NB { 4 }
Xsub LOCK_UN { 8 }
X
X$dbname = "$inn'pathdb/newstally.db";
X$statsdbh = tie %stats, 'DB_File', $dbname || die "dbcreate $dbname $!";
X
X# Lock DB.
X$fd = $statsdbh->fd;
Xopen(DB_FH, "+<&=$fd") || die "dup $!";
Xunless (flock (DB_FH, LOCK_EX | LOCK_NB)) {
X print STDERR "$$: CONTENTION; must have exclusive lock!
X Waiting for write lock ($!) ....";
X unless (flock (DB_FH, LOCK_EX)) { die "flock: $!" }
X}
X
Xif (not defined $stats{".starttime"}) {
X $stats{".starttime"} = time;
X}
X
Xopen(ACTIVE,"$inn'active") || die "cant open active: $!";
Xwhile(<ACTIVE>) {
X @foo = split(/ /);
X next if (4 != @foo); # skip bogus lines in active
X $i = $foo[0];
X if (not defined $stats{$i}) {
X $stats{$i} = '0@0@0'; # create null stats entry for every group in active that does not have one already.
X }
X}
Xclose(ACTIVE);
X
Xwhile(<>) {
X chop;
X @foo = split(/ /);
X $size = shift(@foo);
X $numcps = scalar(@foo);
X foreach $i (@foo) {
X #nuke article numbers
X $i =~ s/:[0-9]*$//;
X &addart($i, $size, $numcps);
X }
X $stats{".lasttime"} = time;
X}
X$statsdbh->sync;
Xflock(DB_FH, LOCK_UN);
Xundef $statsdbh;
Xuntie %stats;
Xclose(DB_FH);
Xexit 0;
X
Xsub addart {
X my($grp, $size, $numcps) = @_;
X my(@curgrpstats);
X
X if (defined $stats{$grp}) {
X @curgrpstats = split(/@/,$stats{$grp});
X if (3 != @curgrpstats) {
X @curgrpstats = (0, 0, 0); # totbytes, tot arts, tot crossposted arts.
X }
X } else {
X @curgrpstats = (0, 0, 0); # totbytes, tot arts, tot crossposted arts.
X }
X $curgrpstats[0] += $size;
X $curgrpstats[1] ++;
X if ($numcps > 1) {
X $curgrpstats[2]++;
X }
X $stats{$grp} = join("@", @curgrpstats);
X}
END-of-newstally20.pl
exit
Technical Details
Message-ID:
<yl6677zaeud.fsf@intrepid.ecn.ou.edu>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<911552258.24620@isc.org> <73au0e$1m3$1@agate.berkeley.edu> <yloglww0p4.fsf_-_@windlord.stanford.edu> <slrn7epigl.4q.murray-paul@unix3.netaxs.com> <ylvhg2nzrb.fsf@windlord.stanford.edu> <7CySAmXHw-B@khms.westfalen.de> <ylogls7uzy.fsf@windlord.stanford.edu>Show Full Headers
Complete Article Headers
Message-ID: <yl6677zaeud.fsf@intrepid.ecn.ou.edu> Subject: Re: news.groups reorganization Date: Wed, 17 Mar 1999 00:00:00 +0000 From: Richard Michael Todd <rmtodd@intrepid.ecn.ou.edu> References: <911552258.24620@isc.org> <73au0e$1m3$1@agate.berkeley.edu> <yloglww0p4.fsf_-_@windlord.stanford.edu> <slrn7epigl.4q.murray-paul@unix3.netaxs.com> <ylvhg2nzrb.fsf@windlord.stanford.edu> <7CySAmXHw-B@khms.westfalen.de> <ylogls7uzy.fsf@windlord.stanford.edu> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 455908723 Followup-To: news.software.nntp X-Complaints-To: news@mailhost.ecn.ou.edu X-Trace: skywalker.ecn.ou.edu 921712484 69350 129.15.112.112 (17 Mar 1999 23:14:44 GMT) Organization: University of Oklahoma, Engineering Computer Network NNTP-Posting-Date: 17 Mar 1999 23:14:44 GMT Newsgroups: news.groups,news.software.nntp