2 # This is a local command to generate the various statistics that
3 # can then be displayed on an MRTG plot
5 # Your mrtg binary must live in one of the standard places
7 # The arguments (keywords) to the mrtg command are these
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
16 # pc92 - PC92 C and K, PC92 A and D
17 # all - all of the above
20 # test - do everything except check for and run mrtg
21 # nomrtg - ditto (better name)
22 # dataonly - only generate the data files for mrtg
23 # cfgonly - only generate the mrtg.cfg file (like cfgmaker)
24 # runmrtg - run mrtg, this is probably used with dataonly
25 # - together with a home rolled mrtg.cfg
27 # Copyright (c) 2002 Dirk Koopman G1TLH
34 my ($self, $line) = @_;
40 for (split /\s+/, $line) { $want{lc $_} = 1};
41 $want{nomrtg} = 1 if $want{cfgonly} || $want{test};
43 return (1, "MRTG not installed") unless $want{nomrtg} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
44 return (1, "MRTG requires top to be installed") unless $want{nomrtg} || -e '/usr/bin/top' || -e '/usr/local/bin/top';
46 my @out = do_it(%want);
56 my $mc = new Mrtg or return (1, "cannot initialise Mrtg $!");
58 # do Data in / out totals
59 my $din = $Msg::total_in;
60 my $dout = $Msg::total_out;
62 $mc->cfgprint('msg', [ qw(integer) ], 64000,
63 "Cluster Data <font color=#00cc00>in</font> and <font color=#0000ff>out</font> of $main::mycall",
64 'Bytes / Sec', 'Bytes In', 'Bytes Out') unless $want{dataonly};
65 $mc->data('msg', $din, $dout, "Data in and out of $main::mycall") unless $want{cfgonly};
66 dbg("mrtg: din: $din dout: $dout") if isdbg("mrtg");
68 # do AGW stats if they apply
70 $mc->cfgprint('agw', [], 64000,
71 "AGW Data <font color=#00cc00>in</font> and <font color=#0000ff>out</font> of $main::mycall",
72 'Bytes / Sec', 'Bytes In', 'Bytes Out') unless $want{dataonly};
73 $mc->data('agw', $AGWMsg::total_in, $AGWMsg::total_out, "AGW Data in and out of $main::mycall") unless $want{cfgonly};
74 dbg("mrtg: agwin: $AGWMsg::total_in agwout: $AGWMsg::total_out") if isdbg("mrtg");
77 if (!$main::is_win && ($want{proc} || $want{all})) {
78 my $secs = $main::clssecs + $main::cldsecs;
80 dbg "mrtg: proc: cluster=$main::clssecs children=$main::cldsecs clock=$secs" if isdbg('mrtg');
82 $mc->cfgprint('proc', [qw(unknaszero withzeroes perminute)], 600,
83 "CPU Usage of <font color=#00cc00>node</font> and its <font color=#0000ff>children</font> in seconds",
84 'CPU Secs/min', 'Node Secs 10ths', 'Child Secs 10ths', 0.1) unless $want{dataonly};
85 $mc->data('proc', int($main::clssecs*10+0.5), int($main::cldsecs*10+0.5), "Processor Usage") unless $want{cfgonly};
88 # do the users and nodes
89 my $users = DXChannel::get_all_users();
90 my $nodes = DXChannel::get_all_nodes();
92 $mc->cfgprint('users', [qw(unknaszero gauge integer)], 500,
93 "<font color=#00cc00>Users</font> and <font color=#0000ff>Nodes</font> on $main::mycall",
94 'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
95 $mc->data('users', $users, $nodes, 'Users / Nodes') unless $want{cfgonly};
96 dbg("mrtg: din: $din dout: $dout") if isdbg("mrtg");
98 # do the total users and nodes
99 if ($want{totalusers} || $want{all}) {
100 $nodes = Route::Node::count();
101 $users = Route::User::count();
102 $mc->cfgprint('totalusers', [qw(integer unknaszero gauge)], 10000,
103 'Total <font color=#00cc00>Users</font> and <font color=#0000ff>Nodes</font> in the Visible Cluster Network',
104 'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
105 $mc->data('totalusers', $users, $nodes, 'Total Users and Nodes in the Visible Cluster Network') unless $want{cfgonly};
106 dbg("mrtg: users: $users nodes: $nodes") if isdbg("mrtg");
110 if ($want{totalspots} || $want{all}) {
111 $mc->cfgprint('totalspots', [qw(integer withzeroes unknaszero noi perminute)], 1000, 'Total Spots',
112 'Spots / min', 'Spots', 'Spots') unless $want{dataonly};
113 $mc->data('totalspots', $Spot::totalspots, $Spot::totalspots, 'Total Spots') unless $want{cfgonly};
114 dbg("mrtg: total spots: $Spot::totalspots") if isdbg("mrtg");
115 #$Spot::totalspots = 0;
118 # do the HF and VHF spots
119 if ($want{hfvhf} || $want{all}) {
120 $mc->cfgprint('hfspots', [qw(integer withzeroes unknaszero perminute)], 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 dbg("mrtg: hfspots: $Spot::hfspots vhfspots: $Spot::vhfspots") if isdbg("mrtg");
124 #$Spot::hfspots = $Spot::vhfspots = 0;
128 if ($want{wwv} || $want{all}) {
129 $mc->cfgprint('wwvsfi', [qw(integer gauge)], 1000, 'WWV <font color=#00cc00>SFI</font> and <font color=#0000ff>R</font>', 'SFI / R', 'SFI', 'R') unless $want{dataonly};
130 $mc->data('wwvsfi', ($Geomag::sfi || $WCY::sfi), ($Geomag::r || $WCY::r), 'WWV SFI and R') unless $want{cfgonly};
131 $mc->cfgprint('wwvka', [qw(gauge)], 1000, 'WWV <font color=#00cc00>A</font> and <font color=#0000ff>K</font>',
132 'A / K', 'A', 'K') unless $want{dataonly};
133 $mc->data('wwvka', $Geomag::a, $Geomag::k, 'WWV A and K') unless $want{cfgonly};
134 dbg("mrtg: WWV A: $Geomag::a K: $Geomag::k") if isdbg("mrtg");
138 if ($want{wcy} || $want{all}) {
139 $mc->cfgprint('wcyka', [qw(integer gauge)], 1000, 'WCY <font color=#00cc00>A</font> and <font color=#0000ff>K</font>',
140 'A / K', 'A', 'K') unless $want{dataonly};
141 $mc->data('wcyka', $WCY::a, $WCY::k, 'WCY A and K') unless $want{cfgonly};
142 dbg("mrtg: WCY A: $WCY::a K: $WCY::k") if isdbg("mrtg");
145 if ($want{pc92} || $want{all}) {
147 $mc->cfgprint('pc92ck', [qw(integer)], 1024000,
148 "PC92 <font color=#00cc00>C</font> and <font color=#0000ff>K</font> records into $main::mycall",
149 'Bytes / Sec', 'C', 'K') unless $want{dataonly};
150 $mc->data('pc92ck', $DXProt::pc92Cin, $DXProt::pc92Kin, "PC92 C and K into $main::mycall") unless $want{cfgonly};
151 # $DXProt::pc92Cin = $DXProt::pc92Kin = 0;
153 $mc->cfgprint('pc92ad', [qw(integer)], 1024000,
154 "PC92 <font color=#00cc00>A</font> and <font color=#0000ff>D</font> records into $main::mycall",
155 'Bytes / Sec', 'A', 'D') unless $want{dataonly};
156 $mc->data('pc92ad', $DXProt::pc92Ain, $DXProt::pc92Din, "PC92 A and D into $main::mycall") unless $want{cfgonly};
157 # $DXProt::pc92Ain = $DXProt::pc92Din = 0;
158 dbg("mrtg: PC92 C: $DXProt::pc92Cin K: $DXProt::pc92Kin A: $DXProt::pc92Ain D: $DXProt::pc92Din") if isdbg("mrtg");
169 @out = $mc->run unless $want{nomrtg};