jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [modules/] [system/] [platform/] [darwin.pm] - Blame information for rev 30

 

Line No. Rev Author Line
11simandlpackage HotSaNICmod::OSdep;
2 
3# return module version
4#
5sub version {
6 ($VERSION = '$Revision: 1.5 $') =~ s/.*(\d+\.\d+).*/$1/;
7 return "$^O.pm $VERSION";
8 }
9 
10# sample data
11#
12sub sample {
13 my %args=@_;
14 
15 @sections = split " ", ($args{SECTIONS});
16 foreach (@sections){
17 if ($_ eq "cpu") {read_cpu(%args)}
18 if ($_ eq "load") {read_load(%args)}
19 if ($_ eq "proc") {read_proc(%args)}
20 if ($_ eq "mem") {read_mem(%args)}
21 if ($_ eq "users") {read_users(%args)}
22 }
23}
24 
25 
26# users.rrd -> tty pty pts
27# cpu.rrd -> cpuusr cpunic cpusys cpuint cpuidl
28# load.rrd -> load15 load5 load1
29# proc.rrd -> procslp procrun proczmb procstp
30# mem.rrd (Linux) -> memfre memshr membuf memcac swpfre swpuse
31 
32 
33#####################################################################################
34# build CPU statistics
35#
36# We get info from the kern.cp_time sysctl. works on 4.6-4.7-STABLE and
37# should work at least on single-cpu 5.0 boxes too. Values for SMP systems
38# are cumulative until I (or anyone else) can get per-cpu info out of
39# the kernel. Gkrellm can't even do that!!! :(
40#
41# sysctl order is: user nice sys intr idle
42 
43sub read_cpu {
44 my %args=@_;
45 
46 @top = `top -l2`;
47 
48 while(@top){
49 if(/CPU Usage:\s+(\d+\.\d+)\% user,\s+(\d+\.\d+)\% sys,\s+(\d+\.\d+)\%/){
50 $cpuusr = $1;
51 $cpusys = $2;
52 $cpuidl = $3;
53 last;
54 }
55 }
56 HotSaNICmod::do_rrd("cpu","U",time,$cpuusr,$cpusys,$cpuidl);
57}
58 
59 
60 
61#####################################################################################
62# here we go with the load-average value ...
63#
64sub read_load {
65 my %args=@_;
66 (undef,$load1,$load5,$load15)=split(/ /,`/sbin/sysctl vm.loadavg`);
67 HotSaNICmod::do_rrd("load","U",time,$load15,$load5,$load1);
68}
69 
70 
71 
72#####################################################################################
73# now the processes. We have to check how many processes are sleeping,
74# running, zombieng spwapped to disc or stopped. To do this we simply
75# have to walk through the /proc tree, check all "stat" files of each
76# process-id subdir and increment the according state-counter.
77#
78sub read_proc {
79 my %args=@_;
80 ($procslp,$procrun,$proczmb,$procstp,$procdsc)=(0,0,0,0,0);
81 
82 @states=`/bin/ps axostate`;
83 foreach (@states) {
84 $procslp++ if (/^[SI]/); #Sleeping (S=<20s, I=>20s)
85 $procdsc++ if (/^D/); #Disk wait
86 $procrun++ if (/^R/); #Running
87 $proczmb++ if (/^Z/); #Zombie
88 $procstp++ if (/^T/); #Stopped
89 }
90 HotSaNICmod::do_rrd("proc","U",time,$procslp,$procrun,$proczmb,$procstp,$procdsc);
91}
92 
93 
94#####################################################################################
95# read users stats
96#
97sub read_users {
98 my %args=@_;
99 
100 # XXX im not shure if this will work. PR
101 @users=`who`;
102 ($tty,$pty,$pts)=(0,0,0);
103 foreach (@users) {
104 if (index($_," ttyv") >=0 ) { $tty++; }
105 elsif (index($_," ttyp") >=0 ) { $pty++; }
106 elsif (index($_," pts") >=0 ) { $pts++; }
107 }
108 HotSaNICmod::do_rrd("users","U",time,$tty,$pty,$pts);
109}
110 
111 
112####################################################################################
113# here we go with the memory and swap statistics...
114#
115sub read_mem {
116 my %args=@_;
117 
118 @top = `top -l2`;
119 
120 #PhysMem: 97.4M wired, 144M active, 567M inactive, 809M used, 727M free
121 #VM: 3.27G + 3.62M 14904(14904) pageins, 44(44) pageouts
122 
123 while(@top){
124 if(/^PhysMem:/){
125 s/^[0-9\.\sKMG]//g;
126 foreach( split ){
127 #convert SI to integer bytes
128 if(/\dG/){ s/G//; $_ *= (1024**3) }
129 if(/\dM/){ s/M//; $_ *= (1024**2) }
130 if(/\dK/){ s/K//; $_ *= 1024 }
131 $_ = int
132 }
133 (undef, $memwire, $memactv, $meminac, $memused, $memfree) = @_;
134 last;
135 }
136 }
137 
138 
139 #get swap.
140 # to be done!
141 open(IN,"/usr/sbin/pstat -sk|");
142 while(<IN>) {
143 (undef, undef, $swpuse, $swpfre) = split;
144 }
145 
146 $swpuse*=1024;
147 $swpfre*=1024;
148 
149 HotSaNICmod::do_rrd("mem","U",time,$memfree,$memwire,$memactv,$meminac,$swpfre,$swpuse);
150 }
151 
1521;

Powered by WebSVN 2.2.1