Article View: news.software.nntp
Article #2559histstats - print news history file statistics
From: Gary Funck
Date: Sun, 08 May 1994 00:05
Date: Sun, 08 May 1994 00:05
1510 lines
47356 bytes
47356 bytes
This message includes the source for 'histstats', a program that reads
the news history file and prints statistics on the number of articles
in each group and hierarchy. Optionally 'histstats' will print a form
of histogram, giving the number of articles that will expire at
various time intervals. Histstats is helpful for determining the
possible space savings gained by a change in expiration policy.
Histstats is derived from the C News 'expire' program, and therefore
depends on the the C News library support routines. The 'readme'
file provides details for compiling and installing 'histstats'.
This is the first release of histstats, so there are likely some
problems, and perhaps some porting issues. If you run into problems,
please send me some mail, and I'll work with you to fix them.
Also, if you have suggestions or enhancements send them my way,
so they can be incorporated in a future release.
- Gary
PS: if you maintain a C News distribution, or some other news handling
system, and find 'histstats' a useable addition, please feel free to
incorporate the program as you see fit.
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: histstats-1.00 histstats-1.00/expire.8
# histstats-1.00/expire.8.diffs histstats-1.00/histstats.README
# histstats-1.00/histstats.c
# Wrapped by gary@intrepid on Mon May 2 13:44:25 1994
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test ! -d 'histstats-1.00' ; then
echo shar: Creating directory \"'histstats-1.00'\"
mkdir 'histstats-1.00'
fi
if test -f 'histstats-1.00/expire.8' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'histstats-1.00/expire.8'\"
else
echo shar: Extracting \"'histstats-1.00/expire.8'\" \(14459 characters\)
sed "s/^X//" >'histstats-1.00/expire.8' <<'END_OF_FILE'
X.\" =()<.ds a @<NEWSARTS>@>()=
X.ds a /iti/spool/news
X.\" =()<.ds b @<NEWSBIN>@>()=
X.ds b /usr/lib/newsbin
X.\" =()<.ds c @<NEWSCTL>@>()=
X.ds c /usr/lib/news
X.\" =()<.ds m @<NEWSMASTER>@>()=
X.ds m news
X.TH EXPIRE 8 "13 April 1992"
X.BY "C News"
X.SH NAME
expire, doexpire, expireiflow \- expire old news
X.br
histstats \- print history file statistics
X.br
mkhistory \- rebuild news history file
X.br
upact \- update news active file
X.br
recovact \- partially recover news active file
X.SH SYNOPSIS
X.B \*b/expire/expire
X[
X.B \-a
archdir
X] [
X.B \-p
X] [
X.B \-s
X] [
X.B \-F
c
X] [
X.B \-c
X] [
X.B \-n
nnnnn
X] [
X.B \-t
X] [
X.B \-l
X] [
X.B \-v
X] [
X.B \-d
X] [
X.B \-r
X] [
X.B \-g
X] [
X.B \-h
X]
X[ controlfile ]
X.br
X.B \*b/expire/histstats
X[
X.B \-g
X] [
X.B \-v
X]
X.br
X[
X.B \-H
history_dir
X] [
X.B \-F
c
X] [
X.B \-n
nnnnn
X] [
X.B \-d
X]
X.br
X.B \*b/expire/doexpire
expireoptions
X.br
X.B \*b/expire/expireiflow
minimum
expireoptions
X.br
X.B \*b/expire/mkhistory
X[
X.B \-s
sizemultiplier ]
X.br
X.B \*b/expire/upact
X.br
X.B \*b/expire/recovact
X.SH DESCRIPTION
X.I Expire
expires old news, removing it from the current-news directories and
X(if asked to) archiving it elsewhere.
It updates news's
X.I history
file to match.
X.I Expire
should normally be run nightly, typically by using \fIdoexpire\fR (see below).
X.PP
X.IR Expire 's
operations are controlled by a control file
X(which can be named or supplied on standard input),
which is not optional\(emthere is no default behavior.
XEach line of the control file
X(except for empty lines and lines starting with `#', which are ignored)
should have four white-space-separated
fields, as follows.
X.PP
The first field is
a newsgroup pattern list
X(containing no spaces!);
partial specifications are acceptable (e.g. `comp' specifies all groups
with that prefix).
See
X.IR newssys (5)
for full details.
X.PP
The second field is one letter, `m', `u', or `x', specifying that the line
applies only to moderated groups, only to unmoderated groups, or to both,
respectively.
X.PP
The third field specifies the expiry period in days.
The most general form is three numbers separated by dashes.
The units are days, decimal fractions are permitted,
and ``never'' is shorthand for an extremely large number.
The first number gives the retention period:
how long must pass after an article's arrival before it is a candidate
for expiry.
The third number gives the purge period:
how long must pass after arrival
before the article will be expired unconditionally.
The middle number gives the expiry period:
how long after an article's arrival it is expired by default.
An explicit expiry date in the article will override the expiry
period but not the retention period or the purge period.
If the field contains only two numbers with a dash separating them,
the retention period defaults to 0.
If the field contains only a number, the retention period defaults to 0
and the purge period defaults to `never'.
X(But see below.)
The retention period must be less than the purge period, and the expiry period
must lie between them.
X.PP
The fourth field is an archiving directory,
or `@' which indicates that the default archiving directory (see \fB\-a\fR)
should be used,
or `\-' which suppresses archiving.
An explicit archiving directory (not `@') prefixed with `=' means
that articles should be archived into that directory itself;
normally they go into subdirectories under it by newsgroup name,
as in the current-news directory tree.
X(E.g., article 123 of comp.pc.drivel being archived into archive directory
X\fI/exp\fR would normally become \fI/exp/comp/pc/drivel/123\fR,
but if the archiving
directory was given as `=/exp' rather than `/exp', it would become
X\fI/exp/123\fR.)
X.I Expire
creates subdirectories under an archiving directory automatically,
but will not create the archiving directory itself.
Archiving directories must be given as full pathnames.
X.PP
The first line of the control file which applies to a given article is
used to control its expiry.
It is an error for no line to apply;
the last line should be something like `all\ x\ 7\ \-'
to ensure that at least one line is always applicable.
Cross-posted articles are treated as if they were independently posted
to each group.
X.PP
The retention and purge defaults can be overridden by including a
X\fIbounds\fR line,
one with the special first field \fB/bounds/\fR.
The retention and purge defaults for following lines will be those of
the bounds line.
The defaults ``stretch'' as necessary to
ensure that the purge period is never less than the expiry period
and the retention period is never greater than the expiry period.
The other fields of a bounds line are ignored but must be present.
X.PP
XEntries in the \fIhistory\fR file can be retained after article expiry,
to stop a late-arriving copy of the article from being taken as a new article.
To arrange this, include a line with the special first field \fB/expired/\fR;
this line then controls the expiry of \fIhistory\fR lines after the
corresponding articles expire.
Dates are still measured from article arrival, not expiry.
The other fields of such a line are ignored but must be present.
It is strongly recommended that such a line be included, and that it
specify as long a time as practical.
X.PP
Command-line options are:
X.TP 10
X.BR \-a " dir"
X\fIdir\fR is the default archiving directory;
if no default is given, the control file may not contain
any `@' archive-directory fields.
X.TP
X.B \-p
print an `index' line for each archived article,
containing its pathname, message ID, date received, and `Subject:' line.
X.TP
X.B \-s
space is tight; optimize error recovery to minimize space consumed rather
than to leave as much evidence as possible.
X.TP
X.BR \-F " c"
the subfield separator character
in the middle \fIhistory\fR field is \fIc\fR rather
than the normal `~'.
X.TP
X.B \-c
check the format and consistency of the control file and the \fIactive\fR
file, but do not do any expiring.
X.TP
X.BR \-n " nnnnn"
set \fIexpire\fR's idea of the time to \fInnnnn\fR (for testing).
X.TP
X.BR \-t
print (on standard error) a shell-script-like description of what would
be done, but don't do it.
In the absence of archiving, all output lines will be of the form
X``\fBremove\fR\ \fIname\fR'', where \fIname\fR is a pathname relative
to \fI\*a\fR.
If an article is to be archived, this will be preceded (on the same
line) by ``\fBcopy\fR\ \fIname\fR\ \fIdir\fR\ \fB;\fR\ '', where \fIname\fR
is as in \fBremove\fR and \fIdir\fR is an archiving directory
X(including any `=' prefix)
as specified by the control file
or the \fB\-a\fR option.
X.TP
X.BR \-l
consider first filename in a \fIhistory\fR line to be the \fIleader\fR of
its line, to be expired only after all others have expired.
X(Meant for use on obnoxious systems like VMS which don't support real links.)
X.TP
X.BR \-r
suppress \fIhistory\fR rebuild.
Mostly for emergencies.
X(This leaves the \fIhistory\fR file out of date and larger than necessary,
but improves speed and eliminates the need for several megabytes of
temporary storage.)
X.TP
X.BR \-h
do not expire any article which would be archived if it were expired.
Mostly for emergencies, so that \fIexpire\fR can be run
X(to delete articles in non-archived groups)
even if space is short in archiving areas.
X.TP
X.BR \-v
verbose:
report some statistics after termination.
X.TP
X.BR \-g
report expiry dates that \fIgetdate\fR(3) does not like.
X.I Expire
ignores such dates, treating the article as if it had no explicit
expiry date.
X.TP
X.BR \-d
turn on (voluminous and cryptic) debugging output.
X.PP
X.I Expire
considers the middle field of a \fIhistory\fR line to consist of one or
more subfields separated by `~'.
The first is the arrival date, which can be either a \fIgetdate\fR(3)-readable
date or a decimal seconds count;
X\fIexpire\fR leaves this field unchanged.
The second\(emif present, non-null, and not `\-'\(emis an explicit expiry
date for the file, again in either format, which \fIexpire\fR will convert
to a decimal seconds count as it regenerates the \fIhistory\fR file.
Subsequent fields are preserved but ignored.
X.PP
X.I Doexpire
checks whether another \fIdoexpire\fR is running,
checks that there is enough disk space,
invokes \fIexpire\fR with any \fIexpireoptions\fR given and with
X\fI\*c/explist\fR as the control file,
and reports any difficulties by sending mail to \fI\*m\fR.
This is usually better than just running \fIexpire\fR directly.
If space is not adequate for archiving, \fIdoexpire\fR reports this
and invokes \fIexpire\fR with the \fB\-h\fR option.
If \fB\-r\fR is not among the \fIexpireoptions\fR,
and disk space is persistently inadequate for the
temporaries needed for history rebuilding, \fIdoexpire\fR reports this
and invokes \fIexpire\fR with the \fB\-r\fR option anyway.
X.PP
X.I Expireiflow
checks whether there are at least \fIminimum\fR megabytes available for
articles,
and invokes \fIdoexpire\fR with
X.B \-r
and the \fIexpireoptions\fR (if any) if not.
This may be useful on systems which run close to the edge on disk space.
X.PP
X.I Mkhistory
rebuilds the \fIhistory\fR file and its auxiliaries to match the articles
in \fI\*a\fR.
Normally
X.I mkhistory
uses a reasonable default size for the
X.IR dbz (3z)
index database; if the
X.B \-s
option is given, the expected number of entries in the history database
is taken to be the number of articles found in \fI\*a\fR times
X.IR sizemultiplier .
X.PP
X.I Histstats
scans the \fIhistory\fR file and prints statistics. A line is printed
for each group, and each news hierarchy that has one or more articles.
By default, each line in the output contains the group or hierarchy
name followed by the total number of articles contained in the
group or hierarchy.
X.PP
If the
X.B \-v
X(verbose) option is given, a line is printed giving a form of
histogram, listing the number of articles that have arrived
within various time intervals, based on the number of days that
have passed since the article was received.
XEach line gives the group or hierarchy name followed
by a series of numbers. The first number gives the total number
of articles in the group or hierarchy.
The next seven numbers give the total number of articles
received before today, yesterday, and so on for the past week.
The next three numbers give the number of
articles that arrived two weeks prior to today,
three weeks prior to today, and one month prior to today.
The last two numbers give the number of articles that were received
two months prior to today, and three months prior to today.
X.PP
XFor example, the default output for the `comp' news hierarchy
might appear as follows:
X.nf
X
comp 155021
X
X.fi
X.PP
If the
X.B \-v
option is given, the output might appear as follows:
X.nf
X
comp 155021 145306 145306 141588 131768 122472 115536 108891 101830 60054 10406 3157 2
X
where:
X
X 155021 is the total number of articles in the hierarchy
X 145306 were received prior to today
X 145306 were received prior to yesterday
X 141588 were received prior to day before yesterday
X 131768 were received prior to 3 days ago
X 122472 were received prior to 4 days ago
X 115536 were received prior to 5 days ago
X 108891 were received prior to 6 days ago
X 101830 were received prior to 2 weeks ago
X 60054 were received prior to 3 weeks ago
X 10406 were received prior to 1 month ago
X 3157 were received prior to 2 months ago
X 2 were received prior to 3 months ago
X.fi
X.PP
Normally,
X.I histstats
prints a line for each group or hierarchy.
If the
X.B \-g
option is given, then a line will be printed only for groups. No
summary information will be printed for hierarchies.
X.PP
X.I Histstats
accepts a few other switches that are seldom used. The
X.B \-H
switch supplies the name of a directory, other than \fI\*c\fR as the
directory containing the `history' file.
The
X.B -n
switch supplies an explicit date to be used to calculate the
number of days that have passed since an article arrived.
X.PP
X.I Upact
updates the third fields of the \fIactive\fR file to match the articles
in \fI\*a\fR (for historical reasons, \fIexpire\fR does not do this).
X.I Recovact
updates the second fields of the \fIactive\fR file to match the articles
in \fI\*a\fR,
for use in disaster recovery based on an outdated \fIactive\fR file
or initialization of a news system based on someone else's \fIactive\fR.
X.PP
X.IR Mkhistory ,
X.IR upact ,
and
X.IR recovact
are all fairly slow and they all lock the whole news
system for the duration of the run, so they should not be run casually.
X.SH FILES
X.ta 6c
X.nf
X\*c/history history file
X\*c/history.pag \fIdbm\fR database for history file
X\*c/history.dir \fIdbm\fR database for history file
X\*c/explist expiry control file
X\*c/history.o history file as of last expiry
X\*c/history.n* new history file and \fIdbm\fR files abuilding
X\*c/LOCKexpire \fIdoexpire\fR's lock file
X\*b/expire/* various auxiliaries
X.SH SEE ALSO
X.IR inews (1),
X.IR dbm (3),
X.IR newssys (5),
X.IR relaynews (8)
X.SH HISTORY
Written at U of Toronto by Henry Spencer, with contributions by Geoff Collyer.
X.SH BUGS
Archiving is always done by copying, never by linking.
This has the side effect that cross-posted articles are archived as
several independent copies.
X.PP
The
X.B \-p
subject-finder botches continued header lines,
as does \fImkhistory\fR,
although such lines are rare.
X.PP
X\fIUpact\fR is a distasteful kludge,
but then, so is the third field of the \fIactive\fR file.
X.PP
X\fIUpact\fR forces the third field of the \fIactive\fR file to be at least
five digits, for backward compatibility, but otherwise just makes it as
large as necessary.
The group-creation operations always create it ten digits long.
The discrepancy is harmless, since unlike the second field, the third
field is never updated in place.
X.PP
One cannot put more than one newsgroup into a single archiving directory
with the `=' feature, since the article numbers will collide with each
other and expire doesn't do anything about this.
Note that archiving a newsgroup which has subgroups into
an `=' directory puts all the subgroups in the same directory as the parent!
X(Specifying the group as `foo.bar,!foo.bar.all' will avoid this.)
X.PP
X.I Mkhistory
is inherently incapable of reconstructing history-file lines corresponding
to expired articles.
Protection against old articles reappearing is thus somewhat limited for
a while after the history file is rebuilt.
X.PP
X.I Expire
uses
X.IR access (2)
to test for the presence of archiving directories,
which can cause anomalies if it is run setuid (normally it's not).
END_OF_FILE
if test 14459 -ne `wc -c <'histstats-1.00/expire.8'`; then
echo shar: \"'histstats-1.00/expire.8'\" unpacked with wrong size!
fi
# end of 'histstats-1.00/expire.8'
fi
if test -f 'histstats-1.00/expire.8.diffs' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'histstats-1.00/expire.8.diffs'\"
else
echo shar: Extracting \"'histstats-1.00/expire.8.diffs'\" \(3577 characters\)
sed "s/^X//" >'histstats-1.00/expire.8.diffs' <<'END_OF_FILE'
X*** expire.8.orig Tue Apr 5 17:17:00 1994
X--- expire.8 Mon May 2 11:03:06 1994
X***************
X*** 11,16 ****
X--- 11,18 ----
X .SH NAME
X expire, doexpire, expireiflow \- expire old news
X .br
X+ histstats \- print history file statistics
X+ .br
X mkhistory \- rebuild news history file
X .br
X upact \- update news active file
X***************
X*** 50,55 ****
X--- 52,77 ----
X ]
X [ controlfile ]
X .br
X+ .B \*b/expire/histstats
X+ [
X+ .B \-g
X+ ] [
X+ .B \-v
X+ ]
X+ .br
X+ [
X+ .B \-H
X+ history_dir
X+ ] [
X+ .B \-F
X+ c
X+ ] [
X+ .B \-n
X+ nnnnn
X+ ] [
X+ .B \-d
X+ ]
X+ .br
X .B \*b/expire/doexpire
X expireoptions
X .br
X***************
X*** 281,286 ****
X--- 303,382 ----
X option is given, the expected number of entries in the history database
X is taken to be the number of articles found in \fI\*a\fR times
X .IR sizemultiplier .
X+ .PP
X+ .I Histstats
X+ scans the \fIhistory\fR file and prints statistics. A line is printed
X+ for each group, and each news hierarchy that has one or more articles.
X+ By default, each line in the output contains the group or hierarchy
X+ name followed by the total number of articles contained in the
X+ group or hierarchy.
X+ .PP
X+ If the
X+ .B \-v
X+ (verbose) option is given, a line is printed giving a form of
X+ histogram, listing the number of articles that have arrived
X+ within various time intervals, based on the number of days that
X+ have passed since the article was received.
X+ Each line gives the group or hierarchy name followed
X+ by a series of numbers. The first number gives the total number
X+ of articles in the group or hierarchy.
X+ The next seven numbers give the total number of articles
X+ received before today, yesterday, and so on for the past week.
X+ The next three numbers give the number of
X+ articles that arrived two weeks prior to today,
X+ three weeks prior to today, and one month prior to today.
X+ The last two numbers give the number of articles that were received
X+ two months prior to today, and three months prior to today.
X+ .PP
X+ For example, the default output for the `comp' news hierarchy
X+ might appear as follows:
X+ .nf
X+
X+ comp 155021
X+
X+ .fi
X+ .PP
X+ If the
X+ .B \-v
X+ option is given, the output might appear as follows:
X+ .nf
X+
X+ comp 155021 145306 145306 141588 131768 122472 115536 108891 101830 60054 10406 3157 2
X+
X+ where:
X+
X+ 155021 is the total number of articles in the hierarchy
X+ 145306 were received prior to today
X+ 145306 were received prior to yesterday
X+ 141588 were received prior to day before yesterday
X+ 131768 were received prior to 3 days ago
X+ 122472 were received prior to 4 days ago
X+ 115536 were received prior to 5 days ago
X+ 108891 were received prior to 6 days ago
X+ 101830 were received prior to 2 weeks ago
X+ 60054 were received prior to 3 weeks ago
X+ 10406 were received prior to 1 month ago
X+ 3157 were received prior to 2 months ago
X+ 2 were received prior to 3 months ago
X+ .fi
X+ .PP
X+ Normally,
X+ .I histstats
X+ prints a line for each group or hierarchy.
X+ If the
X+ .B \-g
X+ option is given, then a line will be printed only for groups. No
X+ summary information will be printed for hierarchies.
X+ .PP
X+ .I Histstats
X+ accepts a few other switches that are seldom used. The
X+ .B \-H
X+ switch supplies the name of a directory, other than \fI\*c\fR as the
X+ directory containing the `history' file.
X+ The
X+ .B -n
X+ switch supplies an explicit date to be used to calculate the
X+ number of days that have passed since an article arrived.
X .PP
X .I Upact
X updates the third fields of the \fIactive\fR file to match the articles
END_OF_FILE
if test 3577 -ne `wc -c <'histstats-1.00/expire.8.diffs'`; then
echo shar: \"'histstats-1.00/expire.8.diffs'\" unpacked with wrong size!
fi
# end of 'histstats-1.00/expire.8.diffs'
fi
if test -f 'histstats-1.00/histstats.README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'histstats-1.00/histstats.README'\"
else
echo shar: Extracting \"'histstats-1.00/histstats.README'\" \(5403 characters\)
sed "s/^X//" >'histstats-1.00/histstats.README' <<'END_OF_FILE'
X Subject: histstats - print news history file statistics
X Date: May, 3, 1994
X From: Gary Funck (gary@intrepid.com), Intrepid Technology Inc.
X
Histstats is a program that aids in the maintenance of the Unix
news article spool area. Histstats reads the news article 'history'
database and prints statistics on the total number of articles
filed in each group or hierarchy. Optionally, a form of histogram
is printed, giving the count of articles received at various
time intervals prior to a specified date.
X
The article counts and histogram produced by histstats can be used
by the news administrator to determine the relative amount of
space consumed by each group or hierarchy. The histogram can
be used to give feedback on the amount of space that might be
gained by imposing a particular article expiration strategy.
X
The command summary for 'histstats', extracted from the
X'expire' manpage, is given below:
X
NAME
X histstats - print history file statistics
X
SYNOPSIS
X /usr/lib/newsbin/expire/histstats [ -g ] [ -v ]
X [ -H history_dir ] [ -F c ] [ -n nnnnn ] [ -d ]
X
DESCRIPTION
X
X Histstats scans the history file and prints statistics. A
X line is printed for each group, and each news hierarchy that
X has one or more articles. By default, each line in the out-
X put contains the group or hierarchy name followed by the
X total number of articles contained in the group or hierar-
X chy.
X
X If the -v (verbose) option is given, a line is printed giv-
X ing a form of histogram, listing the number of articles that
X have arrived within various time intervals, based on the
X number of days that have passed since the article was
X received. Each line gives the group or hierarchy name fol-
X lowed by a series of numbers. The first number gives the
X total number of articles in the group or hierarchy. The
X next seven numbers give the total number of articles
X received before today, yesterday, and so on for the past
X week. The next three numbers give the number of articles
X that arrived two weeks prior to today, three weeks prior to
X today, and one month prior to today. The last two numbers
X give the number of articles that were received two months
X prior to today, and three months prior to today.
X
X For example, the default output for the `comp' news hierar-
X chy might appear as follows:
X
X comp 155021
X
X
X If the -v option is given, the output might appear as fol-
X lows:
X
X comp 155021 145306 145306 141588 131768 122472 115536 108891 101830 60054 10406 3157 2
X
X where:
X
X 155021 is the total number of articles in the hierarchy
X 145306 were received prior to today
X 145306 were received prior to yesterday
X 141588 were received prior to day before yesterday
X 131768 were received prior to 3 days ago
X 122472 were received prior to 4 days ago
X 115536 were received prior to 5 days ago
X 108891 were received prior to 6 days ago
X 101830 were received prior to 2 weeks ago
X 60054 were received prior to 3 weeks ago
X 10406 were received prior to 1 month ago
X 3157 were received prior to 2 months ago
X 2 were received prior to 3 months ago
X
X Normally, histstats prints a line for each group or hierar-
X chy. If the -g option is given, then a line will be printed
X only for groups. No summary information will be printed for
X hierarchies.
X
X Histstats accepts a few other switches that are seldom used.
X The -H switch supplies the name of a directory, other than
X /usr/lib/news as the directory containing the `history'
X file. The -n switch supplies an explicit date to be used to
X calculate the number of days that have passed since an arti-
X cle arrived.
X
INSTALLATION
X------------
X
Histstats is derived from the C News 'expire' program, and is
built in the cnews/expire directory. Here are the steps required
to install 'histstats':
X
X1. Login as the news administrator, and 'cd' to the directory
X where the cnews sources are located. (The C news source
X directory is called 'cnews' in the instructions below.)
X
X2. Copy histstats.c into the cnews/expire source directory.
X
X3. Copy the expire.8 manpage into the cnews/man directory, or
X update the existing expire.8 manpage, using the expire.8.diffs file.
X
X4. Add histstats to the 'THEM' make variable in the cnews/expire Makefile
X as shown below:
X
X THEM = expire histdups histinfo histslash histstats mkhistory \
X upact doexpire mkadir recovact expireiflow
X
X5. Add a step in the cnews/expire Makefile to build histstats
X as shown below:
X
X histstats: histstats.o $(LIBS)
X $(CC) $(CFLAGS) $(LDFLAGS) histstats.o \
X $(PRE) $(DBM) $(LIBS) $(POST) -o $@
X
X6. Make 'install' in the neews/expire directory, and in
X the cnews/man directory.
X
X7. Try running histstats by entering the command
X
X % histstats > article.counts
X
X or
X
X % histstats -v > article.histogram
X
Please send bug reports, fixes, and suggestions to Gary Funck
X(gary@intrepid.com). Hopefully, if histstats proves to be useful,
and reliable, it will become part of C news distribution. For now,
I'll try and make fixes and modest improvements, as needed.
X
DISCLAIMER: This is the first release of histstats.
The program has received little testing. USE AT YOUR OWN RISK.
END_OF_FILE
if test 5403 -ne `wc -c <'histstats-1.00/histstats.README'`; then
echo shar: \"'histstats-1.00/histstats.README'\" unpacked with wrong size!
fi
# end of 'histstats-1.00/histstats.README'
fi
if test -f 'histstats-1.00/histstats.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'histstats-1.00/histstats.c'\"
else
echo shar: Extracting \"'histstats-1.00/histstats.c'\" \(16749 characters\)
sed "s/^X//" >'histstats-1.00/histstats.c' <<'END_OF_FILE'
X/*
X * histstats - print history file statistics
X */
X#include <stdlib.h>
X#include <stdio.h>
X#include <ctype.h>
X#include <string.h>
X#include <errno.h>
X#include "fixerrno.h"
X#include <time.h>
X#include <signal.h>
X#include <sys/types.h>
X#include <sys/timeb.h>
X#include <sys/stat.h>
X#include "libc.h"
X#include "news.h"
X#include "config.h"
X#include "fgetmfs.h"
X#include "case.h"
X#include "dbz.h"
X#include "ngmatch.h"
X
X/* basic parameters of time, used in back() (and debugging code) */
X#ifndef EPOCH
X#define EPOCH ((time_t)0) /* the origin of time_t */
X#endif
X#ifndef FOREVER
X#define FOREVER 1e37 /* FOREVER > max value of time_t */
X#endif
X#define DAY ((double)24*60*60)
X#define DAYS(x) ((int)((now-(x))/DAY))
X
X/* unmoderated, moderated, either */
X#define UNMOD 'u'
X#define MOD 'm'
X#define EITHER 'x'
X
X/* 0-6 days, 1-3 weeks, 1-3 months and up */
X#define NUM_EXPCOUNT (7+3+3)
X
X/* structure for keeping track of group information */
X/* all group descriptions are kept in a linked tree */
X/* with totals kept for internal nodes, representing group hierarchies */
typedef struct gdes {
X struct gdes *down, *right;
X char *group_name; /* news group/hierarchy name */
X char *last_name; /* points to the final part of the group name */
X int is_mod; /* moderated? */
X long article_count; /* total articles in group/hierarchy */
X long expire_count[NUM_EXPCOUNT];
X } group_description;
X
X/* root node for the group descriptions */
group_description *groups;
X
int statdebug = 0; /* set by -d switch */
int verbose = 0; /* report statistics */
int groups_only = 0; /* only group info. (omit hierarchy info) */
char *subsep = "~"; /* subfield separator in middle field */
char *histdir = NULL; /* where to find history files */
X
time_t now; /* set once in startup, as reference */
struct timeb ftnow; /* ftime() result for getdate() */
X#define NODATE ((time_t)(-1)) /* time_t value indicating date not given */
time_t latest = 0; /* most recent arrival date */
X
X/* Buffer etc. for readline and friends. */
char rlbuf[BUFSIZ];
int rlnleft = 0;
char *rest;
int nlocked = 0; /* has readline() locked the news system? */
X
char *progname;
X
extern long atol();
extern double atof();
extern struct tm *gmtime();
extern time_t time();
X
extern time_t getdate();
X
X/* forward declarations */
void cd();
void complain();
void die();
void do_article();
void doit();
void do_line();
void euclose();
void eufclose();
XFILE *eufopen();
void fail();
group_description *find_group();
group_description *new_group();
void printstuff();
void propagate_counts();
void print_counts();
void read_active();
time_t readdate();
char *readline();
void refill();
void warning();
X
X/*
X - main - parse arguments and handle options
X */
main(argc, argv)
int argc;
char *argv[];
X{
X int c;
X int errflg = 0;
X FILE *cf;
X extern int optind;
X extern char *optarg;
X
X progname = argv[0];
X now = time((time_t *)NULL);
X ftime(&ftnow);
X
X while ((c = getopt(argc, argv, "gvF:n:H:d")) != EOF)
X switch (c) {
X case 'g': /* only print info about individual groups */
X groups_only = 1;
X break;
X case 'v': /* verbose */
X verbose = 1;
X break;
X case 'H': /* where to find history files */
X histdir = optarg;
X break;
X case 'F': /* subfield separator in middle field */
X subsep = optarg;
X break;
X case 'n': /* set value of "now" for testing */
X now = atol(optarg);
X break;
X case 'd': /* debug */
X statdebug = 1;
X break;
X case '?':
X default:
X errflg++;
X break;
X }
X if (errflg || optind < argc-1) {
X fprintf(stderr,
X "Usage: %s [-v] [-g] [-F sep] [-H histdir] [-n now_date] [-d] \n",
X progname);
X exit(2);
X }
X if (statdebug)
X setbuf(stderr, (char *)NULL);
X
X read_active(ctlfile("active"));
X
X if (histdir == NULL) histdir = strsave(ctlfile((char *)NULL));
X
X (void) umask(newsumask());
X doit(); /* side effect: newslock() */
X newsunlock();
X
X if (latest > time((time_t *)NULL)) {
X complain("some article arrival dates are in the future!", "");
X complain("\tis your system clock set wrong?", "");
X }
X
X propagate_counts(groups);
X
X print_counts(groups);
X
X exit(0);
X}
X
X/*
X - read_active - read the 'active' file and fill in the news group tree
X */
void
read_active(afile)
char *afile;
X{
X FILE *af;
X# define NFACT 4
X char *field[NFACT];
X char *line, *g_name;
X int i, nf, is_mod;
X
X groups = new_group("ALL");
X af = eufopen(afile, "r");
X while ((line = fgetms(af)) != NULL) {
X i = strlen(line);
X if (i > 0) line[i-1] = '\0';
X nf = split(line, field, NFACT, "");
X g_name = field[0];
X if (nf != NFACT) {
X die("wrong number of fields in active for `%s'", g_name);
X }
X is_mod = (strchr(field[3], 'm') != NULL);
X enter_group(g_name, is_mod);
X free(line);
X }
X (void) fclose(af);
X}
X
X/*
X - doit - read history file and calculate totals
X */
void
doit()
X{
X int history_fd;
X char *line;
X
X cd(histdir);
X history_fd = open("history", 0);
X if (history_fd < 0) fail("cannot open `%s'", "history");
X cd(artfile((char *)NULL));
X while ((line = readline(history_fd)) != NULL) {
X do_line(line);
X free(line);
X }
X /* side effect of readline() == NULL: newslock() */
X (void) close(history_fd);
X}
X
X/*
X - do_line - handle one history line
X */
void
do_line(line)
char *line;
X{
X char *work;
X# define NF 3
X char *field[NF]; /* fields in line */
X int nf;
X# define NSF 10
X char *subfield[NSF]; /* subfields in middle field */
X int nsf;
X time_t recdate;
X time_t expdate;
X char expbuf[25]; /* plenty for decimal time_t */
X
X if (statdebug) {
X fputs("\ndo_line `", stderr);
X fputs(line, stderr);
X fputs("'\n", stderr);
X }
X
X /* pull the incoming line apart */
X work = strsave(line);
X nf = split(work, field, NF, "\t");
X if (nf != 3 && nf != 2) {
X free(work);
X complain("wrong number of fields in history `%.40s...'", line);
X return;
X }
X if (*field[0] == '\0') {
X complain("no message-ID in history `%.40s...' -- expiring", line);
X if (strlen(field[1]) < 3) {
X complain("\toops -- can't -- fix manually", "");
X free(work);
X return; /* leaving the line in the new history file */
X } else
X sprintf(field[1], "0%c0", *subsep);
X }
X if (nf == 2)
X field[2] = NULL;
X nsf = split(field[1], subfield, NSF, subsep);
X
X /* sort out the dates */
X if (nsf < 2 || STREQ(subfield[1], "-") || STREQ(subfield[1], ""))
X expdate = NODATE;
X else {
X expdate = readdate(subfield[1]);
X if (expdate == NODATE) {
X complain("bad expiry date in `%.40s...',", line);
X complain(" specifically, `%s' -- ignored", subfield[1]);
X }
X }
X recdate = readdate(subfield[0]);
X if (recdate == NODATE) {
X free(work);
X complain("bad arrival date in `%.40s...' -- fix by hand", line);
X return;
X }
X if (recdate > latest) latest = recdate;
X if (statdebug)
X fprintf(stderr, "rec %ld, expire %ld\n", (long)recdate,
X (long)expdate);
X
X /* deal with it */
X if (nf > 2 && STREQ(field[2], "/")) /* old C news cancellation */
X field[2] = NULL;
X else if (nf > 2 && STREQ(field[2], "cancelled")) /* B 2.11 */
X field[2] = NULL;
X if (field[2] != NULL) {
X do_article(field[2], recdate, field[0]);
X }
X free(work);
X}
X
X/*
X - do_article - tally time since article received
X *
X */
void
do_article(post_list, recdate, msgid)
char *post_list;
time_t recdate;
char *msgid;
X{
X# define NDELIM " ,"
X char *src, *name, *last_slash, *cp;
X char save_ch;
X group_description *g;
X int i, k;
X long ndays;
X if (post_list == NULL) return;
X for (src = post_list;;) {
X src += strspn(src, NDELIM);
X name = src;
X src += strcspn(src, NDELIM);
X save_ch = *src;
X *src = '\0';
X if (*name == '\0') break;
X last_slash = strrchr(name, '/');
X if (last_slash == NULL) break;
X *last_slash = '\0';
X for (cp = name; *cp; ++cp) {
X if (*cp == '/') *cp = '.';
X }
X if (statdebug) fprintf(stderr, "article group name `%s'\n", name);
X g = find_group(name);
X if (g == NULL) {
X fprintf(stderr, "msg: %s, group '%s' not in active list\n",
X msgid, name);
X enter_group(name, 0);
X g = find_group(name);
X if (g == NULL) die("enter_group failed.");
X }
X *src = save_ch;
X /* increment total articles in this group */
X g->article_count += 1;
X /* get the index of the longest time interval containing expdate */
X ndays = DAYS(recdate);
X if (ndays < 7) {
X k = ndays;
X } else if (ndays < 28) {
X k = 6 + (ndays + 6) /7;
X } else {
X if (ndays > 28*3) ndays = 28*3;
X k = 9 + (ndays + 27) / 28;
X }
X /* add 1 to all intervals that would cover this */
X for (i = k; i >= 0; --i) {
X g->expire_count[i] += 1;
X }
X }
X}
X
X
X/*
X - propagate_counts - compute counts for hierarchies
X *
X * The counts at an internal node equal the sum of the counts of all
X * descendant nodes. A news hierarchy is represented as an internal node.
X * Propagate_counts traverses the tree recursively, and propagates
X * article counts from terminal nodes back to the root of the tree.
X */
void
propagate_counts(g)
group_description *g;
X{
X int i;
X group_description *child;
X if (g == NULL || g->down == NULL) return;
X for (child = g->down; child != NULL; child = child->right) {
X propagate_counts(child);
X g->article_count += child->article_count;
X for (i = 0; i < NUM_EXPCOUNT; ++i) {
X g->expire_count[i] += child->expire_count[i];
X }
X }
X}
X
X
X/*
X - print_counts - print the article/expiration counts for each group/hierarchy
X */
void
print_counts(g)
group_description *g;
X{
X int i;
X group_description *child;
X if (g == NULL) return;
X if (g->article_count == 0) return;
X if (!groups_only || g->down == NULL) {
X printf("%s", g->group_name);
X if (verbose) {
X for (i = 0; i < NUM_EXPCOUNT; ++i) {
X printf(" %d", g->expire_count[i]);
X }
X } else {
X printf(" %d", g->article_count);
X }
X printf("\n");
X }
X for (child = g->down; child != NULL; child = child->right) {
X print_counts(child);
X }
X}
X
X/*
X - readdate - turn a date into internal form
X */
time_t
readdate(text)
char *text;
X{
X time_t ret;
X
X if (strspn(text, "0123456789") == strlen(text))
X ret = atol(text);
X else
X ret = getdate(text, &ftnow);
X if (ret == -1)
X ret = NODATE;
X
X return(ret);
X}
X
X/*
X - new_group - allocate a new group description node
X */
group_description *
new_group(g_name)
char *g_name;
X{
X int i;
X group_description *g;
X char *last_dot, *last_name;
X g = (group_description *)malloc(sizeof(group_description));
X if (g == NULL) fail("out of memory at newsgroup `%s'", g_name);
X g->group_name = strsave(g_name);
X last_dot = strrchr(g->group_name, '.');
X last_name = (last_dot != NULL) ? (last_dot+1) : g->group_name;
X g->last_name = last_name;
X g->is_mod = 0;
X g->down = NULL;
X g->right = NULL;
X g->article_count = 0;
X for (i = 0; i < NUM_EXPCOUNT; ++i) g->expire_count[i] = 0;
X return g;
X}
X
X/*
X - enter_group - enter a group description into the tree
X */
enter_group(group_name, is_mod)
char *group_name;
int is_mod;
X{
X char *cp, *sp, *last_name;
X group_description *r = groups;
X group_description **gg;
X char g_name[2000];
X for (cp = group_name, sp = g_name; *cp; ) {
X int cmp;
X for (last_name = sp; *cp && *cp != '.'; *sp++ = *cp++ ) ;
X *sp = '\0';
X for (gg = &r->down, cmp = 1; *gg != NULL;
X gg = &(*gg)->right) {
X cmp = strcmp(last_name, (*gg)->last_name);
X if (cmp <= 0) break;
X }
X if (cmp != 0) {
X group_description *g_link = *gg;
X *gg = new_group(g_name);
X (*gg)->right = g_link;
X }
X if (*gg == NULL) die("*gg == NULL");
X r = *gg;
X if (*cp == '.') *sp++ = *cp++;
X }
X r->is_mod = is_mod;
X}
X
X/*
X - find_group - look up a group in the 'groups' table
X */
group_description *
find_group(group_name)
char *group_name;
X{
X char *cp, *sp;
X int cmp;
X group_description *r, *gg;
X char last_name[1000];
X for (cp = group_name, r = groups, cmp = 1; *cp; ) {
X for(sp = last_name; *cp && *cp != '.'; *sp++ = *cp++ ) ;
X *sp = '\0';
X for (gg = r->down, cmp = 1; gg != NULL; gg = gg->right) {
X cmp = strcmp(last_name, gg->last_name);
X if (cmp == 0) break;
X }
X if (cmp != 0) break;
X r = gg;
X if (*cp == '.') ++cp;
X }
X if (cmp != 0) r = NULL;
X return r;
X}
X
char *months[12] = {
X "Jan",
X "Feb",
X "Mar",
X "Apr",
X "May",
X "Jun",
X "Jul",
X "Aug",
X "Sep",
X "Oct",
X "Nov",
X "Dec",
X};
X
X/*
X - printstuff - print information about an article
X */
void
printstuff(msgid, name, recdate)
char *msgid;
char *name;
time_t recdate;
X{
X struct tm *gmt;
X
X gmt = gmtime(&recdate);
X printf("%s\t%s\t%d-%s-%d\n", name, msgid,
X gmt->tm_mday, months[gmt->tm_mon]);
X}
X
X/*
X - eufopen - fopen, with fail if doesn't succeed
X */
XFILE *
eufopen(name, mode)
char *name;
char *mode;
X{
X FILE *f;
X static char grump[50] = "can't open `%s' for `";
X
X f = fopen(name, mode);
X if (f == NULL) {
X (void) strcat(grump, mode);
X (void) strcat(grump, "'");
X fail(grump, name);
X }
X return(f);
X}
X
X/*
X - eufclose - fclose with failure checking
X */
void
eufclose(f, name)
XFILE *f;
char *name;
X{
X if (nfclose(f) == EOF)
X fail("error in closing file `%s'", name);
X}
X
X/*
X - euclose - close with failure checking
X */
void
euclose(f, name)
int f;
char *name;
X{
X if (fsync(f) < 0 || close(f) < 0)
X fail("error in closing file `%s'", name);
X}
X
X/*
X - unprivileged - no-op needed to keep the pathname stuff happy
X */
void
unprivileged(reason)
char *reason;
X{
X}
X
X/*
X - fail - call errunlock, possibly after cleanup
X */
void
fail(s1, s2)
char *s1;
char *s2;
X{
X errunlock(s1, s2);
X /* NOTREACHED */
X}
X
X/*
X - die - like fail, but errno contains no information
X */
void
die(s1, s2)
char *s1;
char *s2;
X{
X errno = 0;
X fail(s1, s2);
X}
X
X/*
X - readline - read history line (sans newline), with locking when we hit EOF
X *
X * Minor flaw: will lose a last line which lacks a newline.
X */
char * /* NULL is EOF */
readline(fd)
int fd; /* Note descriptor, not FILE *. */
X{
X char *line;
X int nline;
X char *p;
X int c;
X int n;
X extern void refill();
X
X nline = 100; /* reasonable starter */
X line = malloc(nline);
X if (line == NULL)
X fail("out of space when reading history", "");
X p = line;
X
X for (;;) {
X if (rlnleft <= 0) {
X refill(fd);
X if (rlnleft <= 0) /* refill gave up. */
X return(NULL);
X }
X c = *rest++;
X rlnleft--;
X
X if (c == '\n') {
X *p++ = '\0';
X return(line);
X }
X if (p - line >= nline - 1) {
X nline = (nline * 3) / 2;
X n = p - line;
X line = realloc(line, nline);
X if (line == NULL)
X fail("out of memory in readline", "");
X p = line + n;
X }
X *p++ = c;
X }
X /* NOTREACHED */
X}
X
X/*
X - refill - refill readline's buffer, with locking on EOF
X */
void
refill(fd)
int fd;
X{
X int ret;
X
X /* Just in case... */
X if (rlnleft > 0)
X return;
X
X /* Try ordinary read. */
X ret = read(fd, rlbuf, (int)sizeof(rlbuf));
X if (ret < 0)
X fail("read error in history", "");
X if (ret > 0) {
X rlnleft = ret;
X rest = rlbuf;
X return;
X }
X
X /* EOF. */
X if (nlocked)
X return; /* We're really done. */
X
X /* EOF but we haven't locked yet. Lock and try again. */
X (void) signal(SIGINT, SIG_IGN);
X (void) signal(SIGQUIT, SIG_IGN);
X (void) signal(SIGHUP, SIG_IGN);
X (void) signal(SIGTERM, SIG_IGN);
X newslock();
X nlocked = 1;
X refill(fd);
X}
END_OF_FILE
if test 16749 -ne `wc -c <'histstats-1.00/histstats.c'`; then
echo shar: \"'histstats-1.00/histstats.c'\" unpacked with wrong size!
fi
# end of 'histstats-1.00/histstats.c'
fi
echo shar: End of shell archive.
exit 0
--
Gary Funck gary@intrepid.com
Intrepid Technology Inc., Mountain View CA (415) 964-8135
Technical Details
Message-ID:
<CpGIx6.F9J@Intrepid.COM>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.sources.d.mbox.zip!bga.com!news.sprintlink.net!hookup!europa.eng.gtefsd.com!howland.reston.ans.net!pipex!sunic!EU.net!uunet!intrepid!garyShow Full Headers
Complete Article Headers
Message-ID: <CpGIx6.F9J@Intrepid.COM> Subject: histstats - print news history file statistics Date: Sun, 8 May 1994 00:05:30 GMT From: gary@Intrepid.COM (Gary Funck) Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.sources.d.mbox.zip!bga.com!news.sprintlink.net!hookup!europa.eng.gtefsd.com!howland.reston.ans.net!pipex!sunic!EU.net!uunet!intrepid!gary Newsgroups: news.software.nntp,comp.sources.d Organization: Intrepid Technology, Inc. X-Newsreader: TIN [version 1.2 PL2] Lines: 1509