1 | 1 | simandl | package HotSaNICmod::OSdep; |
2 | | | |
3 | | | sub version { |
4 | | | ($VERSION = '$Revision: 1.14 $') =~ s/.*(\d+\.\d+).*/$1/; |
5 | | | return "$^O.pm $VERSION"; |
6 | | | } |
7 | | | |
8 | | | sub sample { |
9 | | | my %args=@_; |
10 | | | |
11 | | | my %DEVS; |
12 | | | foreach (@{$args{DEV}}) { |
13 | | | my ($device,$name)=split /,/; |
14 | | | $name =~ s/\//_/g; |
15 | | | $name =~ s/^_//g; |
16 | | | $DEVS{$device}=$name; |
17 | | | } |
18 | | | |
19 | | | ###################################################################### |
20 | | | # |
21 | | | # KERNEL 2.2 CODE |
22 | | | # |
23 | | | if ($args{KERNEL} eq "2.2") { |
24 | | | # disk 1494755 377215 221577 144318 |
25 | | | # disk_rio 564538 286941 151189 77490 |
26 | | | # disk_wio 930217 90274 70388 66828 |
27 | | | # disk_rblk 1129538 573882 302378 154980 |
28 | | | # disk_wblk 1860536 180548 140776 133656 |
29 | | | open FILE,"/proc/stat"; |
30 | | | while (<FILE>) { |
31 | | | (undef,@readacc)=split if /disk_rio/; |
32 | | | (undef,@writeacc)=split if /disk_wio/; |
33 | | | (undef,@readblk)=split if /disk_rblk/; |
34 | | | (undef,@writeblk)=split if /disk_wblk/; |
35 | | | } |
36 | | | close FILE; |
37 | | | $device=0; |
38 | | | while (@readacc) { |
39 | | | $racc=shift @readacc; |
40 | | | $wacc=shift @writeacc; |
41 | | | $rblk=shift @readblk; |
42 | | | $wblk=shift @writeblk; |
43 | | | |
44 | | | $blocksize=512; |
45 | | | HotSaNICmod::do_rrd($device,"U",time,$racc,$blocksize*$rblk,$wacc,$blocksize*$wblk); |
46 | | | |
47 | | | $device++; |
48 | | | } |
49 | | | } |
50 | | | |
51 | | | ###################################################################### |
52 | | | # |
53 | | | # KERNEL 2.4 CODE |
54 | | | # |
55 | | | elsif ($args{KERNEL} eq "2.4") { |
56 | | | if ( ($args{"SOURCE"} eq "partitions") or ($args{"SOURCE"} eq "diskstats") ) { |
57 | | | # major minor #blocks name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq |
58 | | | # 8 16 8958120 sdb 285 6274 52274 17480 9 3 96 0 0 2750 17480 |
59 | | | # 34 0 80043264 ide/host2/bus1/target0/lun0/disc 2368478 1209106 28620666 20372050 2689313 9234680 95391960 22393060 0 26560040 42765110 |
60 | | | open FILE,"/proc/".$args{SOURCE}; |
61 | | | $_=<FILE>; # strip header |
62 | | | while (<FILE>) { |
63 | | | chomp; |
64 | | | if ($_ ne "") { |
65 | | | ($major,$minor,undef,undef,$rio,undef,$rsect,undef,$wio,undef,$wsect,undef) = split; |
66 | | | |
67 | | | $device=$major."_".$minor; |
68 | | | if (defined $DEVS{$device}) { |
69 | | | my $sectsize=512; |
70 | | | HotSaNICmod::do_rrd($device,"U",time,$rio,$sectsize*$rsect,$wio,$sectsize*$wsect); |
71 | | | } |
72 | | | } |
73 | | | } |
74 | | | close FILE; |
75 | | | } |
76 | | | else { |
77 | | | # disk_io: (8,0):(985065,41330,436455,943735,13075448) (8,1):(12563,6363,333604,6200,167608) (8,2):(11194,11012,90140,182,3160) |
78 | | | open FILE,"/proc/stat"; |
79 | | | while (<FILE>) { (undef,@stats)=split if /disk_io/; } |
80 | | | close FILE; |
81 | | | foreach my $entry (@stats) { |
82 | | | $entry=~ s/[()]//g; |
83 | | | $entry=~ s/:/,/g; |
84 | | | my ($num1,$num2,undef,$racc,$rblk,$wacc,$wblk)=split /,/,$entry; |
85 | | | |
86 | | | $device=$num1."_".$num2; |
87 | | | if (defined $DEVS{$device}) { |
88 | | | $blocksize=512; |
89 | | | HotSaNICmod::do_rrd($device,"U",time,$racc,$blocksize*$rblk,$wacc,$blocksize*$wblk); |
90 | | | } |
91 | | | } |
92 | | | } |
93 | | | } |
94 | | | |
95 | | | ###################################################################### |
96 | | | # |
97 | | | # KERNEL 2.6 CODE |
98 | | | # |
99 | | | elsif ($args{KERNEL} eq "2.6") { |
100 | | | # diskstats: major minor name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq |
101 | | | # 3 64 hdb 524233 57272 91269016 6239457 233008 24726677 199678904 73630251 0 6331127 79891245 |
102 | | | # 3 64 hdb 524298 57274 91284864 6239742 233012 24726679 199678952 73630252 0 6331403 79891531 |
103 | | | open FILE,"/proc/diskstats"; |
104 | | | while ($entry = <FILE>) { |
105 | | | $entry =~ s/^\s*//; # strip leading whitespaces |
106 | | | my ($major,$minor,undef,$racc,undef,$rsect,undef,$wacc,undef,$wsect)=split(/\s+/,$entry); |
107 | | | $device=$major."_".$minor; |
108 | | | if (defined $DEVS{$device}) { |
109 | | | my $sectsize=512; |
110 | | | HotSaNICmod::do_rrd($device,"U",time,$racc,$rsect*$sectsize,$wacc,$wsect*$sectsize); |
111 | | | } |
112 | | | } |
113 | | | close FILE; |
114 | | | } |
115 | | | |
116 | | | } |
117 | | | |
118 | | | 1; |
119 | | | |