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
31 use Time::HiRes qw( clock_gettime CLOCK_PROCESS_CPUTIME_ID );
35 my ($self, $line) = @_;
41 for (split /\s+/, $line) { $want{lc $_} = 1};
42 $want{nomrtg} = 1 if $want{cfgonly} || $want{test};
44 return (1, "MRTG not installed") unless $want{nomrtg} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
45 return (1, "MRTG requires top to be installed") unless $want{nomrtg} || -e '/usr/bin/top' || -e '/usr/local/bin/top';
47 my @out = do_it(%want);
57 my $mc = new Mrtg or return (1, "cannot initialise Mrtg $!");
59 # do Data in / out totals
60 my $din = $Msg::total_in;
61 my $dout = $Msg::total_out;
63 $mc->cfgprint('msg', [ qw(integer) ], 64000,
64 "Cluster Data <font color=#00cc00>in</font> and <font color=#0000ff>out</font> of $main::mycall",
65 'Bytes / Sec', 'Bytes In', 'Bytes Out') unless $want{dataonly};
66 $mc->data('msg', $din, $dout, "Data in and out of $main::mycall") unless $want{cfgonly};
67 dbg("mrtg: din: $din dout: $dout") if isdbg("mrtg");
69 # do AGW stats if they apply
71 $mc->cfgprint('agw', [], 64000,
72 "AGW Data <font color=#00cc00>in</font> and <font color=#0000ff>out</font> of $main::mycall",
73 'Bytes / Sec', 'Bytes In', 'Bytes Out') unless $want{dataonly};
74 $mc->data('agw', $AGWMsg::total_in, $AGWMsg::total_out, "AGW Data in and out of $main::mycall") unless $want{cfgonly};
75 dbg("mrtg: agwin: $AGWMsg::total_in agwout: $AGWMsg::total_out") if isdbg("mrtg");
78 if (!$main::is_win && ($want{proc} || $want{all})) {
82 $secs = clock_gettime(CLOCK_PROCESS_CPUTIME_ID);
84 $mc->cfgprint('proc', [qw(noi unknaszero withzeroes perminute)], 5*60,
86 'Proc Secs/Min', 'Proc Secs', 'Proc Secs') unless $want{dataonly};
87 $mc->data('proc', $secs, $secs, "Processor Usage") unless $want{cfgonly};
90 # do the users and nodes
91 my $users = DXChannel::get_all_users();
92 my $nodes = DXChannel::get_all_nodes();
94 $mc->cfgprint('users', [qw(unknaszero gauge integer)], 500,
95 "<font color=#00cc00>Users</font> and <font color=#0000ff>Nodes</font> on $main::mycall",
96 'Users / Nodes', 'Users', 'Nodes') unless $want{dataonly};
97 $mc->data('users', $users, $nodes, 'Users / Nodes') unless $want{cfgonly};
98 dbg("mrtg: din: $din dout: $dout") if isdbg("mrtg");
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(integer 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 dbg("mrtg: users: $users nodes: $nodes") if isdbg("mrtg");
112 if ($want{totalspots} || $want{all}) {
113 $mc->cfgprint('totalspots', [qw(integer withzeroes unknaszero noi perminute)], 1000, 'Total Spots',
114 'Spots / min', 'Spots', 'Spots') unless $want{dataonly};
115 $mc->data('totalspots', $Spot::totalspots, $Spot::totalspots, 'Total Spots') unless $want{cfgonly};
116 dbg("mrtg: total spots: $Spot::totalspots") if isdbg("mrtg");
117 #$Spot::totalspots = 0;
120 # do the HF and VHF spots
121 if ($want{hfvhf} || $want{all}) {
122 $mc->cfgprint('hfspots', [qw(integer withzeroes unknaszero perminute)], 1000, '<font color=#00cc00>HF</font> and <font color=#0000ff>VHF+</font> Spots',
123 'Spots / min', 'HF', 'VHF') unless $want{dataonly};
124 $mc->data('hfspots', $Spot::hfspots, $Spot::vhfspots, 'HF and VHF+ Spots') unless $want{cfgonly};
125 dbg("mrtg: hfspots: $Spot::hfspots vhfspots: $Spot::vhfspots") if isdbg("mrtg");
126 #$Spot::hfspots = $Spot::vhfspots = 0;
130 if ($want{wwv} || $want{all}) {
131 $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};
132 $mc->data('wwvsfi', ($Geomag::sfi || $WCY::sfi), ($Geomag::r || $WCY::r), 'WWV SFI and R') unless $want{cfgonly};
133 $mc->cfgprint('wwvka', [qw(gauge)], 1000, 'WWV <font color=#00cc00>A</font> and <font color=#0000ff>K</font>',
134 'A / K', 'A', 'K') unless $want{dataonly};
135 $mc->data('wwvka', $Geomag::a, $Geomag::k, 'WWV A and K') unless $want{cfgonly};
136 dbg("mrtg: WWV A: $Geomag::a K: $Geomag::k") if isdbg("mrtg");
140 if ($want{wcy} || $want{all}) {
141 $mc->cfgprint('wcyka', [qw(integer gauge)], 1000, 'WCY <font color=#00cc00>A</font> and <font color=#0000ff>K</font>',
142 'A / K', 'A', 'K') unless $want{dataonly};
143 $mc->data('wcyka', $WCY::a, $WCY::k, 'WCY A and K') unless $want{cfgonly};
144 dbg("mrtg: WCY A: $WCY::a K: $WCY::k") if isdbg("mrtg");
147 if ($want{pc92} || $want{all}) {
149 $mc->cfgprint('pc92ck', [qw(integer)], 1024000,
150 "PC92 <font color=#00cc00>C</font> and <font color=#0000ff>K</font> records into $main::mycall",
151 'Bytes / Sec', 'C', 'K') unless $want{dataonly};
152 $mc->data('pc92ck', $DXProt::pc92Cin, $DXProt::pc92Kin, "PC92 C and K into $main::mycall") unless $want{cfgonly};
153 # $DXProt::pc92Cin = $DXProt::pc92Kin = 0;
155 $mc->cfgprint('pc92ad', [qw(integer)], 1024000,
156 "PC92 <font color=#00cc00>A</font> and <font color=#0000ff>D</font> records into $main::mycall",
157 'Bytes / Sec', 'A', 'D') unless $want{dataonly};
158 $mc->data('pc92ad', $DXProt::pc92Ain, $DXProt::pc92Din, "PC92 A and D into $main::mycall") unless $want{cfgonly};
159 # $DXProt::pc92Ain = $DXProt::pc92Din = 0;
160 dbg("mrtg: PC92 C: $DXProt::pc92Cin K: $DXProt::pc92Kin A: $DXProt::pc92Ain D: $DXProt::pc92Din") if isdbg("mrtg");
171 @out = $mc->run unless $want{nomrtg};