jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-jablonecka/] [modules/] [traffic/] [platform/] [linux.pm.orig] - Blame information for rev 32

 

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

Powered by WebSVN 2.2.1