File: backlogstat.in

package info (click to toggle)
inn2 2.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,720 kB
  • ctags: 8,983
  • sloc: ansic: 92,499; sh: 13,509; perl: 12,921; makefile: 2,985; yacc: 842; python: 342; lex: 255
file content (118 lines) | stat: -rw-r--r-- 2,889 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#! /usr/bin/perl -w
# fixscript will replace this line with code to load INN::Config

# backlogstat - display backlog to sites
# based on bklog by bill davidsen <davidsen@tmr.com>

# breaks if backlog-directory in innfeed.conf is not "innfeed"
my $dir = "$INN::Config::pathspool/innfeed";
my $Revision = '1.8';

use strict;
use warnings;

use Getopt::Std;
use vars qw($opt_H $opt_h $opt_n $opt_t $opt_k $opt_S $opt_d);
$| = 1;

# option processing
&getopts('HhntkS:d:') || &Usage;
&Usage if $opt_h;

# open the directory;
$dir = $opt_d if $opt_d;
print "$opt_d\n";
chdir($dir) or die "Can't cd to $dir";
opendir(DIR, ".") or die "Can't open dir";

my %nodes;
while (my $name = readdir(DIR)) {
	# must be a file, correct name, non-zero size
	my $size;
	next unless -f $name;
	next unless ($size = -s $name);
	next unless $name =~ m/.*\.(in|out)put/;
	my $io = $1;
	(my $nodename = $name) =~ s/\..*//;

	# check for only some sites wanted
	next if ($opt_S && $nodename !~ /^${opt_S}.*/);
	# here we do the counts if asked
	if ($opt_n) {
		# open the file and count lines
		if (open(IN, "<$name")) {
			if ($name =~ m/.*\.input/) {
				my $offset = <IN> + 0;
				seek(IN, $offset, 0);
			}
			$size = 0;
			for ($size = 0; <IN> ; ++$size) {};
			close IN;
		}
	} else {
		# get the offset on .input files
		if ($name =~ m/.*\.input/ && open(IN, "<$name")) {
			my $offset = <IN> + 0;
			$size -= $offset;
			close IN;
		}
	}			
	$nodes{$nodename} = () unless defined $nodes{$nodename};
	$nodes{$nodename}->{$io} = ( $opt_k ? $size / 1024 : $size );
}
closedir DIR;

# output the data for each node
if (my $numnodes = keys %nodes) {
	if ($opt_H) {
		if ($opt_n) {
			print "  <---------- posts ----------->\n";
		} else {
			print "  <---------- bytes ----------->\n";
		}
	}
	my $ofmt;
	if ($opt_k) {
		print "  input(k)  output(k)   total(k) Feed Name\n" if $opt_H;
		$ofmt = ( $opt_n ? "%10.2f" : "%10.1f" );
	} else {
		print "     input     output      total Feed Name\n" if $opt_H;
		$ofmt = "%10d";
	}
	for my $node (sort keys %nodes) {
		my $hash = $nodes{$node};
		my $size_in = $hash->{in} || 0;
		my $size_out = $hash->{out} || 0;
		my $size_tot = $size_in + $size_out;
		printf "${ofmt} ${ofmt} ${ofmt} %s\n",
			$size_in, $size_out, $size_tot, $node;
	}
} else {
	print "NO backlog!\n";
}

exit 0;

sub Usage
{
	print "\n"
	. "bklog - print innfeed backlog info - v$Revision\n"
	. "\n"
	. "Format:\n"
	. "  bklog [ options ]\n"
	. "\n"
	. "Options:\n"
	. "  -H     output a header at the top of the output\n"
	. "  -k     scale all numbers in k (1024) units\n"
	. "  -n     count number of arts, not bytes of backlog filesize\n"
	. "         Note: this may be SLOW for large files!\n"
	. "  -Sxx   Display only site names starting with xx\n"
	. "  -d dir Use \"dir\" instead of \$pathspool/innfeed\n"
	. "\n"
	. "  -h     HELP - this is all, you got it!\n"
	. "\n";

	exit 1;
}