stop the Timer::handler searching its chain more than once a second
[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 # The arguments (keywords) to the mrtg command are these
8 #
9 # a) content          (you always get the node users and nodes)
10 #    totalspots       - all spots
11 #    hfvhf            - all spots split into HF and VHF
12 #    wwv              - two graphs of WWV, one SFI and R other A and K
13 #    wcy              - WCY A and K 
14 #    all              - all of the above 
15 #    
16 # b) actions          
17 #    test             - do everything except check for and run mrtg
18 #    nomrtg           - ditto (better name)
19 #    dataonly         - only generate the data files for mrtg
20 #    cfgonly          - only generate the mrtg.cfg file (like cfgmaker)
21 #    runmrtg          - run mrtg, this is probably used with dataonly
22 #                     - together with a home rolled mrtg.cfg 
23 #
24 # Copyright (c) 2002 Dirk Koopman G1TLH
25 #
26 # $Id$
27 #
28
29 my ($self, $line) = @_;
30
31 # create the arg list
32 my %want;
33 for (split /\s+/, $line) { $want{lc $_} = 1};
34 $want{nomrtg} = 1 if $want{cfgonly} || $want{test};
35                          
36 return (1, "MRTG not installed") unless $want{nomrtg} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
37
38 my $mc = new Mrtg or return (1, "cannot initialise Mrtg $!");
39                          
40 # do the users and nodes
41 my $users = DXChannel::get_all_users();
42 my $nodes = DXChannel::get_all_nodes();
43
44 $mc->cfgprint('users', [qw(gauge)], 500, 
45                  "Users and Nodes on $main::mycall",
46                  'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
47 $mc->data('users', $users, $nodes, 'Users / Nodes') unless $want{cfgonly};
48
49 # do the  total users and nodes
50 if ($want{totalusers} || $want{all}) {
51         $nodes = Route::Node::count();
52         $users = Route::User::count();
53         $mc->cfgprint('totalusers', [qw(gauge)], 10000, 
54                         'Total Users and Nodes in the Visible Cluster Network',
55                          'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
56         $mc->data('totalusers', $users, $nodes, 'Total Users and Nodes in the Visible Cluster Network') unless $want{cfgonly};
57 }
58
59 # do the total spots
60 if ($want{totalspots} || $want{all}) {
61         $mc->cfgprint('totalspots',  [qw(unknaszero gauge noi)], 1000, 'Total Spots',
62                          'Spots', 'Spots', 'Spots') unless $want{dataonly};
63         $mc->data('totalspots', $Spot::totalspots, $Spot::totalspots, 'Total Spots') unless $want{cfgonly};
64         $Spot::totalspots = 0;
65 }
66
67 # do the HF and VHF spots
68 if ($want{hfvhf} || $want{all}) {
69         $mc->cfgprint('hfspots', [qw(unknaszero gauge)], 1000, 'HF and VHF+ Spots',
70                          'Spots', 'HF', 'VHF') unless $want{dataonly};
71         $mc->data('hfspots', $Spot::hfspots, $Spot::vhfspots, 'HF and VHF+ Spots') unless $want{cfgonly};
72         $Spot::hfspots = $Spot::vhfspots = 0;
73 }
74
75 # wwv stuff
76 if ($want{wwv} || $want{all}) {
77         $mc->cfgprint('wwvsfi', [qw(gauge)], 1000, 'WWV SFI and R',
78                          'SFI / R', 'SFI', 'R') unless $want{dataonly};
79         $mc->data('wwvsfi', ($Geomag::r || $WCY::r), ($Geomag::sfi || $WCY::sfi), 'WWV SFI and R') unless $want{cfgonly};
80         $mc->cfgprint('wwvka', [qw(gauge)], 1000, 'WWV A and K',
81                          'A / K', 'A', 'K') unless $want{dataonly};
82         $mc->data('wwvka', $Geomag::a, $Geomag::k, 'WWV A and K') unless $want{cfgonly};
83 }
84
85 # WCY stuff
86 if ($want{wcy} || $want{all}) {
87         $mc->cfgprint('wcyka', [qw(gauge)], 1000, 'WCY A and K',
88                          'A / K', 'A', 'K') unless $want{dataonly};
89         $mc->data('wcyka', $WCY::a, $WCY::k, 'WCY A and K') unless $want{cfgonly};
90 }
91
92
93 # do the mrtg thing
94 #
95 my @out = $mc->run unless $want{nomrtg};
96 return (1, @out);