import torrus 1.0.9
[freeside.git] / torrus / bin / configinfo.in
1 #!@PERL@ -w
2 #  Copyright (C) 2002  Stanislav Sinyagin
3 #
4 #  This program is free software; you can redistribute it and/or modify
5 #  it under the terms of the GNU General Public License as published by
6 #  the Free Software Foundation; either version 2 of the License, or
7 #  (at your option) any later version.
8 #
9 #  This program is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #  GNU General Public License for more details.
13 #
14 #  You should have received a copy of the GNU General Public License
15 #  along with this program; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17
18 # $Id: configinfo.in,v 1.1 2010-12-27 00:04:03 ivan Exp $
19 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20
21 BEGIN { require '@torrus_config_pl@'; }
22
23 use strict;
24 use BerkeleyDB;
25
26 use Torrus::ConfigTree;
27 use Torrus::TimeStamp;
28 use Torrus::SiteConfig;
29 use Torrus::Log;
30
31 exit(1) if not Torrus::SiteConfig::verify();
32
33 &Torrus::DB::setSafeSignalHandlers();
34
35 Torrus::TimeStamp::init();
36
37 my @tree_names = Torrus::SiteConfig::listTreeNames();
38
39
40 printf("Torrus version %s\n", '@VERSION@');
41 printf("%s\n", DB_VERSION_STRING);
42 printf("BerkeleyDB.pm version %s\n", $BerkeleyDB::VERSION);
43 printf("\n");
44
45 printf("Datasource trees: %d\n", scalar( @tree_names ) );
46 printf("Tree names: %s\n", join(', ', @tree_names) );
47 printf("\n");
48
49 foreach my $tree ( @tree_names )
50 {
51     &Torrus::DB::checkInterrupted();
52     
53     printf("Tree: %s\n", $tree );
54
55     my $config_tree = new Torrus::ConfigTree( -TreeName => $tree );
56     if( not defined($config_tree) )
57     {
58         print("Configuration is not ready\n");
59     }
60     else
61     {
62         my $stats = {};
63         foreach my $name ( 'leaves', 'collectorLeaves', 'monitorLeaves',
64                            'holtwintersLeaves', 'subtrees',
65                            'maxSubtreePath', 'maxSubtreeSize', 'views',
66                            'monitors', 'actions', 'compiled' )
67         {
68             $stats->{$name} = 0;
69         }
70
71         collectStats( $config_tree, $stats );
72         collectOtherStats( $config_tree, $stats );
73
74         printf("Leaves: %d\n",                $stats->{'leaves'} );
75         printf("Collector leaves: %d\n",      $stats->{'collectorLeaves'} );
76         printf("Monitor leaves: %d\n",        $stats->{'monitorLeaves'} );
77         printf("Holt-Winters leaves: %d\n",   $stats->{'holtwintersLeaves'} );
78         printf("Subtrees: %d\n",              $stats->{'subtrees'} );
79         printf("Largest subtree: %s\n",       $stats->{'maxSubtreePath'} );
80         printf("Largest subtree size: %d\n",  $stats->{'maxSubtreeSize'} );
81         printf("Views: %d\n",                 $stats->{'views'} );
82         printf("Monitors: %d\n",              $stats->{'monitors'} );
83         printf("Actions: %d\n",               $stats->{'actions'} );
84         printf("Last compiled: %s\n",
85                scalar(localtime($stats->{'compiled'})));
86         printf("\n");
87     }
88 }
89
90
91 sub collectStats
92 {
93     my $config_tree = shift;
94     my $stats = shift;
95     my $token = shift;
96
97     &Torrus::DB::checkInterrupted();
98
99     if( not defined( $token ) )
100     {
101         $token = $config_tree->token('/');
102     }
103
104     my @children = $config_tree->getChildren( $token );
105
106     my $nChildren = scalar( @children );
107     if( not defined( $stats->{'maxSubtreeSize'} ) or
108         $stats->{'maxSubtreeSize'} < $nChildren )
109     {
110         $stats->{'maxSubtreeSize'} = $nChildren;
111         $stats->{'maxSubtreePath'} = $config_tree->path( $token );
112     }
113
114     foreach my $ctoken ( @children )
115     {
116         if( $config_tree->isSubtree( $ctoken ) )
117         {
118             $stats->{'subtrees'}++;
119             collectStats( $config_tree, $stats, $ctoken );
120         }
121         elsif( $config_tree->isLeaf( $ctoken ) )
122         {
123             $stats->{'leaves'}++;
124             if( $config_tree->getNodeParam( $ctoken, 'ds-type' )
125                 eq 'collector' )
126             {
127                 $stats->{'collectorLeaves'}++;
128             }
129             if( defined( $config_tree->getNodeParam( $ctoken, 'monitor' ) ) )
130             {
131                 $stats->{'monitorLeaves'}++;
132             }
133             my $val = $config_tree->getNodeParam( $ctoken, 'rrd-hwpredict' );
134             if( defined( $val ) and $val eq 'enabled' )
135             {
136                 $stats->{'holtwintersLeaves'}++;
137             }            
138         }
139     }
140 }
141
142
143 sub collectOtherStats
144 {
145     my $config_tree = shift;
146     my $stats = shift;
147
148     my $n = scalar( $config_tree->getViewNames() );
149     $stats->{'views'} = $n if defined( $n );
150
151     $n = scalar( $config_tree->getMonitorNames() );
152     $stats->{'monitors'} = $n if defined( $n );
153
154     $n = scalar( $config_tree->getActionNames() );
155     $stats->{'actions'} = $n if defined( $n );
156
157     $n = $config_tree->getTimestamp();
158     $stats->{'compiled'} = $n if defined( $n );
159 }
160
161
162 # Local Variables:
163 # mode: perl
164 # indent-tabs-mode: nil
165 # perl-indent-level: 4
166 # End: