From 963f07432c98b247bc4c3df1bbef955d120db74a Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Fri, 30 May 2025 16:38:18 +0200 Subject: [PATCH] Move cliservstats to hoststats. Signed-off-by: Thomas Hochstein --- bin/{cliservstats.pl => hoststats.pl} | 144 +++++++++++--------------- bin/postingstats.pl | 8 +- contrib/dopostingstats.sh | 2 +- doc/ChangeLog | 1 + doc/README | 4 +- 5 files changed, 68 insertions(+), 91 deletions(-) rename bin/{cliservstats.pl => hoststats.pl} (74%) diff --git a/bin/cliservstats.pl b/bin/hoststats.pl similarity index 74% rename from bin/cliservstats.pl rename to bin/hoststats.pl index f92eb24..9e949ff 100644 --- a/bin/cliservstats.pl +++ b/bin/hoststats.pl @@ -1,9 +1,9 @@ #! /usr/bin/perl # -# cliservstats.pl +# hoststats.pl # -# This script will get statistical data on client (newsreader) and -# server (host) usage from a database. +# This script will get statistical data on server (host) usage +# from a database. # # It is part of the NewsStats package. # @@ -31,7 +31,7 @@ Getopt::Long::config ('bundling'); ### read commandline options my ($OptCaptions,$OptComments,$OptDB,$OptFileTemplate,$OptFormat, $OptGroupBy,$LowBound,$OptMonth,$OptNames,$OptOrderBy, - $OptReportType,$OptSums,$OptType,$UppBound,$OptConfFile); + $OptReportType,$OptSums,$UppBound,$OptConfFile); GetOptions ('c|captions!' => \$OptCaptions, 'comments!' => \$OptComments, 'db=s' => \$OptDB, @@ -44,7 +44,6 @@ GetOptions ('c|captions!' => \$OptCaptions, 'o|order-by=s' => \$OptOrderBy, 'r|report=s' => \$OptReportType, 's|sums!' => \$OptSums, - 't|type=s' => \$OptType, 'u|upper=i' => \$UppBound, 'conffile=s' => \$OptConfFile, 'h|help' => \&ShowPOD, @@ -52,15 +51,6 @@ GetOptions ('c|captions!' => \$OptCaptions, # parse parameters # $OptComments defaults to TRUE if --filetemplate is not used $OptComments = 1 if (!$OptFileTemplate && !defined($OptComments)); -# parse $OptType -if ($OptType) { - if ($OptType =~ /(host|server)s?/i) { - $OptType = 'host'; - } elsif ($OptType =~ /(newsreader|client)s?/i) { - $OptType = 'client'; - } -} -&Bleat(2, "Please use '--type server' or '--type client'.") if !$OptType; # parse $OptReportType if ($OptReportType) { if ($OptReportType =~ /sums?/i) { @@ -74,14 +64,8 @@ if ($OptReportType) { my %Conf = %{ReadConfig($OptConfFile)}; ### set DBTable -if ($OptDB) { - $Conf{'DBTable'} = $OptDB; -} -elsif ($OptType eq 'host') { - $Conf{'DBTable'} = $Conf{'DBTableHosts'}; -} else { - $Conf{'DBTable'} = $Conf{'DBTableClnts'}; -} +$Conf{'DBTable'} = $Conf{'DBTableHosts'}; +$Conf{'DBTable'} = $OptDB if $OptDB; ### init database my $DBHandle = InitDB(\%Conf,1); @@ -97,14 +81,14 @@ my ($CaptionPeriod,$SQLWherePeriod) = &GetTimePeriod($OptMonth); # with placeholders as well as a list of names to bind to them my ($SQLWhereNames,@SQLBindNames); if ($OptNames) { - ($SQLWhereNames,@SQLBindNames) = &SQLGroupList($OptNames,$OptType); + ($SQLWhereNames,@SQLBindNames) = &SQLGroupList($OptNames,'host'); # bail out if --names is invalid &Bleat(2,"--names option has an invalid format!") if !$SQLWhereNames; } ### build SQL WHERE clause -my $ExcludeSums = $OptSums ? '' : sprintf("%s != 'ALL'",$OptType); +my $ExcludeSums = $OptSums ? '' : sprintf("%s != 'ALL'",'host'); my $SQLWhereClause = SQLBuildClause('where',$SQLWherePeriod,$SQLWhereNames, $ExcludeSums, &SQLSetBounds('default',$LowBound,$UppBound)); @@ -118,8 +102,8 @@ $OptGroupBy = 'name' if (!$OptGroupBy and $OptMonth and $OptMonth =~ /:/ and $OptNames and $OptNames !~ /[:*%]/); # parse $OptGroupBy to $GroupBy, create ORDER BY clause $SQLOrderClause # if $OptGroupBy is still not set, SQLSortOrder() will default to 'month' -my ($GroupBy,$SQLOrderClause) = SQLSortOrder($OptGroupBy, $OptOrderBy, $OptType); -# $GroupBy will contain 'month' or 'host'/'client' (parsed result of $OptGroupBy) +my ($GroupBy,$SQLOrderClause) = SQLSortOrder($OptGroupBy, $OptOrderBy, 'host'); +# $GroupBy will contain 'month' or 'host' (parsed result of $OptGroupBy) # set it to 'month' or 'key' for OutputData() $GroupBy = ($GroupBy eq 'month') ? 'month' : 'key'; @@ -128,19 +112,19 @@ my $SQLSelect; my $SQLGroupClause = ''; my $Precision = 0; # number of digits right of decimal point for output if ($OptReportType and $OptReportType ne 'default') { - $SQLGroupClause = "GROUP BY $OptType"; + $SQLGroupClause = "GROUP BY host"; # change $SQLOrderClause: replace everything before 'postings' $SQLOrderClause =~ s/BY.+postings/BY postings/; - $SQLSelect = "'All months',$OptType,SUM(postings)"; + $SQLSelect = "'All months',host,SUM(postings)"; # change $SQLOrderClause: replace 'postings' with 'SUM(postings)' $SQLOrderClause =~ s/postings/SUM(postings)/; } else { - $SQLSelect = "month,$OptType,postings"; + $SQLSelect = "month,host,postings"; }; ### get length of longest name delivered by query ### for formatting purposes -my $Field = ($GroupBy eq 'month') ? $OptType : 'month'; +my $Field = ($GroupBy eq 'month') ? 'host' : 'month'; my ($MaxLength,$MaxValLength) = &GetMaxLength($DBHandle,$Conf{'DBTable'}, $Field,'postings',$SQLWhereClause, '',@SQLBindNames); @@ -155,8 +139,8 @@ $DBQuery = $DBHandle->prepare(sprintf('SELECT %s FROM %s.%s %s %s %s', $SQLOrderClause)); # execute query $DBQuery->execute(@SQLBindNames) - or &Bleat(2,sprintf("Can't get %s data for %s from %s.%s: %s\n", - $OptType,$CaptionPeriod,$Conf{'DBDatabase'},$Conf{'DBTable'}, + or &Bleat(2,sprintf("Can't get host data for %s from %s.%s: %s\n", + $CaptionPeriod,$Conf{'DBDatabase'},$Conf{'DBTable'}, $DBI::errstr)); ### output results @@ -175,7 +159,7 @@ if ($OptCaptions && $OptComments) { $LeadIn .= sprintf("# ----- Names: %s\n",join(',',split(/:/,$OptNames))) if $OptNames; # print boundaries, if set - my $CaptionBoundary= '(counting only month fulfilling this condition)'; + my $CaptionBoundary= '(counting only months fulfilling this condition)'; $LeadIn .= sprintf("# ----- Threshold: %s %s x %s %s %s\n", $LowBound ? $LowBound : '',$LowBound ? '=>' : '', $UppBound ? '<=' : '',$UppBound ? $UppBound : '',$CaptionBoundary) @@ -201,11 +185,11 @@ __END__ =head1 NAME -cliservstats - create reports on host or client usage +hoststats - create reports on host usage =head1 SYNOPSIS -B B<-t> I [B<-Vhcs> B<--comments>] [B<-m> I[:I] | I] [B<-n> I] [B<-r> I] [B<-l> I] [B<-u> I] [B<-g> I] [B<-o> I] [B<-f> I] [B<--filetemplate> I] [B<--db> I] [B<--conffile> I] +B [B<-Vhcs> B<--comments>] [B<-m> I[:I] | I] [B<-n> I] [B<-r> I] [B<-l> I] [B<-u> I] [B<-g> I] [B<-o> I] [B<-f> I] [B<--filetemplate> I] [B<--db> I] [B<--conffile> I] =head1 REQUIREMENTS @@ -214,8 +198,7 @@ See L. =head1 DESCRIPTION This script create reports on newsgroup usage (number of postings from -each host or using each client per month) taken from result tables -created by B. +each host) taken from result tables created by B. =head2 Features and options @@ -225,9 +208,9 @@ The time period to act on defaults to last month; you can assign another time period or a single month (or drop all time constraints) via the B<--month> option (see below). -B will process all hosts or clients by default; you can -limit processing to only some hosts or clients by supplying a list of -those names by using the B<--names> option (see below). +B will process all hosts by default; you can limit +processing to only some hosts by supplying a list of those names by +using the B<--names> option (see below). =head3 Report type @@ -238,18 +221,18 @@ or all postings summed up; for details, see below. Furthermore you can set an upper and/or lower boundary to exclude some results from output via the B<--lower> and B<--upper> options, -respectively. By default, all hosts/clients with more and/or less -postings per month will be excluded from the result set (i.e. not -shown and not considered forsum reports). +respectively. By default, all hosts with more and/or less postings +per month will be excluded from the result set (i.e. not shown and +not considered for sum reports). =head3 Sorting and formatting the output By default, all results are grouped by month; you can group results by -hosts/clients instead via the B<--group-by> option. Within those -groups, the list of hosts/clients (or months) is sorted alphabetically -(or chronologically, respectively) ascending. You can change that order -(and sort by number of postings) with the B<--order-by> option. For -details and exceptions, please see below. +hosts instead via the B<--group-by> option. Within those groups, the +list of hosts (or months) is sorted alphabetically (or chronologically, +respectively) ascending. You can change that order (and sort by number +of postings) with the B<--order-by> option. For details and exceptions, +please see below. The results will be formatted as a kind of table; you can change the output format to a simple list or just a list of names and number of @@ -262,7 +245,7 @@ one for each month, by submitting the B<--filetemplate> option, see below. =head2 Configuration -B will read its configuration from F +B will read its configuration from F which should be present in etc/ via Config::Auto or from a configuration file submitted by the B<--conffile> option. @@ -282,11 +265,6 @@ Print out version and copyright information and exit. Print this man page and exit. -=item B<-t>, B<--type> I - -Create report for hosts (servers) or clients (newsreaders), using -I or I respectively. - =item B<-m>, B<--month> I Set processing period to a single month in YYYY-MM format or to a time @@ -296,7 +274,7 @@ processing period to process the whole database. =item B<-n>, B<--names> I -Limit processing to a certain set of host or client names. I +Limit processing to a certain set of hostnames. I can be a single name (eternal-september.org), a group of names (*.inka.de) or a list of either of these, separated by colons, for example @@ -312,9 +290,9 @@ containing the sum of all detected hosts for that month. Choose the report type: I or I -By default, B will report the number of postings for each -host/client in each month. But it can also report the total sum of postings -per host/client for all months. +By default, B will report the number of postings for each +host in each month. But it can also report the total sum of postings +per host for all months. For report type I, the B option has no meaning and will be silently ignored (see below). @@ -327,13 +305,13 @@ Set the lower boundary. See below. Set the upper boundary. -By default, all hosts/clients with more postings per month than the -upper boundary and/or less postings per month than the lower boundary +By default, all hosts with more postings per month than the upper +boundary and/or less postings per month than the lower boundary will be excluded from further processing. For the default report that -means each month only hosts/clients with a number of postings between -the boundaries will be displayed. For the sums report, hosts/clients -with a number of postings exceeding the boundaries in all (!) months -will not be considered. +means each month only hosts with a number of postings between the +boundaries will be displayed. For the sums report, hosts with a number +of postings exceeding the boundaries in all (!) months will not be +considered. =item B<-g>, B<--group-by> I @@ -349,8 +327,7 @@ ascending order, like this: individual.net : 16768 news.albasani.net: 7879 -The results can be grouped by host/client instead via -B<--group-by> I: +The results can be grouped by host instead via B<--group-by> I: ----- individual.net 2012-01: 19525 @@ -379,8 +356,8 @@ will therefore be ignored. =item B<-o>, B<--order-by> I -Within each group (a single month or single host/client, see above), -the report will be sorted by name (or month) in ascending alphabetical +Within each group (a single month or single host, see above), the +report will be sorted by host (or month) in ascending alphabetical order by default. You can change the sort order to descending or sort by number of postings instead. @@ -426,19 +403,19 @@ False by default. =item B<--comments|--nocomments> -Add comments (group headers) to I and I output. True by default -as logn as B<--filetemplate> is not set. +Add comments (group headers) to I and I output. True by +default as long as B<--filetemplate> is not set. -Use I<--nocomments> to suppress anything except host/client names or months and -numbers of postings. +Use I<--nocomments> to suppress anything except host names or months +and numbers of postings. =item B<--filetemplate> I -Save output to file(s) instead of dumping it to STDOUT. B will -create one file for each month (or each host/client, accordant to the +Save output to file(s) instead of dumping it to STDOUT. B +will create one file for each month (or each host, according to the setting of B<--group-by>, see above), with filenames composed by adding -year and month (or host/client names) to the I, for -example with B<--filetemplate> I: +year and month (or hostnames) to the I, for example +with B<--filetemplate> I: stats-2012-01 stats-2012-02 @@ -446,7 +423,7 @@ example with B<--filetemplate> I: =item B<--db> I -Override I or I from F. +Override I from F. =item B<--conffile> I @@ -462,29 +439,28 @@ See L. Show number of postings per group for lasth month in I format: - cliservstats --type host + hoststats Show that report for January of 2010 and *.inka plus individual.net: - cliservstats --type host --month 2010-01 --names *.inka:individual.net: + hoststats --month 2010-01 --names *.inka:individual.net: -Only show clients with 30 postings or less last month, ordered +Only show hosts with 30 postings or less last month, ordered by number of postings, descending, in I format: - cliservstats --type client --upper 30 --order-by postings-desc + hoststats --upper 30 --order-by postings-desc List number of postings per host for each month of 2010 and redirect output to one file for each month, named hosts-2010-01 and so on, in machine-readable form (without formatting): - cliservstats -t host -m 2010-01:2010-12 -f dump --filetemplate hosts - + hoststats -m 2010-01:2010-12 -f dump --filetemplate hosts =head1 FILES =over 4 -=item F +=item F The script itself. diff --git a/bin/postingstats.pl b/bin/postingstats.pl index fed9877..f74d89e 100644 --- a/bin/postingstats.pl +++ b/bin/postingstats.pl @@ -15,7 +15,7 @@ # # Usage: # $~ groupstats.pl --nocomments --sums --format dump | postingstats.pl -t groups -# $~ cliservstats.pl -t server --nocomments --sums --format dump | postingstats.pl -t hosts +# $~ hoststats.pl --nocomments --sums --format dump | postingstats.pl -t hosts # BEGIN { @@ -193,7 +193,7 @@ See L. =head1 DESCRIPTION This script will re-format reports on newsgroup usage created by -B or B and create a message that can +B or B and create a message that can be posted to Usenet. =head2 Features and options @@ -291,7 +291,7 @@ Create a posting from a posting statistics report for 2012-01: Create a posting from a host statistics report for last month: - cliservstats.pl -t server --nocomments --sums --format dump | postingstats.pl -t hosts + hoststats.pl --nocomments --sums --format dump | postingstats.pl -t hosts =head1 FILES @@ -334,7 +334,7 @@ groupstats -h =item - -cliservstats -h +hoststats -h =back diff --git a/contrib/dopostingstats.sh b/contrib/dopostingstats.sh index 30ef8f1..13147b2 100644 --- a/contrib/dopostingstats.sh +++ b/contrib/dopostingstats.sh @@ -2,7 +2,7 @@ # installation path is /srv/newsstats/, please adjust accordingly if [[ $1 =~ [0-9]{4}-[0-9]{2} ]]; then /srv/newsstats/bin/groupstats.pl --nocomments --sums --format dump --month $1 | /srv/newsstats/bin/postingstats.pl --month $1 | /srv/newsstats/contrib/tinews.pl -X -Y - /srv/newsstats/bin/cliservstats.pl -t server --nocomments --sums --format dump --month $1 | /srv/newsstats/bin/postingstats.pl -t server --month $1 | /srv/newsstats/contrib/tinews.pl -X -Y + /srv/newsstats/bin/hoststats.pl --nocomments --sums --format dump --month $1 | /srv/newsstats/bin/postingstats.pl -t server --month $1 | /srv/newsstats/contrib/tinews.pl -X -Y else echo 'Input error, please use dopostingstats.sh YYYY-MM' fi diff --git a/doc/ChangeLog b/doc/ChangeLog index 6792cc6..4a54296 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -5,6 +5,7 @@ NewsStats 0.4.0 (unreleased) * Improve documentation for config file. * ParseHeader: re-merge continuation lines. * Add ClientStats to gatherstats. + * Move cliservstats to hoststats. NewsStats 0.3.0 (2025-05-18) * Extract GroupStats (in gatherstats) to subroutine. diff --git a/doc/README b/doc/README index 222cdba..f6b1f44 100644 --- a/doc/README +++ b/doc/README @@ -74,8 +74,8 @@ Getting Started Report generation is handled by specialised scripts for each report type. Currently reports on the number of postings per group and month and injection server and month are supported; you can - use 'groupstats.pl' and 'cliservstats.pl' for that. See the - groupstats.pl and cliservstats.pl man pages for more information. + use 'groupstats.pl' and 'hoststats.pl' for that. See the + groupstats.pl and hoststats.pl man pages for more information. Reporting Bugs