49 |
|
# sub to print pairs of data, separated by a single space character. |
50 |
|
# If the second argument is undefined, then the pair is still printed, |
51 |
|
# however, the value shall be displayed as the string "unknown". |
52 |
< |
sub print_pair($$) { |
53 |
< |
my($name, $value) = @_; |
52 |
> |
# If $type is non-zero, then "0" is printed instead of "unknown". |
53 |
> |
sub print_pair($$$) { |
54 |
> |
my($type, $name, $value) = @_; |
55 |
|
|
56 |
|
if (!defined $value) { |
57 |
< |
$value = "unknown"; |
57 |
> |
if ($type) { |
58 |
> |
$value = "0.00"; |
59 |
> |
} |
60 |
> |
else { |
61 |
> |
$value = "unknown"; |
62 |
> |
} |
63 |
|
} |
64 |
|
|
65 |
|
# Remove the trailing linefeed if we've not already done so. |
84 |
|
# $4 will not match unless everything before it does... |
85 |
|
if (defined $5) { |
86 |
|
my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5); |
87 |
< |
&print_pair("packet.disk.p$partition_no.attributes.name", $filesystem); |
88 |
< |
&print_pair("packet.disk.p$partition_no.attributes.kbytes", $kbytes); |
89 |
< |
&print_pair("packet.disk.p$partition_no.attributes.used", $used); |
90 |
< |
&print_pair("packet.disk.p$partition_no.attributes.avail", $avail); |
91 |
< |
&print_pair("packet.disk.p$partition_no.attributes.mount", $mount); |
87 |
> |
&print_pair(0, "packet.disk.p$partition_no.attributes.name", $filesystem); |
88 |
> |
&print_pair(1, "packet.disk.p$partition_no.attributes.kbytes", $kbytes); |
89 |
> |
&print_pair(1, "packet.disk.p$partition_no.attributes.used", $used); |
90 |
> |
&print_pair(1, "packet.disk.p$partition_no.attributes.avail", $avail); |
91 |
> |
&print_pair(0, "packet.disk.p$partition_no.attributes.mount", $mount); |
92 |
|
++$partition_no; |
93 |
|
} |
94 |
|
} |
106 |
|
my($users_count) = $#users + 1; |
107 |
|
my($users_list) = $users; |
108 |
|
|
109 |
< |
&print_pair("packet.users.count", $users_count); |
110 |
< |
&print_pair("packet.users.list", $users_list); |
109 |
> |
&print_pair(1, "packet.users.count", $users_count); |
110 |
> |
&print_pair(0, "packet.users.list", $users_list); |
111 |
|
} |
112 |
|
|
113 |
|
|
120 |
|
my($top) = join(" ", @top); |
121 |
|
$top =~ s/\n//g; |
122 |
|
|
123 |
< |
&print_pair("packet.load.load1", $top =~ /load averages:\s*([^\s]+?),/); |
124 |
< |
&print_pair("packet.load.load5", $top =~ /load averages:\s*.+?,\s*([^\s]+?),/); |
125 |
< |
&print_pair("packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s*/); |
126 |
< |
&print_pair("packet.processes.total", $top =~ /([^\s]+?) processes:/); |
127 |
< |
&print_pair("packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); |
128 |
< |
&print_pair("packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); |
129 |
< |
&print_pair("packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); |
130 |
< |
&print_pair("packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/); |
131 |
< |
&print_pair("packet.cpu.idle", $top =~ /([^\s]+?)% idle/); |
132 |
< |
&print_pair("packet.cpu.user", $top =~ /([^\s]+?)% user/); |
133 |
< |
&print_pair("packet.cpu.kernel", $top =~ /([^\s]+?)% kernel/); |
134 |
< |
&print_pair("packet.cpu.iowait", $top =~ /([^\s]+?)% iowait/); |
135 |
< |
&print_pair("packet.cpu.swap", $top =~ /([^\s]+?)% swap/); |
136 |
< |
&print_pair("packet.memory.real", $top =~ /([^\s]+?)[MG] real/); |
137 |
< |
&print_pair("packet.memory.free", $top =~ /([^\s]+?)[MG] free/); |
138 |
< |
&print_pair("packet.memory.swap_in_use", $top =~ /([^\s]+?)[MG] swap in use/); |
139 |
< |
&print_pair("packet.memory.swap_free", $top =~ /([^\s]+?)[MG] swap free/); |
140 |
< |
|
123 |
> |
&print_pair(1, "packet.load.load1", $top =~ /load averages:\s*([^\s]+?),/); |
124 |
> |
&print_pair(1, "packet.load.load5", $top =~ /load averages:\s*.+?,\s*([^\s]+?),/); |
125 |
> |
&print_pair(1, "packet.load.load15", $top =~ /load averages:\s*.+?,\s*.+?,\s*([^\s]+?)\s*/); |
126 |
> |
&print_pair(1, "packet.processes.total", $top =~ /([^\s]+?) processes:/); |
127 |
> |
&print_pair(1, "packet.processes.sleeping", $top =~ / ([^\s]+?) sleeping/); |
128 |
> |
&print_pair(1, "packet.processes.zombie", $top =~ / ([^\s]+?) zombie/); |
129 |
> |
&print_pair(1, "packet.processes.stopped", $top =~ / ([^\s]+?) stopped/); |
130 |
> |
&print_pair(1, "packet.processes.cpu", $top =~ /([^\s]+?)\s*on cpu/); |
131 |
> |
&print_pair(1, "packet.cpu.idle", $top =~ /([^\s]+?)% idle/); |
132 |
> |
&print_pair(1, "packet.cpu.user", $top =~ /([^\s]+?)% user/); |
133 |
> |
&print_pair(1, "packet.cpu.kernel", $top =~ /([^\s]+?)% kernel/); |
134 |
> |
&print_pair(1, "packet.cpu.iowait", $top =~ /([^\s]+?)% iowait/); |
135 |
> |
&print_pair(1, "packet.cpu.swap", $top =~ /([^\s]+?)% swap/); |
136 |
> |
|
137 |
> |
# The following need to be specified in megabytes. |
138 |
> |
# If they are preceeded by a G, then multiply by 1024. |
139 |
> |
|
140 |
> |
$top =~ /([^\s]+?)([MG]) real/; |
141 |
> |
my($real) = $1*1024 if $2 eq "G"; |
142 |
> |
&print_pair(1, "packet.memory.real", $real); |
143 |
> |
|
144 |
> |
$top =~ /([^\s]+?)([MG]) free/; |
145 |
> |
my($free) = $1*1024 if $2 eq "G"; |
146 |
> |
&print_pair(1, "packet.memory.free", $free); |
147 |
> |
|
148 |
> |
$top =~ /([^\s]+?)([MG]) swap in use/; |
149 |
> |
my($swap_in_use) = $1*1024 if $2 eq "G"; |
150 |
> |
&print_pair(1, "packet.memory.swap_in_use", $swap_in_use); |
151 |
> |
|
152 |
> |
$top =~ /([^\s]+?)([MG]) swap free/; |
153 |
> |
my($swap_free) = $1*1024 if $2 eq "G"; |
154 |
> |
&print_pair(1, "packet.memory.swap_free", $swap_free); |
155 |
|
} |
156 |
|
|
157 |
|
# sub to get details of the machine's operating system. |
166 |
|
my($os_sysname) = `uname -n`; |
167 |
|
my($os_version) = `uname -v`; |
168 |
|
|
169 |
< |
&print_pair("packet.os.name", $os_name); |
170 |
< |
&print_pair("packet.os.release", $os_release); |
171 |
< |
&print_pair("packet.os.platform", $os_platform); |
172 |
< |
&print_pair("packet.os.sysname", $os_sysname); |
173 |
< |
&print_pair("packet.os.version", $os_version); |
169 |
> |
&print_pair(0, "packet.os.name", $os_name); |
170 |
> |
&print_pair(0, "packet.os.release", $os_release); |
171 |
> |
&print_pair(0, "packet.os.platform", $os_platform); |
172 |
> |
&print_pair(0, "packet.os.sysname", $os_sysname); |
173 |
> |
&print_pair(0, "packet.os.version", $os_version); |
174 |
|
|
175 |
|
} |