2 # This is a local command to generate the various statistics that
3 # can then be displayed on an MRTG plot
5 # Your mrtg binary must live in one of the standard places
7 # you will need perl 5.6 (probably) to be able to run this command
10 sub cfgprint($$@$$$$$);
12 my ($self, $line) = @_;
16 for (split /\s+/, $line) { $want{lc $_} = 1};
18 return (1, "MRTG not installed") unless $want{test} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
20 my $dir = "$main::root/mrtg";
21 my $html = "$main::root/html/mrtg";
22 my $cfg = "$dir/mrtg.cfg";
24 my $mc = new IO::File ">$cfg" or return(1, "cannot open $cfg for mrtg writing");
26 # print out the header
30 # to get bits instead of bytes and graphs growing to the right
31 # Options[_]: growright, bits
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 (my $m = new IO::File ">$dir/users") {
52 print $m "$users\n$nodes\n$uptime\nUsers and Nodes\n";
55 cfgprint($mc, 'users', [qw(gauge)], 500,
56 "Users and Nodes on $main::mycall",
57 'Users / Nodes', 'Users', 'Nodes');
59 # do the total users and nodes
60 if ($want{totalusers} || $want{all}) {
61 $nodes = Route::Node::count();
62 $users = Route::User::count();
63 #dbg "$users $nodes $uptime\n";
64 if (my $m = new IO::File ">$dir/totalusers") {
65 print $m "$users\n$nodes\n$uptime\nTotal Users and Nodes\n";
68 cfgprint($mc, 'totalusers', [qw(gauge)], 10000,
69 'Total Users and Nodes in the Visible Cluster Network',
70 'Users / Nodes', 'Users', 'Nodes');
74 if ($want{totalspots} || $want{all}) {
75 if (my $m = new IO::File ">$dir/totalspots") {
76 print $m "$Spot::totalspots\n$Spot::totalspots\n$uptime\nTotal Spots\n";
79 $Spot::totalspots = 0;
80 cfgprint($mc, 'totalspots', [qw(unknaszero gauge noi)], 1000, 'Total Spots',
81 'Spots', 'Spots', 'Spots');
84 # do the HF and VHF spots
85 if ($want{hfvhf} || $want{all}) {
86 if (my $m = new IO::File ">$dir/hfspots") {
87 print $m "$Spot::hfspots\n$Spot::vhfspots\n$uptime\nHF and VHF+ Spots\n";
90 $Spot::hfspots = $Spot::vhfspots = 0;
91 cfgprint($mc, 'hfspots', [qw(unknaszero gauge)], 1000, 'HF and VHF+ Spots',
92 'Spots', 'HF', 'VHF');
99 my @out = `mrtg $cfg`;
104 my ($mc, $name, $options, $max, $title, $legend, $iname, $oname) = @_;
105 my $opt = join ', ', @$options, qw(withzeroes gauge growright nopercent integer);
113 Target[$name]: `cat /spider/mrtg/$name`
114 MaxBytes[$name]: $max
117 YLegend[$name]: $legend
118 YTicsFactor[$name]: 1
119 ShortLegend[$name]: \
120 Legend1[$name]:Maximum No of $iname
121 Legend2[$name]:Maximum No of $oname
122 LegendI[$name]:$iname
123 LegendO[$name]:$oname
124 PageTop[$name]: <H1>$title</H1>
126 <TR><TD>System:</TD> <TD>$main::mycall</TD></TR>
127 <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
128 <TR><TD>Description:</TD><TD>$title</TD></TR>