sigar 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -4
- data/bindings/SigarWrapper.pm +47 -0
- data/include/sigar.h +41 -0
- data/include/sigar_private.h +7 -2
- data/include/sigar_util.h +6 -0
- data/src/os/aix/aix_sigar.c +17 -0
- data/src/os/darwin/darwin_sigar.c +20 -13
- data/src/os/hpux/hpux_sigar.c +19 -0
- data/src/os/linux/linux_sigar.c +28 -0
- data/src/os/solaris/solaris_sigar.c +16 -1
- data/src/os/win32/sigar_os.h +2 -0
- data/src/os/win32/win32_sigar.c +50 -6
- data/src/sigar.c +131 -115
- data/src/sigar_cache.c +81 -7
- data/src/sigar_ptql.c +9 -0
- metadata +3 -23
- data/bindings/ruby/examples/arp.rb +0 -24
- data/bindings/ruby/examples/cpu_info.rb +0 -35
- data/bindings/ruby/examples/df.rb +0 -49
- data/bindings/ruby/examples/free.rb +0 -36
- data/bindings/ruby/examples/ifconfig.rb +0 -101
- data/bindings/ruby/examples/logging.rb +0 -58
- data/bindings/ruby/examples/net_info.rb +0 -31
- data/bindings/ruby/examples/netstat.rb +0 -71
- data/bindings/ruby/examples/pargs.rb +0 -35
- data/bindings/ruby/examples/penv.rb +0 -31
- data/bindings/ruby/examples/route.rb +0 -48
- data/bindings/ruby/examples/version.rb +0 -40
- data/bindings/ruby/examples/who.rb +0 -30
- data/bindings/ruby/test/cpu_test.rb +0 -40
- data/bindings/ruby/test/file_system_test.rb +0 -43
- data/bindings/ruby/test/helper.rb +0 -57
- data/bindings/ruby/test/loadavg_test.rb +0 -30
- data/bindings/ruby/test/mem_test.rb +0 -45
- data/bindings/ruby/test/swap_test.rb +0 -36
- data/bindings/ruby/test/uptime_test.rb +0 -26
data/src/sigar_ptql.c
CHANGED
@@ -1338,6 +1338,14 @@ static ptql_lookup_t PTQL_Cpu[] = {
|
|
1338
1338
|
{ NULL }
|
1339
1339
|
};
|
1340
1340
|
|
1341
|
+
static ptql_lookup_t PTQL_Disk_IO[] = {
|
1342
|
+
{ "BytesRead", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_read, UI64) },
|
1343
|
+
{ "BytesWritten", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_written, UI64) },
|
1344
|
+
{ "BytesTotal", PTQL_LOOKUP_ENTRY(proc_disk_io, bytes_total, UI64) },
|
1345
|
+
{ NULL }
|
1346
|
+
};
|
1347
|
+
|
1348
|
+
|
1341
1349
|
static ptql_lookup_t PTQL_CredName[] = {
|
1342
1350
|
{ "User", PTQL_LOOKUP_ENTRY(proc_cred_name, user, STR) },
|
1343
1351
|
{ "Group", PTQL_LOOKUP_ENTRY(proc_cred_name, group, STR) },
|
@@ -1424,6 +1432,7 @@ static ptql_entry_t ptql_map[] = {
|
|
1424
1432
|
{ "Port", PTQL_Port },
|
1425
1433
|
{ "Pid", PTQL_Pid },
|
1426
1434
|
{ "Service", PTQL_Service },
|
1435
|
+
{ "Disk_IO", PTQL_Disk_IO },
|
1427
1436
|
{ NULL }
|
1428
1437
|
};
|
1429
1438
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sigar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: System Information Gatherer And Reporter
|
15
15
|
email: sigar-users@hyperic.org
|
@@ -25,28 +25,8 @@ files:
|
|
25
25
|
- version.properties
|
26
26
|
- bindings/SigarWrapper.pm
|
27
27
|
- bindings/SigarBuild.pm
|
28
|
-
- bindings/ruby/examples/arp.rb
|
29
|
-
- bindings/ruby/examples/cpu_info.rb
|
30
|
-
- bindings/ruby/examples/df.rb
|
31
|
-
- bindings/ruby/examples/free.rb
|
32
|
-
- bindings/ruby/examples/ifconfig.rb
|
33
|
-
- bindings/ruby/examples/logging.rb
|
34
|
-
- bindings/ruby/examples/net_info.rb
|
35
|
-
- bindings/ruby/examples/netstat.rb
|
36
|
-
- bindings/ruby/examples/pargs.rb
|
37
|
-
- bindings/ruby/examples/penv.rb
|
38
|
-
- bindings/ruby/examples/route.rb
|
39
|
-
- bindings/ruby/examples/version.rb
|
40
|
-
- bindings/ruby/examples/who.rb
|
41
28
|
- bindings/ruby/extconf.rb
|
42
29
|
- bindings/ruby/rbsigar.c
|
43
|
-
- bindings/ruby/test/cpu_test.rb
|
44
|
-
- bindings/ruby/test/file_system_test.rb
|
45
|
-
- bindings/ruby/test/helper.rb
|
46
|
-
- bindings/ruby/test/loadavg_test.rb
|
47
|
-
- bindings/ruby/test/mem_test.rb
|
48
|
-
- bindings/ruby/test/swap_test.rb
|
49
|
-
- bindings/ruby/test/uptime_test.rb
|
50
30
|
- include/sigar.h
|
51
31
|
- include/sigar_fileinfo.h
|
52
32
|
- include/sigar_format.h
|
@@ -105,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
85
|
version: '0'
|
106
86
|
requirements: []
|
107
87
|
rubyforge_project:
|
108
|
-
rubygems_version: 1.8.
|
88
|
+
rubygems_version: 1.8.23
|
109
89
|
signing_key:
|
110
90
|
specification_version: 3
|
111
91
|
summary: System Information Gatherer And Reporter
|
@@ -1,24 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2010 VMware, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
|
17
|
-
require 'sigar'
|
18
|
-
|
19
|
-
Sigar.new.arp_list.each do |arp|
|
20
|
-
host = "?" #XXX
|
21
|
-
puts host + " " +
|
22
|
-
"(" + arp.address + ")" + " at " + arp.hwaddr + " " +
|
23
|
-
"[" + arp.type + "]" + " on " + arp.ifname
|
24
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2007 Hyperic, Inc.
|
3
|
-
# Copyright (c) 2009-2010 VMware, Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require 'sigar'
|
19
|
-
|
20
|
-
sigar = Sigar.new
|
21
|
-
|
22
|
-
infos = sigar.cpu_info_list
|
23
|
-
|
24
|
-
num = infos.length
|
25
|
-
|
26
|
-
puts num.to_s + " total CPUs.."
|
27
|
-
|
28
|
-
infos.each do |info|
|
29
|
-
puts "Vendor........" + info.vendor
|
30
|
-
puts "Model........." + info.model
|
31
|
-
puts "Current Mhz..." + info.mhz.to_s
|
32
|
-
puts "Maximum Mhz..." + info.mhz_max.to_s
|
33
|
-
puts "Minimum Mhz..." + info.mhz_min.to_s
|
34
|
-
puts "Cache size...." + info.cache_size.to_s
|
35
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2007, 2009 Hyperic, Inc.
|
3
|
-
# Copyright (c) 2010 VMware, Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require 'sigar'
|
19
|
-
|
20
|
-
def format_size(size)
|
21
|
-
return Sigar.format_size(size * 1024)
|
22
|
-
end
|
23
|
-
|
24
|
-
sigar = Sigar.new
|
25
|
-
fslist = sigar.file_system_list
|
26
|
-
|
27
|
-
puts "Filesystem\tSize\tUsed\tAvail\tUse%\tMounted on\tType\n"
|
28
|
-
|
29
|
-
fslist.each do |fs|
|
30
|
-
dir_name = fs.dir_name
|
31
|
-
begin
|
32
|
-
usage = sigar.file_system_usage(dir_name)
|
33
|
-
total = usage.total
|
34
|
-
used = total - usage.free
|
35
|
-
avail = usage.avail
|
36
|
-
pct = usage.use_percent * 100
|
37
|
-
rescue Exception => e
|
38
|
-
#e.g. floppy or cdrom drive
|
39
|
-
used = avail = total = pct = 0;
|
40
|
-
end
|
41
|
-
|
42
|
-
puts fs.dev_name + "\t" +
|
43
|
-
format_size(total) + "\t" +
|
44
|
-
format_size(used) + "\t" +
|
45
|
-
format_size(avail) + "\t" +
|
46
|
-
(pct == 0.0 ? '-' : pct.to_s) + "\t" +
|
47
|
-
dir_name + "\t" +
|
48
|
-
fs.sys_type_name + "/" + fs.type_name
|
49
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2007 Hyperic, Inc.
|
3
|
-
# Copyright (c) 2010 VMware, Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require 'sigar'
|
19
|
-
|
20
|
-
sigar = Sigar.new
|
21
|
-
mem = sigar.mem
|
22
|
-
swap = sigar.swap
|
23
|
-
|
24
|
-
puts "\tTotal\tUsed\tFree"
|
25
|
-
|
26
|
-
puts "Mem: " +
|
27
|
-
(mem.total / 1024).to_s + "\t" +
|
28
|
-
(mem.used / 1024).to_s + "\t" +
|
29
|
-
(mem.free/ 1024).to_s
|
30
|
-
|
31
|
-
puts "Swap: " +
|
32
|
-
(swap.total / 1024).to_s + "\t" +
|
33
|
-
(swap.used / 1024).to_s + "\t" +
|
34
|
-
(swap.free/ 1024).to_s
|
35
|
-
|
36
|
-
puts "RAM: " + mem.ram.to_s + "MB";
|
@@ -1,101 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2007 Hyperic, Inc.
|
3
|
-
# Copyright (c) 2009 SpringSource, Inc.
|
4
|
-
# Copyright (c) 2010 VMware, Inc.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'sigar'
|
20
|
-
|
21
|
-
sigar = Sigar.new
|
22
|
-
iflist = sigar.net_interface_list
|
23
|
-
|
24
|
-
iflist.each do |ifname|
|
25
|
-
ifconfig = sigar.net_interface_config(ifname)
|
26
|
-
flags = ifconfig.flags
|
27
|
-
encap = ifconfig.type
|
28
|
-
|
29
|
-
if (flags & Sigar::IFF_UP) == 0
|
30
|
-
next
|
31
|
-
end
|
32
|
-
|
33
|
-
hwaddr = ifconfig.hwaddr
|
34
|
-
if hwaddr == Sigar::NULL_HWADDR
|
35
|
-
hwaddr = ""
|
36
|
-
else
|
37
|
-
hwaddr = " HWaddr " + hwaddr
|
38
|
-
end
|
39
|
-
|
40
|
-
puts ifname + "\t" + "Link encap:" + encap + hwaddr
|
41
|
-
|
42
|
-
if (flags & Sigar::IFF_POINTOPOINT) != 0
|
43
|
-
ptp = " P-t-P:" + ifconfig.destination
|
44
|
-
else
|
45
|
-
ptp = ""
|
46
|
-
end
|
47
|
-
|
48
|
-
if (flags & Sigar::IFF_BROADCAST) != 0
|
49
|
-
bcast = " Bcast:" + ifconfig.broadcast
|
50
|
-
else
|
51
|
-
bcast = ""
|
52
|
-
end
|
53
|
-
|
54
|
-
address = ifconfig.address
|
55
|
-
if address != "0.0.0.0"
|
56
|
-
puts "\t" + "inet addr:" + address +
|
57
|
-
ptp + bcast + " Mask:" + ifconfig.netmask
|
58
|
-
end
|
59
|
-
|
60
|
-
if ifconfig.prefix6_length != 0
|
61
|
-
puts "\t" + "inet6 addr: " + ifconfig.address6 + "/" +
|
62
|
-
ifconfig.prefix6_length.to_s + " Scope:" + Sigar.net_scope_to_s(ifconfig.scope6)
|
63
|
-
end
|
64
|
-
|
65
|
-
puts "\t" +
|
66
|
-
Sigar.net_interface_flags_to_s(flags) +
|
67
|
-
" MTU:" + ifconfig.mtu.to_s +
|
68
|
-
" Metric:" + ifconfig.metric.to_s
|
69
|
-
|
70
|
-
if (!ifname.include?(":"))
|
71
|
-
ifstat = sigar.net_interface_stat(ifname)
|
72
|
-
puts "\t" +
|
73
|
-
"RX packets:" + ifstat.rx_packets.to_s +
|
74
|
-
" errors:" + ifstat.rx_errors.to_s +
|
75
|
-
" dropped:" + ifstat.rx_dropped.to_s +
|
76
|
-
" overruns:" + ifstat.rx_overruns.to_s +
|
77
|
-
" frame:" + ifstat.rx_frame.to_s
|
78
|
-
|
79
|
-
puts "\t" +
|
80
|
-
"TX packets:" + ifstat.tx_packets.to_s +
|
81
|
-
" errors:" + ifstat.tx_errors.to_s +
|
82
|
-
" dropped:" + ifstat.tx_dropped.to_s +
|
83
|
-
" overruns:" + ifstat.tx_overruns.to_s +
|
84
|
-
" carrier:" + ifstat.tx_carrier.to_s
|
85
|
-
|
86
|
-
puts "\t" + "collisions:" + ifstat.tx_collisions.to_s +
|
87
|
-
" txqueuelen:" + ifconfig.tx_queue_len.to_s
|
88
|
-
|
89
|
-
rx_bytes = ifstat.rx_bytes
|
90
|
-
tx_bytes = ifstat.tx_bytes
|
91
|
-
|
92
|
-
puts "\t" +
|
93
|
-
"RX bytes:" + rx_bytes.to_s +
|
94
|
-
" (" + Sigar.format_size(rx_bytes) + ")" +
|
95
|
-
" " +
|
96
|
-
"TX bytes:" + tx_bytes.to_s +
|
97
|
-
" (" + Sigar.format_size(tx_bytes) + ")" + "\n"
|
98
|
-
end
|
99
|
-
|
100
|
-
puts "\n"
|
101
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2009 SpringSource, Inc.
|
3
|
-
# Copyright (c) 2010 VMware, Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
# Example illustrating the use of the optional logger.
|
19
|
-
|
20
|
-
require 'sigar'
|
21
|
-
require 'logger'
|
22
|
-
|
23
|
-
sigar = Sigar.new
|
24
|
-
sigar.log_level = Sigar::LOG_DEBUG
|
25
|
-
|
26
|
-
logger = Logger.new(STDERR)
|
27
|
-
logger.datetime_format = "%H:%M:%S"
|
28
|
-
|
29
|
-
# Call something that has DEBUG level logging.
|
30
|
-
fslist = sigar.file_system_list
|
31
|
-
|
32
|
-
# cache data
|
33
|
-
fslist.each do |fs|
|
34
|
-
dir_name = fs.dir_name
|
35
|
-
usage = sigar.file_system_usage(dir_name)
|
36
|
-
end
|
37
|
-
|
38
|
-
puts "Calling file_system_usage() for each filesystem"
|
39
|
-
|
40
|
-
puts "\nwith Logger:"
|
41
|
-
|
42
|
-
sigar.logger = logger
|
43
|
-
|
44
|
-
fslist.each do |fs|
|
45
|
-
dir_name = fs.dir_name
|
46
|
-
usage = sigar.file_system_usage(dir_name)
|
47
|
-
end
|
48
|
-
|
49
|
-
puts "\nwith Proc:"
|
50
|
-
|
51
|
-
sigar.logger = Proc.new do |level, msg|
|
52
|
-
puts "Level #{level}: #{msg}"
|
53
|
-
end
|
54
|
-
|
55
|
-
fslist.each do |fs|
|
56
|
-
dir_name = fs.dir_name
|
57
|
-
usage = sigar.file_system_usage(dir_name)
|
58
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2009-2010 VMware, Inc.
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
#
|
16
|
-
|
17
|
-
# Example illustrating the collecting of network information.
|
18
|
-
|
19
|
-
require 'sigar'
|
20
|
-
|
21
|
-
sigar = Sigar.new
|
22
|
-
|
23
|
-
ninfo = sigar.net_info
|
24
|
-
|
25
|
-
puts "Hostname: " + ninfo.host_name
|
26
|
-
puts "Domain Name: " + ninfo.domain_name
|
27
|
-
puts "FQDN: " + sigar.fqdn
|
28
|
-
puts "Default gateway: " + ninfo.default_gateway
|
29
|
-
puts "Default gateway interface: " + ninfo.default_gateway_interface
|
30
|
-
puts "Primary DNS: " + ninfo.primary_dns
|
31
|
-
puts "Secondary DNS: " + ninfo.secondary_dns
|
@@ -1,71 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright (c) 2007 Hyperic, Inc.
|
3
|
-
# Copyright (c) 2010 VMware, Inc.
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require 'sigar'
|
19
|
-
require 'socket'
|
20
|
-
|
21
|
-
#XXX this example is incomplete wrt:
|
22
|
-
#../../java/src/org/hyperic/sigar/cmd/Netstat.java
|
23
|
-
|
24
|
-
is_numeric = false
|
25
|
-
flags = Sigar::NETCONN_CLIENT|Sigar::NETCONN_SERVER
|
26
|
-
flags |= Sigar::NETCONN_TCP
|
27
|
-
|
28
|
-
def format_port(sigar, proto, port, is_numeric)
|
29
|
-
if port == 0
|
30
|
-
return "*"
|
31
|
-
end
|
32
|
-
if !is_numeric
|
33
|
-
service = sigar.net_services_name(proto, port)
|
34
|
-
if service != nil
|
35
|
-
return service
|
36
|
-
end
|
37
|
-
end
|
38
|
-
port.to_s
|
39
|
-
end
|
40
|
-
|
41
|
-
def format_address(sigar, proto, ip, portnum, is_numeric)
|
42
|
-
port = format_port(sigar, proto, portnum, is_numeric)
|
43
|
-
address = ""
|
44
|
-
if ip == "0.0.0.0" || ip == "::"
|
45
|
-
address = "*"
|
46
|
-
elsif is_numeric
|
47
|
-
address = ip.to_s
|
48
|
-
else
|
49
|
-
begin
|
50
|
-
name = Socket.gethostbyname(ip)
|
51
|
-
address = name[0]
|
52
|
-
rescue SocketError
|
53
|
-
address = ip.to_s
|
54
|
-
end
|
55
|
-
end
|
56
|
-
return address + ":" + port
|
57
|
-
end
|
58
|
-
|
59
|
-
sigar = Sigar.new
|
60
|
-
|
61
|
-
connections = sigar.net_connection_list(flags)
|
62
|
-
puts "Proto\tLocal Address\tForeign Address\tState"
|
63
|
-
|
64
|
-
connections.each do |conn|
|
65
|
-
proto = Sigar.net_connection_type_to_s(conn.type)
|
66
|
-
state = Sigar.net_connection_state_to_s(conn.state)
|
67
|
-
local = format_address(sigar, conn.type, conn.local_address, conn.local_port, is_numeric)
|
68
|
-
remote = format_address(sigar, conn.type, conn.remote_address, conn.remote_port, is_numeric)
|
69
|
-
puts proto + "\t" + local + "\t" + remote + "\t" + state
|
70
|
-
end
|
71
|
-
|