added Mrtg.pm and WWV and WCY plots
authorminima <minima>
Thu, 26 Sep 2002 10:35:44 +0000 (10:35 +0000)
committerminima <minima>
Thu, 26 Sep 2002 10:35:44 +0000 (10:35 +0000)
Changes
cmd/mrtg.pl
perl/Mrtg.pm [new file with mode: 0644]
perl/cluster.pl

diff --git a/Changes b/Changes
index bb017b03142dbb0844d1dc6359fdf8718352d3c6..efe0bfe672936277f315d263886f4d0df4297d50 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,5 @@
+26Sep02=======================================================================
+1. added WWV and WCY to the Mrtg stats. Don't forget to do an indexmaker!
 25Sep02=======================================================================
 1. added mrtg stuff to the system as a template. In order to use this you
 must install mrtg onto your system and copy all the mrtg files (or at least
index dba856e5b4495d429e78c6750255a4a9b8d8c791..03a9edae3e393f69a0b56e20839ede2330aee576 100644 (file)
@@ -7,8 +7,6 @@
 # you will need perl 5.6 (probably) to be able to run this command
 #
 
-sub cfgprint($$@$$$$$);
-
 my ($self, $line) = @_;
 
 # create the arg list
@@ -17,42 +15,13 @@ for (split /\s+/, $line) { $want{lc $_} = 1};
                         
 return (1, "MRTG not installed") unless $want{test} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
 
-my $dir = "$main::root/mrtg";
-my $html = "$main::root/html/mrtg";
-my $cfg = "$dir/mrtg.cfg";
-
-my $mc = new IO::File ">$cfg" or return(1, "cannot open $cfg for mrtg writing");
-
-# print out the header
-print $mc <<"EOF";
-### Global Defaults
-
-#  to get bits instead of bytes and graphs growing to the right
-# Options[_]: growright, bits
-
-Htmldir: $html
-Imagedir: $html
-Logdir: $dir
-Options[_]: growright
-
-##
-##
-
-EOF
-
-
-#dbg "$dir\n$html\n";
+my $mc = new Mrtg or return (1, "cannot initialise Mrtg $!");
                         
 # do the users and nodes
 my $users = DXChannel::get_all_users();
 my $nodes = DXChannel::get_all_nodes();
-my $uptime = main::uptime();
-#dbg "$users $nodes $uptime\n";
-if (my $m = new IO::File ">$dir/users") {
-       print $m "$users\n$nodes\n$uptime\nUsers and Nodes\n";
-       close $m;
-}
-cfgprint($mc, 'users', [qw(gauge)], 500, 
+
+$mc->cfgprint('users', $users, $nodes, [qw(gauge)], 500, 
                 "Users and Nodes on $main::mycall",
                 'Users / Nodes', 'Users', 'Nodes');
 
@@ -60,73 +29,41 @@ cfgprint($mc, 'users', [qw(gauge)], 500,
 if ($want{totalusers} || $want{all}) {
        $nodes = Route::Node::count();
        $users = Route::User::count();
-       #dbg "$users $nodes $uptime\n";
-       if (my $m = new IO::File ">$dir/totalusers") {
-               print $m "$users\n$nodes\n$uptime\nTotal Users and Nodes\n";
-               close $m;
-       }
-       cfgprint($mc, 'totalusers', [qw(gauge)], 10000, 
+       $mc->cfgprint('totalusers', $users, $nodes,  [qw(gauge)], 10000, 
                        'Total Users and Nodes in the Visible Cluster Network',
                         'Users / Nodes', 'Users', 'Nodes');
 }
 
 # do the total spots
 if ($want{totalspots} || $want{all}) {
-       if (my $m = new IO::File ">$dir/totalspots") {
-               print $m "$Spot::totalspots\n$Spot::totalspots\n$uptime\nTotal Spots\n";
-               close $m;
-       }
-       $Spot::totalspots = 0;
-       cfgprint($mc, 'totalspots', [qw(unknaszero gauge noi)], 1000, 'Total Spots',
+       $mc->cfgprint('totalspots', $Spot::totalspots, $Spot::totalspots, [qw(unknaszero gauge noi)], 1000, 'Total Spots',
                         'Spots', 'Spots', 'Spots');
+       $Spot::totalspots = 0;
 }
 
 # do the HF and VHF spots
 if ($want{hfvhf} || $want{all}) {
-       if (my $m = new IO::File ">$dir/hfspots") {
-               print $m "$Spot::hfspots\n$Spot::vhfspots\n$uptime\nHF and VHF+ Spots\n";
-               close $m;
-       }
-       $Spot::hfspots = $Spot::vhfspots = 0;
-       cfgprint($mc, 'hfspots', [qw(unknaszero gauge)], 1000, 'HF and VHF+ Spots',
+       $mc->cfgprint('hfspots', $Spot::hfspots, $Spot::vhfspots, [qw(unknaszero gauge)], 1000, 'HF and VHF+ Spots',
                         'Spots', 'HF', 'VHF');
+       $Spot::hfspots = $Spot::vhfspots = 0;
+}
+
+# wwv stuff
+if ($want{wwv} || $want{all}) {
+       $mc->cfgprint('wwvsfi', $Geomag::r || $WCY::r, $Geomag::sfi || $WCY::sfi, [qw(gauge)], 1000, 'WWV SFI and R',
+                        'SFI / R', 'SFI', 'R');
+       $mc->cfgprint('wwvka', $Geomag::a, $Geomag::k, [qw(gauge)], 1000, 'WWV A and K',
+                        'A / K', 'A', 'K');
+}
+
+# WCY stuff
+if ($want{wcy} || $want{all}) {
+       $mc->cfgprint('wcyka', $WCY::a, $WCY::k, [qw(gauge)], 1000, 'WCY A and K',
+                        'A / K', 'A', 'K');
 }
 
 # 
 # do the mrtg thing
 #
-close $mc;
-my @out = `mrtg $cfg`;
+my @out = $mc->run unless $want{test};
 return (1, @out);
-
-sub cfgprint
-{
-       my ($mc, $name, $options, $max, $title, $legend, $iname, $oname) = @_;
-       my $opt = join ', ', @$options, qw(withzeroes gauge growright nopercent integer);
-               
-       print $mc <<"EOF";
-
-#
-# $title
-#
-
-Target[$name]: `cat /spider/mrtg/$name`
-MaxBytes[$name]: $max
-Title[$name]: $title
-Options[$name]: $opt
-YLegend[$name]: $legend
-YTicsFactor[$name]: 1
-ShortLegend[$name]: \&nbsp;
-Legend1[$name]:Maximum No of $iname
-Legend2[$name]:Maximum No of $oname
-LegendI[$name]:$iname
-LegendO[$name]:$oname
-PageTop[$name]: <H1>$title</H1>
- <TABLE>
-   <TR><TD>System:</TD>     <TD>$main::mycall</TD></TR>
-   <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
-   <TR><TD>Description:</TD><TD>$title</TD></TR>
- </TABLE>
-EOF
-
-}
diff --git a/perl/Mrtg.pm b/perl/Mrtg.pm
new file mode 100644 (file)
index 0000000..8a6e79e
--- /dev/null
@@ -0,0 +1,96 @@
+#
+# the MRTG handler
+#
+# Copyright (c) - 2002 Dirk Koopman G1TLH
+#
+# $Id$
+#
+
+package Mrtg;
+
+use IO::File;
+use DXVars;
+use DXDebug;
+use DXUtil;
+use strict;
+
+use vars qw($VERSION $BRANCH);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
+sub new
+{
+       my $pkg = shift;
+       my $class = ref $pkg || $pkg;
+       my %args = @_;
+       my $self = bless { }, $class;
+
+       # argument processing
+       $self->{dir} = $args{dir} || "$main::root/mrtg";
+       $self->{html} = $args{html} || "$main::root/html/mrtg";
+       $self->{cfg} = $args{cfg} || "$self->{dir}/mrtg.cfg";
+
+       my $mc = new IO::File ">$self->{cfg}" or return undef;
+       $self->{mc} = $mc;
+       
+       # print out the header
+       print $mc <<"EOF";
+### Global Defaults
+Htmldir: $self->{html}
+Imagedir: $self->{html}
+Logdir: $self->{dir}
+Options[_]: growright
+##
+##
+EOF
+
+       return $self;
+}
+
+sub run
+{
+       my $self = shift;
+       $self->{mc}->close;
+       return `mrtg $self->{cfg}`;
+}
+
+sub cfgprint
+{
+       my ($self, $name, $vali, $valo, $options, $max, $title, $legend, $iname, $oname) = @_;
+       my $opt = join ', ', @$options, qw(withzeroes gauge growright nopercent integer);
+       my $uptime = main::uptime();
+
+       if (my $m = new IO::File ">$self->{dir}/$name") {
+               $m->print("$vali\n$valo\n$uptime\n$title\n");
+               $m->close;
+       }
+               
+       $self->{mc}->print(<<"EOF");
+
+#
+# $title
+#
+
+Target[$name]: `cat /spider/mrtg/$name`
+MaxBytes[$name]: $max
+Title[$name]: $title
+Options[$name]: $opt
+YLegend[$name]: $legend
+YTicsFactor[$name]: 1
+ShortLegend[$name]: \&nbsp;
+Legend1[$name]:Maximum No of $iname
+Legend2[$name]:Maximum No of $oname
+LegendI[$name]:$iname
+LegendO[$name]:$oname
+PageTop[$name]: <H1>$title</H1>
+ <TABLE>
+   <TR><TD>System:</TD>     <TD>$main::mycall</TD></TR>
+   <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
+   <TR><TD>Description:</TD><TD>$title</TD></TR>
+ </TABLE>
+EOF
+
+}
+1;
index 888ecc2fcd37aa39036de562a7b3ed93dabac060..7a93e685955ef616aacb1ca76052b3a538ba61ef 100755 (executable)
@@ -95,6 +95,7 @@ use Route;
 use Route::Node;
 use Route::User;
 use Editable;
+use Mrtg;
 
 use Data::Dumper;
 use IO::File;
@@ -122,7 +123,7 @@ $reqreg = 0;                                        # 1 = registration required, 2 = deregister people
 use vars qw($VERSION $BRANCH $build $branch);
 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
-$main::build += 11;                            # add an offset to make it bigger than last system
+$main::build += 10;                            # add an offset to make it bigger than last system
 $main::build += $VERSION;
 $main::branch += $BRANCH;