jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [packets/] [platform/] [freebsd.pm] - Blame information for rev 31

 

Line No. Rev Author Line
131simandlpackage HotSaNICmod::OSdep;
2 
3use lib "../../lib";
4use RRDs;
5 
6eval { require "platform/syssnmp.pm"; };
7$NO_SNMP=1 if($@);
8 
9sub version {
10 ($VERSION = '$Revision: 1.6 $') =~ s/.*(\d+\.\d+).*/$1/;
11 return "$^O.pm $VERSION";
12 }
13 
14sub sample {
15 my %args=@_;
16 
17 my %maxin;
18 my %maxout;
19 my %devin;
20 my %devout;
21 my %sampletime;
22 my %snmpdev;
23 
24 foreach (keys(%args)) {
25 if ( index($_,"DEV") >= 0) {
26 ($dev,$maxin,$maxout,$description)=split /,/,$args{$_};
27 
28 if ( index($dev,"SNMP\:") >= 0) {
29 (undef,$host,$community,$interface)=split /:/,$dev;
30 my $max = $maxin;
31 $max = $maxout if $maxin < $maxout;
32 my @data = ( $interface, $max);
33 if (defined $snmpdev{$host."_".$community}) {
34 push @{$snmpdev{$host."_".$community}}, @data;
35 } else {
36 $snmpdev{$host."_".$community} = [ @data ] ;
37 }
38 } else {
39 $dev =~ s/:/_/g;
40 $maxin{$dev}=$maxin;
41 $maxout{$dev}=$maxout;
42 $devin{$dev}="U";
43 $devout{$dev}="U";
44 $sampletime{$dev}=time;
45 }
46 }
47 }
48 
49 open(IN,"netstat -nib | grep Link |");
50 while(<IN>) {
51 chomp;
52 @line = split;
53 $name = $line[0];
54 $input = $line[$#line-4];
55 $output= $line[$#line-1];
56 $devin{$name}=$input;
57 $devout{$name}=$output;
58 $sampletime{$name}=time;
59 }
60 close(IN);
61 
62 #
63 # then query SNMP hosts and check interfaces
64 #
65 
66 syssnmp::do_snmp(%snmpdev);
67 
68 #
69 # save data
70 #
71 foreach $name (keys %maxin) {
72 
73 # build new database if needed
74 #
75 if (! -e "rrd/$name.rrd" ) {
76 
77 # get max. transmission value
78 #
79 my $max=$maxin{$name};
80 if ($max < $maxout{$name}) { $max=$maxout{$name} };
81 
82 # if max-transmission is not set, assume 100 MBit.
83 #
84 if ($max == 0) { $max=12500000; }
85 system("./makerrd","$name","$max")
86 }
87 
88 # update database
89 RRDs::update "rrd/$name.rrd",$sampletime{$name}.":".$devin{$name}.":".$devout{$name};
90 if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
91 }
92 
93 }
94 
951;
96 

Powered by WebSVN 2.2.1