jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [traffic/] [platform/] [linux.pm] - Blame information for rev 22

 

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 my %rrcpdev;
26 
27 foreach (keys(%args)) {
28 if ( index($_,"DEV") >= 0) {
29 ($dev,$maxin,$maxout,$description)=split /,/,$args{$_};
30 
31 if(index($dev,"SNMP\:") >= 0) {
32 (undef,$host,$community,$interface)=split /:/,$dev;
33 
34 my $max = $maxin;
35 $max = $maxout if $maxin < $maxout;
36 my @data = ( $interface, $max);
37 if (defined $snmpdev{$host."_".$community}) {
38 push @{$snmpdev{$host."_".$community}}, @data;
39 } else {
40 $snmpdev{$host."_".$community} = [ @data ] ;
41 }
42 } else {
43 if(index($dev,"RRCP\:") >= 0) {
44# print "l1 $dev\n";
45 (undef,$host,$community,$interface)=split /:/,$dev;
46 
47 $host =~ s/\./:/g;
48 my $max = $maxin;
49 $max = $maxout if $maxin < $maxout;
50 my @data = ( $interface, $max);
51 if (defined $rrcpdev{$host."_".$community}) {
52 push @{$rrcpdev{$host."_".$community}}, @data;
53# print "defined\n";
54 } else {
55 $rrcpdev{$host."_".$community} = [ @data ] ;
56# print "undefined\n";
57 }
58 } else {
59 $dev =~ s/:/_/g;
60 $maxin{$dev}=$maxin;
61 $maxout{$dev}=$maxout;
62 $devin{$dev}="U";
63 $devout{$dev}="U";
64 $sampletime{$dev}=time;
65 } # else
66 } # else
67 } # if
68 } # foreach
69 
70 open(IN,"/proc/net/dev");
71 while(<IN>) {
72 chomp;
73 if ( /:/ ) {
74 my ($combined, $a, undef, undef, undef, undef, undef, undef, $output, $e)=split;
75 ($name, $input)=split(":",$combined);
76 if(!$input) { ($input, $output) = ($a, $e); }
77 $devin{$name}=$input;
78 $devout{$name}=$output;
79 $sampletime{$name}=time;
80 }
81 }
82 close(IN);
83 
84 #
85 # then query SNMP hosts and check interfaces
86 #
87 
88 syssnmp::do_snmp(%snmpdev);
89 
90 #
91 # then query RRCP hosts and check interfaces
92 #
93 
94 sysrrcp::do_rrcp(%rrcpdev);
95 
96 foreach $name (keys %maxin) {
97 
98 # build new database if needed
99 #
100 if (! -e "rrd/$name.rrd" ) {
101 
102 # get max. transmission value
103 #
104 my $max=$maxin{$name};
105 if ($max < $maxout{$name}) { $max=$maxout{$name} };
106 
107 # if max-transmission is not set, assume 100 MBit.
108 #
109 if ($max == 0) { $max=12500000; }
110 system("./makerrd","$name","$max")
111 }
112 
113 # update database
114 RRDs::update "rrd/$name.rrd",$sampletime{$name}.":".$devin{$name}.":".$devout{$name};
115 if ($ERROR = RRDs::error) { print time,": ",$args{MODNAME},": unable to update `$name.rrd': $ERROR\n"; }
116 }
117 
118}
119 
1201;
121 

Powered by WebSVN 2.2.1