Medium sized Internalization made by flattener against megalog-2018-03-12
[andk-cpan-tools.git] / munin / reportflow
blob1f6ad5e107d4b9c43e3162acc12e2d03689286e6
1 #!/usr/bin/perl
2 # Parameters understood:
4 # config (required)
5 # autoconf (optional - used by munin-config)
7 # Magic markers - optional - used by installation scripts and
8 # munin-config:
10 #%# family=auto
11 #%# capabilities=autoconf
13 use strict;
15 use Time::HiRes;
16 my $t0 = Time::HiRes::time;
18 my $mb_log = "/home/andreas/var/metabase-log/metabase.log-proc.log";
19 # 20121018T195811:INFO[13627]: Newlines written: 506, Keeping in mem records: 1000
21 my $refill_dir = "/home/andreas/var/refill-cpanstatsdb";
22 # .../2012/10/20121027T2308-24182412-24182626.json.gz => 215 records
24 use constant DEBUG => 1;
26 if ($ARGV[0] eq "autoconf"){
27 if ( -e $mb_log
29 print "yes\n";
30 exit 0;
31 } else {
32 print "no\n";
33 exit 1;
37 if ( $ARGV[0] eq "config" ){
38 print <<EOF;
39 graph_title reports this month
40 graph_args -r
41 graph_vlabel total reports
42 graph_scale yes
43 graph_info Show number of reports via mb (log.txt,David Golden,amazon) vs refill (cpantesters,Barbie,CPAN::Testers::WWW::Reports::Query::Reports)
44 graph_category cpantesters
45 EOF
47 for my $c ("mb","refill"){
48 #my $draw = "??/";
49 print <<EOF;
50 rf$c.label $c
51 rf$c.min 0
52 rf$c.type GAUGE
53 EOF
55 exit 0;
59 use Fcntl ":seek";
60 my $t = int time;
61 my($mb_cnt,$refill_cnt) = (0,0);
62 my @time = gmtime($t);
63 $time[4]++;
64 $time[5]+=1900;
65 my $stamp_s = sprintf "%04d%02d%02dT%02d%02d%02d", @time[5,4,3,2,1,0];
66 my $stamp_month = substr($stamp_s,0,6);
67 for my $suffix (".1","") {
68 if (open my $fh, "$mb_log$suffix") {
69 while (<$fh>) {
70 next unless /^(\d{8}T\d{6}):INFO\[\d+\]: Newlines written:\s(\d+),/;
71 my($tstamp,$tcnt) = ($1,$2);
72 last if $tstamp gt $stamp_s;
73 next if $tstamp lt $stamp_month;
74 next unless $tcnt;
75 $mb_cnt+=$tcnt;
77 } else {
78 # expected during logrotate (which in turn is expected to be done manually)
79 warn "Could not open '$mb_log$suffix'\: $!";
82 opendir my $dh, $refill_dir or die "Could not opendir $refill_dir\: $!";
83 for my $y (sort readdir $dh) {
84 next unless $y =~ /^(\d{4})$/;
85 last if $y gt $stamp_s;
86 next if $y lt substr($stamp_s,0,4);
87 opendir my $dh2, "$refill_dir/$y" or die "Could not opendir $refill_dir/$y\: $!";
88 for my $m (sort readdir $dh2) {
89 next unless $m =~ /^(\d{2})$/;
90 last if "$y$m" gt $stamp_s;
91 next if "$y$m" lt substr($stamp_s,0,6);
92 opendir my $dh3, "$refill_dir/$y/$m" or die "Could not opendir $refill_dir/$y/$m\: $!";
93 for my $logfile (sort readdir $dh3) {
94 next unless $logfile =~ /(\d{8}T\d{4})-(\d+)-(\d+)\.json\.gz$/;
95 my($tstamp,$tstart,$tend) = ($1,$2,$3);
96 last if $tstamp gt $stamp_s;
97 my $tcnt = $tend - $tstart + 1;
98 $refill_cnt+=$tcnt;
102 if (DEBUG) {
103 if (open my $fh, ">>", "/var/log/munin.munin/reportflow-debug.log") {
104 printf {$fh} "%s rfmb.value %d rfrefill.value %d took %.4f\n",
105 $stamp_s, $mb_cnt, $refill_cnt, Time::HiRes::time-$t0;
106 } else {
107 warn "Could not open '/var/log/munin.munin/reportflow-debug.log': $! (running with EUID $>)";
110 printf "rfmb.value %d\n", $mb_cnt;
111 printf "rfrefill.value %d\n", $refill_cnt;
114 # Local Variables:
115 # mode: cperl
116 # cperl-indent-level: 4
117 # indent-tabs-mode: nil
118 # End:
119 # vim:sw=4:ts=8:sta:et