added mrtg stuff
[spider.git] / cmd / mrtg.pl
1 #
2 # This is a local command to generate the various statistics that
3 # can then be displayed on an MRTG plot
4 #
5 # Your mrtg binary must live in one of the standard places
6 #
7 my ($self, $line) = @_;
8
9 return (1) unless -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
10
11 my $dir = "$main::root/mrtg";
12 my $html = "$main::root/html/mrtg";
13 my $cfg = "$dir/mrtg.cfg";
14
15 # do some checking
16 return (1, "$dir is missing") unless -d $dir;
17 return (1, "$html is missing") unless -d $html; 
18 return (1, "$cfg is missing") unless -e "$cfg";
19 open MC, ">$cfg" or return(1, "cannot open $cfg for mrtg writing");
20
21 # print out the header
22 print MC <<"EOF";
23 ### Global Defaults
24
25 #  to get bits instead of bytes and graphs growing to the right
26 # Options[_]: growright, bits
27
28 Htmldir: $html
29 Imagedir: $html
30 Logdir: $dir
31 Options[_]: growright
32
33 ##
34 ##
35
36 EOF
37
38 # create the arg list
39 my %want;
40 for ( split /\s+/, $line) {
41         $want{lc $_} = 1;
42 }; 
43
44 #dbg "$dir\n$html\n";
45
46 # do the users and nodes
47 my $users = DXChannel::get_all_users();
48 my $nodes = DXChannel::get_all_nodes();
49 my $uptime = main::uptime();
50 #dbg "$users $nodes $uptime\n";
51 if (open M, ">$dir/users") {
52         print M "$users\n$nodes\n$uptime\nUsers and Nodes\n";
53         close M;
54 }
55 print MC <<"EOF";
56 #
57 # local users and nodes
58 #
59 Target[users]: `cat /spider/mrtg/users`
60 MaxBytes1[users]: 500
61 MaxBytes2[users]: 200
62 Title[users]: Users and Nodes for $main::mycall
63 Options[users]: withzeroes, gauge, growright, nopercent, integer
64 YLegend[users]: Users \&amp; Nodes
65 YTicsFactor[users]: 1
66 ShortLegend[users]: \&nbsp;
67 Legend1[users]:Maximum No of Users
68 Legend2[users]:Maximum No of Nodes
69 LegendI[users]:Users
70 LegendO[users]:Nodes
71 PageTop[users]: <H1>Users and Nodes on GB7DJK</H1>
72  <TABLE>
73    <TR><TD>System:</TD>     <TD>$main::mycall</TD></TR>
74    <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
75    <TR><TD>Description:</TD><TD>Users \&amp; Nodes </TD></TR>
76  </TABLE>
77 EOF
78
79 # do the  total users and nodes
80 if ($want{totalusers} || $want{all}) {
81         $nodes = Route::Node::count();
82         $users = Route::User::count();
83         #dbg "$users $nodes $uptime\n";
84         if (open M, ">$dir/totalusers") {
85                 print M "$users\n$nodes\n$uptime\nTotal Users and Nodes\n";
86                 close M;
87         }
88         print MC <<"EOF";
89 #
90 # total users and nodes
91 #
92 Target[totalusers]: `cat /spider/mrtg/totalusers`
93 MaxBytes1[totalusers]: 5000
94 MaxBytes2[totalusers]: 5000
95 Title[totalusers]: Total Users and Nodes for the Visible Cluster Network
96 Options[totalusers]: withzeroes,  gauge, growright, nopercent, integer
97 YLegend[totalusers]: Users \&amp; Nodes
98 YTicsFactor[totalusers]: 1
99 ShortLegend[totalusers]: \&nbsp;
100 Legend1[totalusers]:Maximum No of Users
101 Legend2[totalusers]:Maximum No of Nodes
102 LegendI[totalusers]:Users
103 LegendO[totalusers]:Nodes
104 PageTop[totalusers]: <H1>Total Users and Nodes in the Visible Network</H1>
105  <TABLE>
106    <TR><TD>System:</TD>     <TD>$main::mycall</TD></TR>
107    <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
108    <TR><TD>Description:</TD><TD>Total Users \&amp; Nodes for the Visible Cluster Network </TD></TR>
109  </TABLE>
110 EOF
111 }
112
113 # do the total spots
114 if ($want{totalspots} || $want{all}) {
115         if (open M, ">$dir/totalspots") {
116                 print M "$Spot::totalspots\n$Spot::totalspots\n$uptime\nTotal Spots\n";
117                 close M;
118         }
119         $Spot::totalspots = 0;
120         print MC <<"EOF";
121 #
122 # total spots
123 #
124 Target[totalspots]: `cat /spider/mrtg/totalspots`
125 MaxBytes[totalspots]: 20000
126 Title[totalspots]: Total Spots
127 Options[totalspots]: unknaszero, gauge, withzeroes, growright, nopercent, integer, noi
128 YLegend[totalspots]: Spots
129 YTicsFactor[totalspots]: 1
130 ShortLegend[totalspots]: \&nbsp;
131 Legend2[totalspots]:Maximum No of Spots
132 LegendO[totalspots]:Spots
133 PageTop[totalspots]: <H1>Total Spots</H1>
134  <TABLE>
135    <TR><TD>System:</TD>     <TD>$main::mycall</TD></TR>
136    <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
137    <TR><TD>Description:</TD><TD>Total Spots</TD></TR>
138  </TABLE>
139 EOF
140 }
141
142 # do the HF and VHF spots
143 if ($want{hfvhf} || $want{all}) {
144         if (open M, ">$dir/hfspots") {
145                 print M "$Spot::hfspots\n$Spot::vhfspots\n$uptime\nHF and VHF+ Spots\n";
146                 close M;
147         }
148         $Spot::hfspots = $Spot::vhfspots = 0;
149         print MC <<"EOF";
150
151 # HF and VHF spots
152 #
153 Target[hfspots]: `cat /spider/mrtg/hfspots`
154 MaxBytes[hfspots]: 20000
155 Title[hfspots]: HF and VHF+ Spots
156 Options[hfspots]: unknaszero, gauge, withzeroes, growright, nopercent, integer
157 YLegend[hfspots]: Spots
158 WithPeak[hfspots]: ymwd
159 YTicsFactor[hfspots]: 1
160 ShortLegend[hfspots]: \&nbsp;
161 Legend1[hfspots]:Max no of HF Spots
162 Legend2[hfspots]:Max no of VHF Spots
163 LegendI[hfspots]:HF
164 LegendO[hfspots]:VHF+
165 PageTop[hfspots]: <H1>Total HF and VHF+ Spots</H1>
166  <TABLE>
167    <TR><TD>System:</TD>     <TD>$main::mycall</TD></TR>
168    <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
169    <TR><TD>Description:</TD><TD>Total HF and VHF+ Spots</TD></TR>
170  </TABLE>
171 EOF
172 }
173
174 close MC;
175
176 my @args;
177 @args = ("mrtg", $cfg);
178 system @args;
179
180 return (1);