ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/generic/statgrab.pl
(Generate patch)

Comparing projects/cms/source/host/generic/statgrab.pl (file contents):
Revision 1.11 by pjm2, Mon Jan 22 17:23:25 2001 UTC vs.
Revision 1.23 by pjm2, Mon Feb 5 08:27:38 2001 UTC

# Line 21 | Line 21 | $| = 1;
21   # You'd be silly not to use this ;)
22   use strict;
23  
24 + # Paths
25 + my($topbin) = "/usr/local/sbin/top";
26 + my($dfbin) = "/usr/bin/df";
27 + my($usersbin) = "/usr/ucb/users";
28 + my($unamebin) = "/usr/bin/uname";
29 + my($uptimebin) = "/usr/bin/uptime";
30 +
31   # Run the following components: -
32   &print_ident();
33   &include_osver();
34 + &include_uptime();
35   &include_users();
36   &include_top();
37   &include_disk();
# Line 74 | Line 82 | sub print_pair($$$) {
82   sub include_disk() {
83      
84      # Run the df program.
85 <    my(@df) = `df -ak`;
85 >    my(@df) = `$dfbin -ak`;
86  
87      # Go through each line of the program, looking for each thing we want.
88      my($partition_no) = 0;
# Line 100 | Line 108 | sub include_disk() {
108   sub include_users() {
109  
110      # Find out all users on this machine.
111 <    my($users) = `users`;
112 <    my(@users) = split(/\s+/, $users);
111 >    my($users) = `$usersbin`;
112 >    $users = "\n" unless defined $users;
113 >    chop $users;
114 >    my($users_count) = 0;
115 >    $users_count++ while $users =~ /\w+/g;
116 >    my($users_list) = $users." ";
117  
106    my($users_count) = $#users + 1;
107    my($users_list) = $users;
108
118      &print_pair(1, "packet.users.count", $users_count);
119      &print_pair(0, "packet.users.list", $users_list);
120   }
# Line 116 | Line 125 | sub include_users() {
125   sub include_top() {
126  
127      # Find out some numbers from top.
128 <    my(@top) = `top -d2 -s1 0`;
128 >    my(@top) = `$topbin -d2 -s1 0`;
129      my($top) = join(" ", @top);
130      $top =~ s/\n//g;
131  
132      &print_pair(1, "packet.load.load1", $top =~ /load averages:\s*([^\s]+?),/);
133      &print_pair(1, "packet.load.load5", $top =~ /load averages:\s*.+?,\s*([^\s]+?),/);
134 <    &print_pair(1, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s*/);
134 >    &print_pair(1, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s+/);
135      &print_pair(1, "packet.processes.total", $top =~ /([^\s]+?) processes:/);
136      &print_pair(1, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/);
137      &print_pair(1, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/);
# Line 150 | Line 159 | sub include_top() {
159      $top =~ /([^\s]+?)([MG]) swap in use/;
160      my($swap_in_use) = $1;
161      $swap_in_use*=1024 if $2 eq "G";
162 <    &print_pair(1, "packet.memory.swap_in_use", $swap_in_use);
162 >    # DO NOT print this one out... save it for in a moment...
163  
164      $top =~ /([^\s]+?)([MG]) swap free/;
165      my($swap_free) = $1;
166      $swap_free*=1024 if $2 eq "G";
167      &print_pair(1, "packet.memory.swap_free", $swap_free);
168 +
169 +    # AJ requested total swap instead of swap_in_use, so here we go!
170 +    &print_pair(1, "packet.memory.swap_total", $swap_free + $swap_in_use);
171   }
172  
173   # sub to get details of the machine's operating system.
# Line 164 | Line 176 | sub include_osver() {
176      # Find out details about the operating system
177      # If these values remain undefined, then the print_pair
178      # function shall show the value to be the string "unknown".
179 <    my($os_name) = `uname -s`;
180 <    my($os_release) = `uname -r`;
181 <    my($os_platform) = `uname -m`;
182 <    my($os_sysname) = `uname -n`;
183 <    my($os_version) = `uname -v`;
179 >    my($os_name) = `$unamebin -s`;
180 >    my($os_release) = `$unamebin -r`;
181 >    my($os_platform) = `$unamebin -m`;
182 >    my($os_sysname) = `$unamebin -n`;
183 >    my($os_version) = `$unamebin -v`;
184  
185      &print_pair(0, "packet.os.name", $os_name);
186      &print_pair(0, "packet.os.release", $os_release);
187      &print_pair(0, "packet.os.platform", $os_platform);
188      &print_pair(0, "packet.os.sysname", $os_sysname);
189      &print_pair(0, "packet.os.version", $os_version);
190 +
191 + }
192 +
193 + # sub to get system uptime.
194 + sub include_uptime() {
195 +
196 +    # grab the uptime
197 +    my($uptime) = `$uptimebin`;
198 +
199 +    # work out the days, hours, and minutes
200 +    if ($uptime =~ /hr/) {
201 +      # 0 minutes
202 +        $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:$2:0/;
203 +    }
204 +    elsif ($uptime =~ /min/) {
205 +      # 0 hours
206 +        $uptime =~ s/up ([0-9]+) .*, ([0-9]+) .*,/$1:0:$2/;
207 +    }
208 +    elsif ($uptime =~ /day/) {
209 +      # normal
210 +        $uptime =~ s/up ([0-9]+) .*, ([0-9]+):([0-9]+)/$1:$2:$3/;
211 +    }
212 +    else {
213 +      # 0 days
214 +        $uptime =~ s/up ([0-9]+):([0-9]+)/0:$1:$2/;
215 +    }
216 +
217 +    # turn into minutes
218 +
219 +    $uptime =~ /([0-9]+):([0-9]+):([0-9]+)/;
220 +    $uptime = $3 + ($2 + $1*24)*60;
221 +
222 +    &print_pair(0, "packet.os.uptime", $uptime);
223  
224   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines