/usr/share/mgm/modules/linux/diskstat is in mgm 1.1.svn.20080520-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | # -*-Perl-*-
# instances allowed: one
# (single instance modules would be silly to use more than one of
# anyway, so we use package local storage. This is faster and places
# less artificial load on the machine than doing everything through
# the object hash)
# todo: go back to using disk id numbers as reported rather than
# trying to make a contiguous numbering
package MGMmodule::diskstat;
use vars qw($xpath @rsectors @wsectors @prevr @prevw $widget $graph
$numdisks $lastdisks $lastmod $kernel @disknames);
use IO::Seekable;
# class init
sub module_init{
my$this=shift;
my$toplevel=$this->{"toplevel"};
my$xclass=$this->{"xclass"};
# how many disks? Call read once to init
$numdisks=0;
# 2.0 and 2.2
if(defined($MGMmodule::helperST::proc{"disk_rblk"})){
$kernel=0;$this->read_proc;
}
# 2.4
if(defined($MGMmodule::helperST::proc{"disk_io:"})){
$kernel=4;$this->read_proc;
}
# 2.6
if(defined(%MGMmodule::helperST::disk26)){
$kernel=6;$this->read_proc;
}
if(!$numdisks){
$toplevel->optionAdd("$xclass.active",'false',21);
}
$toplevel->optionAdd("$xclass.order",10,21);
$lastdisks=$numdisks;
$this;
}
# instance init
sub module_instance{
my$this=shift;
my$toplevel=$this->{"toplevel"};
return undef if(defined($xpath));
$xpath=$this->{"xpath"};
# modify defaults
for(my$i=0;$i<$numdisks;$i++){
$toplevel->optionAdd("$xpath.bar.".($i*2).".label",
"$disknames[$i] read",21);
$toplevel->optionAdd("$xpath.bar.".($i*2+1).".label",
"$disknames[$i] write",21);
$toplevel->optionAdd("$xpath.bar.".($i*2).".litbackground",
'#e7ad74',21);
$toplevel->optionAdd("$xpath.bar.".($i*2+1).".litbackground",
'#ade774',21);
}
$toplevel->optionAdd("$xpath.scalewidadj", 160*$numdisks,21); # narrower
$toplevel->optionAdd("$xpath.scalereturn", 120,21);
# this relies on the above defaults
my($minx,$miny)=MGM::Graph::calcxysize($this,1024*1024*512,
' sect/s',$numdisks*2);
$toplevel->optionAdd("$xpath.minx", $minx,21);
$toplevel->optionAdd("$xpath.miny", $miny,21);
$this;
}
# instance widget build
sub module_run{
my$this=shift;
$graph=MGM::Graph->new($this,num=>$numdisks*2,
prompt=>' sect/s',
minscale=>128);
$lastmod=-1;
$widget=$graph->{"widget"}; # must return the widget
}
sub read_proc{
if($kernel==6){ #2.6-ish
undef @rsectors;
undef @wsectors;
$numdisks=0;
foreach my $key (sort(keys %MGMmodule::helperST::disk26)){
# if there are per-parition stats available, skip the whole-disk entries
if($key=~m/^[^0-9]+$/){
if(defined($MGMmodule::helperST::disk26{"$key"."1"})){
next;
}
}
if($MGMmodule::helperST::disk26{$key}=~m/\d+\s+\d+\s+(\d+)\s+\d+\s+\d+\s+\d+\s+(\d+)/ ||
$MGMmodule::helperST::disk26{$key}=~m/\d+\s+(\d+)\s+\d+\s+(\d+)/){
# if this entry is as-yet unused, ignore it
next if($1==0 && $2==0);
$rsectors[$numdisks]=$1;
$wsectors[$numdisks]=$2;
$disknames[$numdisks]=$key;
$numdisks++;
}
}
}else{
# now uses the 00helper to save on opens
if($kernel==4){ #2.4-ish
my $disk;
my@disks=split ' ',$MGMmodule::helperST::proc{"disk_io:"};
$numdisks=0;
undef @rsectors;
undef @wsectors;
foreach $disk (@disks){
$disk=~m/\(\d+,\d+\):\(\d+,\d+,(\d+),\d+,(\d+)\)/;
if ($1 || $2){
$rsectors[$numdisks]=$1;
$wsectors[$numdisks]=$2;
$disknames[$numdisks]="disk$numdisks";
$numdisks++;
}
}
}else{ #2.0/2.2-ish
my@A=split ' ',$MGMmodule::helperST::proc{"disk_rblk"};
my@B=split ' ',$MGMmodule::helperST::proc{"disk_wblk"};
$numdisks=0;
map{if ($A[$_] || $B[$_]){$rsectors[$numdisks]=$A[$_];
$wsectors[$numdisks]=$B[$_];
$disknames[$numdisks]="disk$numdisks";
}}(0..$#A);
}
}
}
sub module_update{
my$this=shift;
# don't update unless the helper has
if($lastmod!=$MGMmodule::helperST::lastmod){
my$time=$MGMmodule::helperST::lastmod;
$this->read_proc;
return &reconfig if($numdisks != $lastdisks);
$lastdisks=$numdisks;
if(defined(@prevr)){
my @vals;
for(my$i=0;$i<=$#rsectors;$i++){
if ($rsectors[$i] or $wsectors[$i]){
my$r=($rsectors[$i]-$prevr[$i])/($time-$lastmod)*100;
my$w=($wsectors[$i]-$prevw[$i])/($time-$lastmod)*100;
push @vals, $r, $w;
}
}
# don't be clever and only call set if values change; set must
# be called each refresh period or the graph will get
# confused.
$graph->set(@vals);
}
@prevr=@rsectors;
@prevw=@wsectors;
$lastmod=$time;
}
}
sub reconfig{
$lastdisks=$numdisks;
@prevr=@rsectors;
@prevw=@wsectors;
&main::reinstance() if($widget->optionGet("reconfig","") eq 'true');
}
sub destroy{
undef $xpath;
}
bless {};
|