add in and out stats for data into the cluster
[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 Msg totals
41 $mc->cfgprint('msg', [], 64000, 
42                  "Data in and out of $main::mycall",
43                  'Bits / Sec', 'Bytes In', 'Bytes Out') unless $want{dataonly};
44 $mc->data('msg', $Msg::total_in, $Msg::total_out, "Data in and out of $main::mycall") unless $want{cfgonly};
45
46 # do AGW stats if they apply
47 if ($want{agw}) {
48         $mc->cfgprint('agw', [], 64000, 
49                                   "AGW Data in and out of $main::mycall",
50                                   'Bits / Sec', 'Bytes In', 'Bytes Out') unless $want{dataonly};
51         $mc->data('agw', $AGWMsg::total_in, $AGWMsg::total_out, "AGW Data in and out of $main::mycall") unless $want{cfgonly};
52 }
53                          
54 # do the users and nodes
55 my $users = DXChannel::get_all_users();
56 my $nodes = DXChannel::get_all_nodes();
57
58 $mc->cfgprint('users', [qw(unknaszero gauge)], 500, 
59                  "Users and Nodes on $main::mycall",
60                  'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
61 $mc->data('users', $users, $nodes, 'Users / Nodes') unless $want{cfgonly};
62
63 # do the  total users and nodes
64 if ($want{totalusers} || $want{all}) {
65         $nodes = Route::Node::count();
66         $users = Route::User::count();
67         $mc->cfgprint('totalusers', [qw(unknaszero gauge)], 10000, 
68                         'Total Users and Nodes in the Visible Cluster Network',
69                          'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
70         $mc->data('totalusers', $users, $nodes, 'Total Users and Nodes in the Visible Cluster Network') unless $want{cfgonly};
71 }
72
73 # do the total spots
74 if ($want{totalspots} || $want{all}) {
75         $mc->cfgprint('totalspots',  [qw(unknaszero gauge noi)], 1000, 'Total Spots',
76                          'Spots', 'Spots', 'Spots') unless $want{dataonly};
77         $mc->data('totalspots', $Spot::totalspots, $Spot::totalspots, 'Total Spots') unless $want{cfgonly};
78         $Spot::totalspots = 0;
79 }
80
81 # do the HF and VHF spots
82 if ($want{hfvhf} || $want{all}) {
83         $mc->cfgprint('hfspots', [qw(unknaszero gauge)], 1000, 'HF and VHF+ Spots',
84                          'Spots', 'HF', 'VHF') unless $want{dataonly};
85         $mc->data('hfspots', $Spot::hfspots, $Spot::vhfspots, 'HF and VHF+ Spots') unless $want{cfgonly};
86         $Spot::hfspots = $Spot::vhfspots = 0;
87 }
88
89 # wwv stuff
90 if ($want{wwv} || $want{all}) {
91         $mc->cfgprint('wwvsfi', [qw(gauge)], 1000, 'WWV SFI and R',
92                          'SFI / R', 'SFI', 'R') unless $want{dataonly};
93         $mc->data('wwvsfi', ($Geomag::r || $WCY::r), ($Geomag::sfi || $WCY::sfi), 'WWV SFI and R') unless $want{cfgonly};
94         $mc->cfgprint('wwvka', [qw(gauge)], 1000, 'WWV A and K',
95                          'A / K', 'A', 'K') unless $want{dataonly};
96         $mc->data('wwvka', $Geomag::a, $Geomag::k, 'WWV A and K') unless $want{cfgonly};
97 }
98
99 # WCY stuff
100 if ($want{wcy} || $want{all}) {
101         $mc->cfgprint('wcyka', [qw(gauge)], 1000, 'WCY A and K',
102                          'A / K', 'A', 'K') unless $want{dataonly};
103         $mc->data('wcyka', $WCY::a, $WCY::k, 'WCY A and K') unless $want{cfgonly};
104 }
105
106
107 # do the mrtg thing
108 #
109 my @out = $mc->run unless $want{nomrtg};
110 return (1, @out);