vmstat 0.1.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +100 -110
- data/ext/vmstat/vmstat.c +133 -140
- data/ext/vmstat/vmstat.h +11 -18
- data/lib/vmstat.rb +79 -37
- data/lib/vmstat/cpu.rb +4 -0
- data/lib/vmstat/disk.rb +20 -0
- data/lib/vmstat/load_average.rb +4 -0
- data/lib/vmstat/memory.rb +24 -0
- data/lib/vmstat/network_interface.rb +19 -0
- data/lib/vmstat/snapshot.rb +17 -0
- data/lib/vmstat/task.rb +6 -0
- data/lib/vmstat/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/vmstat/cpu_spec.rb +34 -0
- data/spec/vmstat/disk_spec.rb +32 -0
- data/spec/vmstat/load_average_spec.rb +23 -0
- data/spec/vmstat/memory_spec.rb +44 -0
- data/spec/vmstat/network_spec.rb +38 -0
- data/spec/vmstat/snapshot_spec.rb +49 -0
- data/spec/vmstat/task_spec.rb +28 -0
- data/spec/vmstat_spec.rb +20 -161
- metadata +25 -4
data/README.md
CHANGED
@@ -3,10 +3,11 @@
|
|
3
3
|
This is a focused and fast library to get system information like:
|
4
4
|
|
5
5
|
* _Memory_ (free, active, ...)
|
6
|
-
* _Network
|
6
|
+
* _Network Interfaces_ (name, in bytes, out bytes, ...)
|
7
7
|
* _CPU_ (user, system, nice, idle)
|
8
8
|
* _Load_ Average
|
9
9
|
* _Disk_ (type, disk path, free bytes, total bytes, ...)
|
10
|
+
* _Current Task_ (used bytes and usage time *MAC OS X ONLY*)
|
10
11
|
|
11
12
|
*It currently supports:*
|
12
13
|
|
@@ -34,117 +35,106 @@ Or install it yourself as:
|
|
34
35
|
|
35
36
|
## Usage
|
36
37
|
|
37
|
-
Just require the library.
|
38
|
+
Just require the library and make a snapshot or use the distinct methods to just capture parts of the statistics.
|
38
39
|
|
39
40
|
require "vmstat"
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
#
|
134
|
-
|
135
|
-
|
136
|
-
#
|
137
|
-
Vmstat.disk("/dev/disk0s2") # => {...}
|
138
|
-
|
139
|
-
The result looks like this:
|
140
|
-
|
141
|
-
{:type => :devfs,
|
142
|
-
:origin => "devfs",
|
143
|
-
:mount => "/dev",
|
144
|
-
:free_bytes => 0,
|
145
|
-
:available_bytes => 0,
|
146
|
-
:used_bytes => 192000,
|
147
|
-
:total_bytes => 192000}
|
41
|
+
require "pp"
|
42
|
+
Vmstat.snapshot # => #<Vmstat::Snapshot:0x007fe5f22df660
|
43
|
+
# @at=2012-10-09 21:48:57 +0200,
|
44
|
+
# @boot_time=2012-10-09 18:42:37 +0200,
|
45
|
+
# @cpu=
|
46
|
+
# [#<struct Vmstat::Cpu
|
47
|
+
# num=0,
|
48
|
+
# user=187167,
|
49
|
+
# system=144466,
|
50
|
+
# nice=0,
|
51
|
+
# idle=786622>,
|
52
|
+
# #<struct Vmstat::Cpu num=1, user=2819, system=1641, nice=0, idle=1113782>,
|
53
|
+
# #<struct Vmstat::Cpu num=2, user=158698, system=95186, nice=0, idle=864359>,
|
54
|
+
# #<struct Vmstat::Cpu num=3, user=2702, system=1505, nice=0, idle=1114035>,
|
55
|
+
# #<struct Vmstat::Cpu num=4, user=140231, system=78248, nice=0, idle=899764>,
|
56
|
+
# #<struct Vmstat::Cpu num=5, user=2468, system=1314, nice=0, idle=1114460>,
|
57
|
+
# #<struct Vmstat::Cpu num=6, user=120764, system=66284, nice=0, idle=931195>,
|
58
|
+
# #<struct Vmstat::Cpu num=7, user=2298, system=1207, nice=0, idle=1114737>],
|
59
|
+
# @disks=
|
60
|
+
# [#<struct Vmstat::Disk
|
61
|
+
# type=:hfs,
|
62
|
+
# origin="/dev/disk0s2",
|
63
|
+
# mount="/",
|
64
|
+
# block_size=4096,
|
65
|
+
# free_blocks=51470668,
|
66
|
+
# available_blocks=51406668,
|
67
|
+
# total_blocks=61069442>],
|
68
|
+
# @load_average=
|
69
|
+
# #<struct Vmstat::LoadAverage
|
70
|
+
# one_minute=1.74072265625,
|
71
|
+
# five_minutes=1.34326171875,
|
72
|
+
# fifteen_minutes=1.1845703125>,
|
73
|
+
# @memory=
|
74
|
+
# #<struct Vmstat::Memory
|
75
|
+
# pagesize=4096,
|
76
|
+
# wired=1037969,
|
77
|
+
# active=101977,
|
78
|
+
# inactive=484694,
|
79
|
+
# free=470582,
|
80
|
+
# pageins=102438,
|
81
|
+
# pageouts=0,
|
82
|
+
# zero_filled=930821373,
|
83
|
+
# reactivated=33,
|
84
|
+
# purgeable=88184,
|
85
|
+
# purged=0,
|
86
|
+
# faults=90277275,
|
87
|
+
# copy_on_write_faults=668693,
|
88
|
+
# lookups=516021,
|
89
|
+
# hits=17>,
|
90
|
+
# @network_interfaces=
|
91
|
+
# [#<struct Vmstat::NetworkInterface
|
92
|
+
# name=:lo0,
|
93
|
+
# in_bytes=6209398,
|
94
|
+
# in_errors=0,
|
95
|
+
# in_drops=0,
|
96
|
+
# out_bytes=6209398,
|
97
|
+
# out_errors=0,
|
98
|
+
# type=24>,
|
99
|
+
# #<struct Vmstat::NetworkInterface
|
100
|
+
# name=:gif0,
|
101
|
+
# in_bytes=0,
|
102
|
+
# in_errors=0,
|
103
|
+
# in_drops=0,
|
104
|
+
# out_bytes=0,
|
105
|
+
# out_errors=0,
|
106
|
+
# type=55>,
|
107
|
+
# #<struct Vmstat::NetworkInterface
|
108
|
+
# name=:stf0,
|
109
|
+
# in_bytes=0,
|
110
|
+
# in_errors=0,
|
111
|
+
# in_drops=0,
|
112
|
+
# out_bytes=0,
|
113
|
+
# out_errors=0,
|
114
|
+
# type=57>,
|
115
|
+
# #<struct Vmstat::NetworkInterface
|
116
|
+
# name=:en0,
|
117
|
+
# in_bytes=1321276010,
|
118
|
+
# in_errors=0,
|
119
|
+
# in_drops=0,
|
120
|
+
# out_bytes=410426678,
|
121
|
+
# out_errors=0,
|
122
|
+
# type=6>,
|
123
|
+
# #<struct Vmstat::NetworkInterface
|
124
|
+
# name=:p2p0,
|
125
|
+
# in_bytes=0,
|
126
|
+
# in_errors=0,
|
127
|
+
# in_drops=0,
|
128
|
+
# out_bytes=0,
|
129
|
+
# out_errors=0,
|
130
|
+
# type=6>],
|
131
|
+
# @task=
|
132
|
+
# #<struct Vmstat::Task
|
133
|
+
# suspend_count=0,
|
134
|
+
# virtual_size=2551554048,
|
135
|
+
# resident_size=19628032,
|
136
|
+
# user_time_ms=28,
|
137
|
+
# system_time_ms=83>>
|
148
138
|
|
149
139
|
## Contributing
|
150
140
|
|
data/ext/vmstat/vmstat.c
CHANGED
@@ -8,66 +8,30 @@
|
|
8
8
|
#include <sys/mount.h>
|
9
9
|
#if defined(__APPLE__)
|
10
10
|
#include <mach/mach.h>
|
11
|
+
#include <mach/mach_host.h>
|
11
12
|
#endif
|
12
13
|
#include <vmstat.h>
|
13
14
|
|
15
|
+
// helper methodsd
|
16
|
+
int system_int(const char *);
|
17
|
+
unsigned long long system_ull(const char *);
|
18
|
+
|
14
19
|
void Init_vmstat() {
|
15
20
|
vmstat = rb_define_module("Vmstat");
|
16
21
|
|
17
|
-
rb_define_singleton_method(vmstat, "
|
18
|
-
rb_define_singleton_method(vmstat, "cpu",
|
19
|
-
rb_define_singleton_method(vmstat, "memory",
|
20
|
-
rb_define_singleton_method(vmstat, "disk",
|
21
|
-
rb_define_singleton_method(vmstat, "
|
22
|
-
rb_define_singleton_method(vmstat, "boot_time",
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
SYM_FREE = ID2SYM(rb_intern("free"));
|
27
|
-
|
28
|
-
// network symbols
|
29
|
-
SYM_IN_BYTES = ID2SYM(rb_intern("in_bytes"));
|
30
|
-
SYM_IN_ERRORS = ID2SYM(rb_intern("in_errors"));
|
31
|
-
SYM_IN_DROPS = ID2SYM(rb_intern("in_drops"));
|
32
|
-
SYM_OUT_BYTES = ID2SYM(rb_intern("out_bytes"));
|
33
|
-
SYM_OUT_ERRORS = ID2SYM(rb_intern("out_errors"));
|
34
|
-
|
35
|
-
// cpu symbols
|
36
|
-
SYM_USER = ID2SYM(rb_intern("user"));
|
37
|
-
SYM_SYSTEM = ID2SYM(rb_intern("system"));
|
38
|
-
SYM_NICE = ID2SYM(rb_intern("nice"));
|
39
|
-
SYM_IDLE = ID2SYM(rb_intern("idle"));
|
40
|
-
|
41
|
-
// memory symbols
|
42
|
-
SYM_PAGESIZE = ID2SYM(rb_intern("pagesize"));
|
43
|
-
SYM_WIRED = ID2SYM(rb_intern("wired"));
|
44
|
-
SYM_ACTIVE = ID2SYM(rb_intern("active"));
|
45
|
-
SYM_INACTIVE = ID2SYM(rb_intern("inactive"));
|
46
|
-
SYM_WIRED_BYTES = ID2SYM(rb_intern("wired_bytes"));
|
47
|
-
SYM_ACTIVE_BYTES = ID2SYM(rb_intern("active_bytes"));
|
48
|
-
SYM_INACTIVE_BYTES = ID2SYM(rb_intern("inactive_bytes"));
|
49
|
-
SYM_FREE_BYTES = ID2SYM(rb_intern("free_bytes"));
|
50
|
-
SYM_ZERO_FILLED = ID2SYM(rb_intern("zero_filled"));
|
51
|
-
SYM_REACTIVATED = ID2SYM(rb_intern("reactivated"));
|
52
|
-
SYM_PURGEABLE = ID2SYM(rb_intern("purgeable"));
|
53
|
-
SYM_PURGED = ID2SYM(rb_intern("purged"));
|
54
|
-
SYM_PAGEINS = ID2SYM(rb_intern("pageins"));
|
55
|
-
SYM_PAGEOUTS = ID2SYM(rb_intern("pageouts"));
|
56
|
-
SYM_FAULTS = ID2SYM(rb_intern("faults"));
|
57
|
-
SYM_COW_FAULTS = ID2SYM(rb_intern("copy_on_write_faults"));
|
58
|
-
SYM_LOOKUPS = ID2SYM(rb_intern("lookups"));
|
59
|
-
SYM_HITS = ID2SYM(rb_intern("hits"));
|
60
|
-
|
61
|
-
// disk symbols
|
62
|
-
SYM_ORIGIN = ID2SYM(rb_intern("origin"));
|
63
|
-
SYM_MOUNT = ID2SYM(rb_intern("mount"));
|
64
|
-
SYM_AVAILABLE_BYTES = ID2SYM(rb_intern("available_bytes"));
|
65
|
-
SYM_USED_BYTES = ID2SYM(rb_intern("used_bytes"));
|
66
|
-
SYM_TOTAL_BYTES = ID2SYM(rb_intern("total_bytes"));
|
22
|
+
rb_define_singleton_method(vmstat, "network_interfaces", vmstat_network_interfaces, 0);
|
23
|
+
rb_define_singleton_method(vmstat, "cpu", vmstat_cpu, 0);
|
24
|
+
rb_define_singleton_method(vmstat, "memory", vmstat_memory, 0);
|
25
|
+
rb_define_singleton_method(vmstat, "disk", vmstat_disk, 1);
|
26
|
+
rb_define_singleton_method(vmstat, "load_average", vmstat_load_average, 0);
|
27
|
+
rb_define_singleton_method(vmstat, "boot_time", vmstat_boot_time, 0);
|
28
|
+
#if defined(__APPLE__)
|
29
|
+
rb_define_singleton_method(vmstat, "task", vmstat_task, 0);
|
30
|
+
#endif
|
67
31
|
}
|
68
32
|
|
69
|
-
VALUE
|
70
|
-
VALUE devices =
|
33
|
+
VALUE vmstat_network_interfaces(VALUE self) {
|
34
|
+
VALUE devices = rb_ary_new();
|
71
35
|
int i, err;
|
72
36
|
struct ifmibdata mibdata;
|
73
37
|
size_t len = sizeof(mibdata);
|
@@ -79,14 +43,16 @@ VALUE method_network(VALUE self) {
|
|
79
43
|
ifmib_path[4] = i; // set the current row
|
80
44
|
err = sysctl(ifmib_path, 6, &mibdata, &len, NULL, 0);
|
81
45
|
if (err == 0) {
|
82
|
-
VALUE device =
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
46
|
+
VALUE device = rb_funcall(rb_path2class("Vmstat::NetworkInterface"),
|
47
|
+
rb_intern("new"), 7, ID2SYM(rb_intern(mibdata.ifmd_name)),
|
48
|
+
ULL2NUM(mibdata.ifmd_data.ifi_ibytes),
|
49
|
+
ULL2NUM(mibdata.ifmd_data.ifi_ierrors),
|
50
|
+
ULL2NUM(mibdata.ifmd_data.ifi_iqdrops),
|
51
|
+
ULL2NUM(mibdata.ifmd_data.ifi_obytes),
|
52
|
+
ULL2NUM(mibdata.ifmd_data.ifi_oerrors),
|
53
|
+
ULL2NUM(mibdata.ifmd_data.ifi_type));
|
54
|
+
|
55
|
+
rb_ary_push(devices, device);
|
90
56
|
}
|
91
57
|
}
|
92
58
|
|
@@ -94,7 +60,7 @@ VALUE method_network(VALUE self) {
|
|
94
60
|
}
|
95
61
|
|
96
62
|
#if defined(__APPLE__)
|
97
|
-
VALUE
|
63
|
+
VALUE vmstat_cpu(VALUE self) {
|
98
64
|
VALUE cpus = rb_ary_new();
|
99
65
|
processor_info_array_t cpuInfo;
|
100
66
|
mach_msg_type_number_t numCpuInfo;
|
@@ -104,21 +70,29 @@ VALUE method_cpu(VALUE self) {
|
|
104
70
|
|
105
71
|
if(err == KERN_SUCCESS) {
|
106
72
|
unsigned i;
|
73
|
+
|
107
74
|
for(i = 0U; i < numCPUsU; ++i) {
|
108
|
-
VALUE cpu = rb_hash_new();
|
109
75
|
int pos = CPU_STATE_MAX * i;
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
76
|
+
VALUE cpu = rb_funcall(rb_path2class("Vmstat::Cpu"),
|
77
|
+
rb_intern("new"), 5, ULL2NUM(i),
|
78
|
+
ULL2NUM(cpuInfo[pos + CPU_STATE_USER]),
|
79
|
+
ULL2NUM(cpuInfo[pos + CPU_STATE_SYSTEM]),
|
80
|
+
ULL2NUM(cpuInfo[pos + CPU_STATE_NICE]),
|
81
|
+
ULL2NUM(cpuInfo[pos + CPU_STATE_IDLE]));
|
114
82
|
rb_ary_push(cpus, cpu);
|
115
83
|
}
|
84
|
+
|
85
|
+
err = vm_deallocate(mach_task_self(), (vm_address_t)cpuInfo,
|
86
|
+
(vm_size_t)sizeof(*cpuInfo) * numCpuInfo);
|
87
|
+
if (err != KERN_SUCCESS) {
|
88
|
+
rb_bug("vm_deallocate: %s\n", mach_error_string(err));
|
89
|
+
}
|
116
90
|
}
|
117
91
|
|
118
92
|
return cpus;
|
119
93
|
}
|
120
94
|
|
121
|
-
VALUE
|
95
|
+
VALUE vmstat_memory(VALUE self) {
|
122
96
|
VALUE memory = Qnil;
|
123
97
|
vm_size_t pagesize;
|
124
98
|
uint host_count = HOST_VM_INFO_COUNT;
|
@@ -130,31 +104,54 @@ VALUE method_memory(VALUE self) {
|
|
130
104
|
err = host_statistics(mach_host_self(), HOST_VM_INFO,
|
131
105
|
(host_info_t)&vm_stat, &host_count);
|
132
106
|
if (err == KERN_SUCCESS) {
|
133
|
-
memory =
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
107
|
+
memory = rb_funcall(rb_path2class("Vmstat::Memory"),
|
108
|
+
rb_intern("new"), 15, ULL2NUM(pagesize),
|
109
|
+
ULL2NUM(vm_stat.active_count),
|
110
|
+
ULL2NUM(vm_stat.inactive_count),
|
111
|
+
ULL2NUM(vm_stat.wire_count),
|
112
|
+
ULL2NUM(vm_stat.free_count),
|
113
|
+
ULL2NUM(vm_stat.pageins),
|
114
|
+
ULL2NUM(vm_stat.pageouts),
|
115
|
+
ULL2NUM(vm_stat.zero_fill_count),
|
116
|
+
ULL2NUM(vm_stat.reactivations),
|
117
|
+
ULL2NUM(vm_stat.purgeable_count),
|
118
|
+
ULL2NUM(vm_stat.purges),
|
119
|
+
ULL2NUM(vm_stat.faults),
|
120
|
+
ULL2NUM(vm_stat.cow_faults),
|
121
|
+
ULL2NUM(vm_stat.lookups),
|
122
|
+
ULL2NUM(vm_stat.hits));
|
123
|
+
}
|
124
|
+
|
125
|
+
err = vm_deallocate(mach_task_self(), (vm_address_t)pagesize,
|
126
|
+
(vm_size_t)host_count);
|
127
|
+
if (err != KERN_SUCCESS) {
|
128
|
+
rb_bug("vm_deallocate: %s\n", mach_error_string(err));
|
153
129
|
}
|
154
130
|
}
|
155
|
-
|
131
|
+
|
156
132
|
return memory;
|
157
133
|
}
|
134
|
+
|
135
|
+
VALUE vmstat_task(VALUE self) {
|
136
|
+
VALUE task = Qnil;
|
137
|
+
struct task_basic_info info;
|
138
|
+
kern_return_t err;
|
139
|
+
mach_msg_type_number_t size = sizeof(info);
|
140
|
+
|
141
|
+
err = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
|
142
|
+
if (err == KERN_SUCCESS) {
|
143
|
+
task = rb_funcall(rb_path2class("Vmstat::Task"),
|
144
|
+
rb_intern("new"), 5, LONG2NUM(info.suspend_count),
|
145
|
+
LONG2NUM(info.virtual_size),
|
146
|
+
LONG2NUM(info.resident_size),
|
147
|
+
LONG2NUM(info.user_time.seconds * 1000 + info.user_time.microseconds),
|
148
|
+
LONG2NUM(info.system_time.seconds * 1000 + info.system_time.microseconds));
|
149
|
+
} else {
|
150
|
+
rb_bug("task_info: %s\n", mach_error_string(err));
|
151
|
+
}
|
152
|
+
|
153
|
+
return task;
|
154
|
+
}
|
158
155
|
#elif __linux
|
159
156
|
// linux
|
160
157
|
#elif __unix // all unices not caught above
|
@@ -166,98 +163,94 @@ typedef struct {
|
|
166
163
|
long idle;
|
167
164
|
} cpu_time_t;
|
168
165
|
|
169
|
-
VALUE
|
166
|
+
VALUE vmstat_cpu(VALUE self) {
|
170
167
|
VALUE cpus = rb_ary_new();
|
171
168
|
int cpu_count = system_int("hw.ncpu");
|
172
169
|
size_t len = sizeof(cpu_time_t) * cpu_count;
|
173
170
|
cpu_time_t * cp_times = ALLOC_N(cpu_time_t, cpu_count);
|
171
|
+
cpu_time_t * cp_time;
|
174
172
|
int i;
|
175
173
|
|
176
174
|
if (sysctlbyname("kern.cp_times", cp_times, &len, NULL, 0) == 0) {
|
177
175
|
for (i = 0; i < cpu_count; i++) {
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
176
|
+
cp_time = &cp_times[i];
|
177
|
+
VALUE cpu = rb_funcall(rb_path2class("Vmstat::Cpu"),
|
178
|
+
rb_intern("new"), 5, ULL2NUM(i),
|
179
|
+
ULL2NUM(cp_time->user),
|
180
|
+
ULL2NUM(cp_time->system + cp_time->intr),
|
181
|
+
ULL2NUM(cp_time->nice),
|
182
|
+
ULL2NUM(cp_time->idle));
|
184
183
|
rb_ary_push(cpus, cpu);
|
185
184
|
}
|
186
185
|
}
|
186
|
+
|
187
187
|
free(cp_times);
|
188
188
|
|
189
189
|
return cpus;
|
190
190
|
}
|
191
191
|
|
192
|
-
VALUE
|
193
|
-
VALUE memory =
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
rb_hash_aset(memory, SYM_PURGED, Qnil);
|
210
|
-
rb_hash_aset(memory, SYM_PAGEINS, Qnil);
|
211
|
-
rb_hash_aset(memory, SYM_PAGEOUTS, Qnil);
|
212
|
-
rb_hash_aset(memory, SYM_FAULTS, ULL2NUM(system_ull("vm.stats.vm.v_vm_faults")));
|
213
|
-
rb_hash_aset(memory, SYM_COW_FAULTS, ULL2NUM(system_ull("vm.stats.vm.v_cow_faults")));
|
214
|
-
rb_hash_aset(memory, SYM_LOOKUPS, Qnil);
|
215
|
-
rb_hash_aset(memory, SYM_HITS, Qnil);
|
216
|
-
|
192
|
+
VALUE vmstat_memory(VALUE self) {
|
193
|
+
VALUE memory = rb_funcall(rb_path2class("Vmstat::Memory"),
|
194
|
+
rb_intern("new"), 15, ULL2NUM(system_ull("vm.stats.vm.v_page_size")),
|
195
|
+
ULL2NUM(system_ull("vm.stats.vm.v_active_count")),
|
196
|
+
ULL2NUM(system_ull("vm.stats.vm.v_wire_count")),
|
197
|
+
ULL2NUM(system_ull("vm.stats.vm.v_inactive_count")),
|
198
|
+
ULL2NUM(system_ull("vm.stats.vm.v_free_count")),
|
199
|
+
ULL2NUM(Qnil),
|
200
|
+
ULL2NUM(Qnil),
|
201
|
+
ULL2NUM(system_ull("vm.stats.misc.zero_page_count")),
|
202
|
+
ULL2NUM(system_ull("vm.stats.vm.v_reactivated")),
|
203
|
+
ULL2NUM(Qnil),
|
204
|
+
ULL2NUM(Qnil),
|
205
|
+
ULL2NUM(system_ull("vm.stats.vm.v_vm_faults")),
|
206
|
+
ULL2NUM(system_ull("vm.stats.vm.v_cow_faults")),
|
207
|
+
ULL2NUM(Qnil),
|
208
|
+
ULL2NUM(Qnil));
|
217
209
|
return memory;
|
218
210
|
}
|
219
211
|
#elif __posix
|
220
212
|
// POSIX
|
221
213
|
#endif
|
222
214
|
|
223
|
-
VALUE
|
215
|
+
VALUE vmstat_disk(VALUE self, VALUE path) {
|
224
216
|
VALUE disk = Qnil;
|
225
217
|
struct statfs stat;
|
226
218
|
|
227
219
|
if (statfs(StringValueCStr(path), &stat) != -1) {
|
228
|
-
disk =
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
220
|
+
disk = rb_funcall(rb_path2class("Vmstat::Disk"),
|
221
|
+
rb_intern("new"), 7, ID2SYM(rb_intern(stat.f_fstypename)),
|
222
|
+
rb_str_new(stat.f_mntfromname, strlen(stat.f_mntfromname)),
|
223
|
+
rb_str_new(stat.f_mntonname, strlen(stat.f_mntonname)),
|
224
|
+
ULL2NUM(stat.f_bsize),
|
225
|
+
ULL2NUM(stat.f_bfree),
|
226
|
+
ULL2NUM(stat.f_bavail),
|
227
|
+
ULL2NUM(stat.f_blocks));
|
236
228
|
}
|
237
229
|
|
238
230
|
return disk;
|
239
231
|
}
|
240
232
|
|
241
|
-
|
242
|
-
VALUE
|
243
|
-
VALUE loads = rb_ary_new();
|
233
|
+
VALUE vmstat_load_average(VALUE self) {
|
234
|
+
VALUE load = Qnil;
|
244
235
|
double loadavg[AVGCOUNT];
|
245
|
-
int i;
|
246
236
|
|
247
237
|
getloadavg(&loadavg[0], AVGCOUNT);
|
248
|
-
for(i = 0; i < AVGCOUNT; i++) {
|
249
|
-
rb_ary_push(loads, rb_float_new(loadavg[i]));
|
250
|
-
}
|
251
238
|
|
252
|
-
|
239
|
+
load = rb_funcall(rb_path2class("Vmstat::LoadAverage"),
|
240
|
+
rb_intern("new"), 3, rb_float_new(loadavg[0]),
|
241
|
+
rb_float_new(loadavg[1]),
|
242
|
+
rb_float_new(loadavg[2]));
|
243
|
+
|
244
|
+
return load;
|
253
245
|
}
|
254
246
|
|
255
|
-
|
247
|
+
static int BOOT_TIME_MIB[] = { CTL_KERN, KERN_BOOTTIME };
|
248
|
+
|
249
|
+
VALUE vmstat_boot_time(VALUE self) {
|
256
250
|
struct timeval tv;
|
257
251
|
size_t size = sizeof(tv);
|
258
|
-
static int which[] = { CTL_KERN, KERN_BOOTTIME };
|
259
252
|
|
260
|
-
if (sysctl(
|
253
|
+
if (sysctl(BOOT_TIME_MIB, 2, &tv, &size, NULL, 0) == 0) {
|
261
254
|
return rb_time_new(tv.tv_sec, tv.tv_usec);
|
262
255
|
} else {
|
263
256
|
return Qnil;
|