detail
[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 # you will need perl 5.6 (probably) to be able to run this command
8 #
9
10 my ($self, $line) = @_;
11
12 # create the arg list
13 my %want;
14 for (split /\s+/, $line) { $want{lc $_} = 1};
15                          
16 return (1, "MRTG not installed") unless $want{test} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
17
18 my $mc = new Mrtg or return (1, "cannot initialise Mrtg $!");
19                          
20 # do the users and nodes
21 my $users = DXChannel::get_all_users();
22 my $nodes = DXChannel::get_all_nodes();
23
24 $mc->cfgprint('users', $users, $nodes, [qw(gauge)], 500, 
25                  "Users and Nodes on $main::mycall",
26                  'Users / Nodes', 'Users', 'Nodes');
27
28 # do the  total users and nodes
29 if ($want{totalusers} || $want{all}) {
30         $nodes = Route::Node::count();
31         $users = Route::User::count();
32         $mc->cfgprint('totalusers', $users, $nodes,  [qw(gauge)], 10000, 
33                         'Total Users and Nodes in the Visible Cluster Network',
34                          'Users / Nodes', 'Users', 'Nodes');
35 }
36
37 # do the total spots
38 if ($want{totalspots} || $want{all}) {
39         $mc->cfgprint('totalspots', $Spot::totalspots, $Spot::totalspots, [qw(unknaszero gauge noi)], 1000, 'Total Spots',
40                          'Spots', 'Spots', 'Spots');
41         $Spot::totalspots = 0;
42 }
43
44 # do the HF and VHF spots
45 if ($want{hfvhf} || $want{all}) {
46         $mc->cfgprint('hfspots', $Spot::hfspots, $Spot::vhfspots, [qw(unknaszero gauge)], 1000, 'HF and VHF+ Spots',
47                          'Spots', 'HF', 'VHF');
48         $Spot::hfspots = $Spot::vhfspots = 0;
49 }
50
51 # wwv stuff
52 if ($want{wwv} || $want{all}) {
53         $mc->cfgprint('wwvsfi', ($Geomag::r || $WCY::r), ($Geomag::sfi || $WCY::sfi), [qw(gauge)], 1000, 'WWV SFI and R',
54                          'SFI / R', 'SFI', 'R');
55         $mc->cfgprint('wwvka', $Geomag::a, $Geomag::k, [qw(gauge)], 1000, 'WWV A and K',
56                          'A / K', 'A', 'K');
57 }
58
59 # WCY stuff
60 if ($want{wcy} || $want{all}) {
61         $mc->cfgprint('wcyka', $WCY::a, $WCY::k, [qw(gauge)], 1000, 'WCY A and K',
62                          'A / K', 'A', 'K');
63 }
64
65
66 # do the mrtg thing
67 #
68 my @out = $mc->run unless $want{test};
69 return (1, @out);