21 |
|
# You'd be silly not to use this ;) |
22 |
|
use strict; |
23 |
|
|
24 |
< |
# Path's |
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(); |
109 |
|
|
110 |
|
# Find out all users on this machine. |
111 |
|
my($users) = `$usersbin`; |
112 |
< |
chop($users); |
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; |
116 |
> |
my($users_list) = $users." "; |
117 |
|
|
118 |
|
&print_pair(1, "packet.users.count", $users_count); |
119 |
|
&print_pair(0, "packet.users.list", $users_list); |
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/); |
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 |
|
} |