From: minima Date: Thu, 26 Sep 2002 10:35:44 +0000 (+0000) Subject: added Mrtg.pm and WWV and WCY plots X-Git-Tag: PRE-1-52~192 X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=f560010fd287184ea755233f751adba83defccaa;p=spider.git added Mrtg.pm and WWV and WCY plots --- diff --git a/Changes b/Changes index bb017b03..efe0bfe6 100644 --- 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 diff --git a/cmd/mrtg.pl b/cmd/mrtg.pl index dba856e5..03a9edae 100644 --- a/cmd/mrtg.pl +++ b/cmd/mrtg.pl @@ -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]: \  -Legend1[$name]:Maximum No of $iname -Legend2[$name]:Maximum No of $oname -LegendI[$name]:$iname -LegendO[$name]:$oname -PageTop[$name]:

$title

- - - - -
System: $main::mycall
Maintainer: $main::myemail
Description:$title
-EOF - -} diff --git a/perl/Mrtg.pm b/perl/Mrtg.pm new file mode 100644 index 00000000..8a6e79ed --- /dev/null +++ b/perl/Mrtg.pm @@ -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]: \  +Legend1[$name]:Maximum No of $iname +Legend2[$name]:Maximum No of $oname +LegendI[$name]:$iname +LegendO[$name]:$oname +PageTop[$name]:

$title

+ + + + +
System: $main::mycall
Maintainer: $main::myemail
Description:$title
+EOF + +} +1; diff --git a/perl/cluster.pl b/perl/cluster.pl index 888ecc2f..7a93e685 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -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;