change legend on data to bytes
[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 #    agw              - include the AGW stats separately 
11 #    totalspots       - all spots
12 #    hfvhf            - all spots split into HF and VHF
13 #    wwv              - two graphs of WWV, one SFI and R other A and K
14 #    wcy              - WCY A and K 
15 #    all              - all of the above 
16 #    
17 # b) actions          
18 #    test             - do everything except check for and run mrtg
19 #    nomrtg           - ditto (better name)
20 #    dataonly         - only generate the data files for mrtg
21 #    cfgonly          - only generate the mrtg.cfg file (like cfgmaker)
22 #    runmrtg          - run mrtg, this is probably used with dataonly
23 #                     - together with a home rolled mrtg.cfg 
24 #
25 # Copyright (c) 2002 Dirk Koopman G1TLH
26 #
27 # $Id$
28 #
29
30 my ($self, $line) = @_;
31
32 # create the arg list
33 my %want;
34 for (split /\s+/, $line) { $want{lc $_} = 1};
35 $want{nomrtg} = 1 if $want{cfgonly} || $want{test};
36                          
37 return (1, "MRTG not installed") unless $want{nomrtg} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
38
39 my $mc = new Mrtg or return (1, "cannot initialise Mrtg $!");
40
41 # do Data in / out totals
42 my $din = $Msg::total_in;
43 my $dout = $Msg::total_in;
44 unless ($want{agw}) {
45         $din += $AGWMsg::total_in;
46         $dout += $AGWMsg::total_out;
47 }
48
49 $mc->cfgprint('msg', [], 64000, 
50                  "Data <font color=#00cc00>in</font> and <font color=#0000ff>out</font> of $main::mycall",
51                  'Bytes / Sec', 'Bytes In', 'Bytes Out') unless $want{dataonly};
52 $mc->data('msg', $din, $dout, "Data in and out of $main::mycall") unless $want{cfgonly};
53
54 # do AGW stats if they apply
55 if ($want{agw}) {
56         $mc->cfgprint('agw', [], 64000, 
57                                   "AGW Data <font color=#00cc00>in</font> and <font color=#0000ff>out</font> of $main::mycall",
58                                   'Bytes / Sec', 'Bytes In', 'Bytes Out') unless $want{dataonly};
59         $mc->data('agw', $AGWMsg::total_in, $AGWMsg::total_out, "AGW Data in and out of $main::mycall") unless $want{cfgonly};
60 }
61                          
62 # do the users and nodes
63 my $users = DXChannel::get_all_users();
64 my $nodes = DXChannel::get_all_nodes();
65
66 $mc->cfgprint('users', [qw(unknaszero gauge)], 500, 
67                  "<font color=#00cc00>Users</font> and <font color=#0000ff>Nodes</font> on $main::mycall",
68                  'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
69 $mc->data('users', $users, $nodes, 'Users / Nodes') unless $want{cfgonly};
70
71 # do the  total users and nodes
72 if ($want{totalusers} || $want{all}) {
73         $nodes = Route::Node::count();
74         $users = Route::User::count();
75         $mc->cfgprint('totalusers', [qw(unknaszero gauge)], 10000, 
76                         'Total <font color=#00cc00>Users</font> and <font color=#0000ff>Nodes</font> in the Visible Cluster Network',
77                          'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
78         $mc->data('totalusers', $users, $nodes, 'Total Users and Nodes in the Visible Cluster Network') unless $want{cfgonly};
79 }
80
81 # do the total spots
82 if ($want{totalspots} || $want{all}) {
83         $mc->cfgprint('totalspots',  [qw(unknaszero gauge noi)], 1000, 'Total Spots',
84                          'Spots', 'Spots', 'Spots') unless $want{dataonly};
85         $mc->data('totalspots', $Spot::totalspots, $Spot::totalspots, 'Total Spots') unless $want{cfgonly};
86         $Spot::totalspots = 0;
87 }
88
89 # do the HF and VHF spots
90 if ($want{hfvhf} || $want{all}) {
91         $mc->cfgprint('hfspots', [qw(unknaszero gauge)], 1000, '<font color=#00cc00>HF</font> and <font color=#0000ff>VHF+</font> Spots',
92                          'Spots', 'HF', 'VHF') unless $want{dataonly};
93         $mc->data('hfspots', $Spot::hfspots, $Spot::vhfspots, 'HF and VHF+ Spots') unless $want{cfgonly};
94         $Spot::hfspots = $Spot::vhfspots = 0;
95 }
96
97 # wwv stuff
98 if ($want{wwv} || $want{all}) {
99         $mc->cfgprint('wwvsfi', [qw(gauge)], 1000, 'WWV <font color=#00cc00>SFI</font> and <font color=#0000ff>R</font>', 'SFI / R', 'SFI', 'R') unless $want{dataonly};
100         $mc->data('wwvsfi', ($Geomag::r || $WCY::r), ($Geomag::sfi || $WCY::sfi), 'WWV SFI and R') unless $want{cfgonly};
101         $mc->cfgprint('wwvka', [qw(gauge)], 1000, 'WWV <font color=#00cc00>A</font> and <font color=#0000ff>K</font>',
102                          'A / K', 'A', 'K') unless $want{dataonly};
103         $mc->data('wwvka', $Geomag::a, $Geomag::k, 'WWV A and K') unless $want{cfgonly};
104 }
105
106 # WCY stuff
107 if ($want{wcy} || $want{all}) {
108         $mc->cfgprint('wcyka', [qw(gauge)], 1000, 'WCY <font color=#00cc00>A</font> and <font color=#0000ff>K</font>',
109                          'A / K', 'A', 'K') unless $want{dataonly};
110         $mc->data('wcyka', $WCY::a, $WCY::k, 'WCY A and K') unless $want{cfgonly};
111 }
112
113
114 # do the mrtg thing
115 #
116 my @out = $mc->run unless $want{nomrtg};
117 return (1, @out);