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