vmstat 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/README.md +6 -15
- data/Rakefile +1 -1
- data/ext/vmstat/hw/bsd.h +14 -22
- data/ext/vmstat/hw/mach.h +8 -17
- data/lib/vmstat.rb +11 -2
- data/lib/vmstat/cpu.rb +11 -0
- data/lib/vmstat/disk.rb +24 -0
- data/lib/vmstat/linux_disk.rb +10 -3
- data/lib/vmstat/load_average.rb +7 -0
- data/lib/vmstat/memory.rb +25 -6
- data/lib/vmstat/network_interface.rb +14 -0
- data/lib/vmstat/procfs.rb +21 -1
- data/lib/vmstat/snapshot.rb +18 -2
- data/lib/vmstat/stub.rb +3 -0
- data/lib/vmstat/task.rb +10 -2
- data/lib/vmstat/version.rb +1 -1
- data/spec/procfs/self/stat +1 -0
- data/spec/vmstat/cpu_spec.rb +1 -1
- data/spec/vmstat/disk_spec.rb +21 -1
- data/spec/vmstat/load_average_spec.rb +1 -1
- data/spec/vmstat/memory_spec.rb +29 -10
- data/spec/vmstat/network_spec.rb +1 -1
- data/spec/vmstat/procfs_spec.rb +13 -3
- data/spec/vmstat/snapshot_spec.rb +4 -4
- data/spec/vmstat/task_spec.rb +1 -3
- data/spec/vmstat_spec.rb +1 -1
- data/vmstat.gemspec +3 -2
- metadata +25 -6
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Vmstat
|
1
|
+
# Vmstat [![Build Status](https://secure.travis-ci.org/threez/ruby-vmstat.png)](http://travis-ci.org/threez/ruby-vmstat) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/threez/ruby-vmstat)
|
2
2
|
|
3
3
|
This is a focused and fast library to get system information like:
|
4
4
|
|
@@ -7,8 +7,8 @@ This is a focused and fast library to get system information like:
|
|
7
7
|
* _CPU_ (user, system, nice, idle)
|
8
8
|
* _Load_ Average
|
9
9
|
* _Disk_ (type, disk path, free bytes, total bytes, ...)
|
10
|
-
* _Boot
|
11
|
-
* _Current Task_ (used bytes and usage time *MAC OS X ONLY*)
|
10
|
+
* _Boot Time_
|
11
|
+
* _Current Task_ (used bytes and usage time *MAC OS X / Linux ONLY*)
|
12
12
|
|
13
13
|
*It currently supports:*
|
14
14
|
|
@@ -45,7 +45,7 @@ Just require the library and make a snapshot or use the distinct methods to just
|
|
45
45
|
Vmstat.snapshot # => #<Vmstat::Snapshot:0x007fe5f22df660
|
46
46
|
# @at=2012-10-09 21:48:57 +0200,
|
47
47
|
# @boot_time=2012-10-09 18:42:37 +0200,
|
48
|
-
# @
|
48
|
+
# @cpus=
|
49
49
|
# [#<struct Vmstat::Cpu
|
50
50
|
# num=0,
|
51
51
|
# user=187167,
|
@@ -81,15 +81,7 @@ Just require the library and make a snapshot or use the distinct methods to just
|
|
81
81
|
# inactive=484694,
|
82
82
|
# free=470582,
|
83
83
|
# pageins=102438,
|
84
|
-
# pageouts=0
|
85
|
-
# zero_filled=930821373,
|
86
|
-
# reactivated=33,
|
87
|
-
# purgeable=88184,
|
88
|
-
# purged=0,
|
89
|
-
# faults=90277275,
|
90
|
-
# copy_on_write_faults=668693,
|
91
|
-
# lookups=516021,
|
92
|
-
# hits=17>,
|
84
|
+
# pageouts=0>,
|
93
85
|
# @network_interfaces=
|
94
86
|
# [#<struct Vmstat::NetworkInterface
|
95
87
|
# name=:lo0,
|
@@ -142,9 +134,8 @@ Just require the library and make a snapshot or use the distinct methods to just
|
|
142
134
|
## Todo
|
143
135
|
|
144
136
|
* Swap information
|
145
|
-
* Reduce the number of memory information gatherd
|
146
137
|
* Support more platforms (hp ux, aix, solaris, ...)
|
147
|
-
* Server performance information (open file handles, cache sizes, ...)
|
138
|
+
* Server performance/system information (open file handles, cache sizes, number of inodes ...)
|
148
139
|
|
149
140
|
## Contributing
|
150
141
|
|
data/Rakefile
CHANGED
data/ext/vmstat/hw/bsd.h
CHANGED
@@ -43,37 +43,29 @@ VALUE vmstat_cpu(VALUE self) {
|
|
43
43
|
|
44
44
|
return cpus;
|
45
45
|
}
|
46
|
+
|
47
|
+
int system_int(const char * name) {
|
48
|
+
int number;
|
49
|
+
size_t number_size = sizeof(number);
|
50
|
+
sysctlbyname(name, &number, &number_size, NULL, 0);
|
51
|
+
return number;
|
52
|
+
}
|
46
53
|
#endif
|
47
54
|
|
48
55
|
#ifndef VMSTAT_MEMORY
|
49
56
|
#define VMSTAT_MEMORY
|
50
57
|
VALUE vmstat_memory(VALUE self) {
|
51
58
|
VALUE memory = rb_funcall(rb_path2class("Vmstat::Memory"),
|
52
|
-
rb_intern("new"),
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
ULL2NUM(system_ull("vm.stats.misc.zero_page_count")),
|
60
|
-
ULL2NUM(system_ull("vm.stats.vm.v_reactivated")),
|
61
|
-
ULL2NUM(Qnil),
|
62
|
-
ULL2NUM(Qnil),
|
63
|
-
ULL2NUM(system_ull("vm.stats.vm.v_vm_faults")),
|
64
|
-
ULL2NUM(system_ull("vm.stats.vm.v_cow_faults")),
|
65
|
-
ULL2NUM(Qnil),
|
66
|
-
ULL2NUM(Qnil));
|
59
|
+
rb_intern("new"), 7, ULL2NUM(system_ull("vm.stats.vm.v_page_size")),
|
60
|
+
ULL2NUM(system_ull("vm.stats.vm.v_active_count")),
|
61
|
+
ULL2NUM(system_ull("vm.stats.vm.v_wire_count")),
|
62
|
+
ULL2NUM(system_ull("vm.stats.vm.v_inactive_count")),
|
63
|
+
ULL2NUM(system_ull("vm.stats.vm.v_free_count")),
|
64
|
+
ULL2NUM(system_ull("vm.stats.vm.v_vnodepgsin")),
|
65
|
+
ULL2NUM(system_ull("vm.stats.vm.v_vnodepgsout")));
|
67
66
|
return memory;
|
68
67
|
}
|
69
68
|
|
70
|
-
int system_int(const char * name) {
|
71
|
-
int number;
|
72
|
-
size_t number_size = sizeof(number);
|
73
|
-
sysctlbyname(name, &number, &number_size, NULL, 0);
|
74
|
-
return number;
|
75
|
-
}
|
76
|
-
|
77
69
|
unsigned long long system_ull(const char * name) {
|
78
70
|
long number;
|
79
71
|
size_t number_size = sizeof(number);
|
data/ext/vmstat/hw/mach.h
CHANGED
@@ -53,21 +53,13 @@ VALUE vmstat_memory(VALUE self) {
|
|
53
53
|
(host_info_t)&vm_stat, &host_count);
|
54
54
|
if (err == KERN_SUCCESS) {
|
55
55
|
memory = rb_funcall(rb_path2class("Vmstat::Memory"),
|
56
|
-
rb_intern("new"),
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
ULL2NUM(vm_stat.zero_fill_count),
|
64
|
-
ULL2NUM(vm_stat.reactivations),
|
65
|
-
ULL2NUM(vm_stat.purgeable_count),
|
66
|
-
ULL2NUM(vm_stat.purges),
|
67
|
-
ULL2NUM(vm_stat.faults),
|
68
|
-
ULL2NUM(vm_stat.cow_faults),
|
69
|
-
ULL2NUM(vm_stat.lookups),
|
70
|
-
ULL2NUM(vm_stat.hits));
|
56
|
+
rb_intern("new"), 7, ULL2NUM(pagesize),
|
57
|
+
ULL2NUM(vm_stat.active_count),
|
58
|
+
ULL2NUM(vm_stat.inactive_count),
|
59
|
+
ULL2NUM(vm_stat.wire_count),
|
60
|
+
ULL2NUM(vm_stat.free_count),
|
61
|
+
ULL2NUM(vm_stat.pageins),
|
62
|
+
ULL2NUM(vm_stat.pageouts));
|
71
63
|
}
|
72
64
|
|
73
65
|
err = vm_deallocate(mach_task_self(), (vm_address_t)pagesize,
|
@@ -92,8 +84,7 @@ VALUE vmstat_task(VALUE self) {
|
|
92
84
|
err = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
|
93
85
|
if (err == KERN_SUCCESS) {
|
94
86
|
task = rb_funcall(rb_path2class("Vmstat::Task"),
|
95
|
-
rb_intern("new"),
|
96
|
-
LONG2NUM(info.virtual_size),
|
87
|
+
rb_intern("new"), 4, LONG2NUM(info.virtual_size),
|
97
88
|
LONG2NUM(info.resident_size),
|
98
89
|
LONG2NUM(info.user_time.seconds * 1000 + info.user_time.microseconds),
|
99
90
|
LONG2NUM(info.system_time.seconds * 1000 + info.system_time.microseconds));
|
data/lib/vmstat.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require "vmstat/version"
|
2
2
|
|
3
|
+
# This is a focused and fast library to get system information like:
|
4
|
+
#
|
5
|
+
# * _Memory_ (free, active, ...)
|
6
|
+
# * _Network_ _Interfaces_ (name, in bytes, out bytes, ...)
|
7
|
+
# * _CPU_ (user, system, nice, idle)
|
8
|
+
# * _Load_ Average
|
9
|
+
# * _Disk_ (type, disk path, free bytes, total bytes, ...)
|
10
|
+
# * _Boot_ _Time_
|
11
|
+
# * _Current_ _Task_ (used bytes and usage time *MACOSX* or *LINUX* *ONLY*)
|
3
12
|
module Vmstat
|
4
13
|
autoload :Cpu, "vmstat/cpu"
|
5
14
|
autoload :NetworkInterface, "vmstat/network_interface"
|
@@ -11,7 +20,7 @@ module Vmstat
|
|
11
20
|
autoload :ProcFS, "vmstat/procfs"
|
12
21
|
autoload :Stub, "vmstat/stub"
|
13
22
|
autoload :Snapshot, "vmstat/snapshot"
|
14
|
-
extend Stub # the default
|
23
|
+
extend Stub # the default empty implementation
|
15
24
|
|
16
25
|
# @!method self.boot_time
|
17
26
|
# Fetches the boot time of the system.
|
@@ -64,7 +73,7 @@ module Vmstat
|
|
64
73
|
# Vmstat.task # => #<struct Vmstat::Task ...>
|
65
74
|
|
66
75
|
# Creates a full snapshot of the systems hardware statistics.
|
67
|
-
# @param [Array<String>] the paths to the disks to snapshot.
|
76
|
+
# @param [Array<String>] paths the paths to the disks to snapshot.
|
68
77
|
# @return [Vmstat::Snapshot] a snapshot of all statistics.
|
69
78
|
# @example
|
70
79
|
# Vmstat.snapshot # => #<struct Vmstat::Snapshot ...>
|
data/lib/vmstat/cpu.rb
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
module Vmstat
|
2
|
+
# Gathered cpu performance statistics snapshot.
|
3
|
+
# @attr [Fixnum] num
|
4
|
+
# The number of the cpu starting at 0 for the first cpu.
|
5
|
+
# @attr [Fixnum] user
|
6
|
+
# Current counter of ticks spend in user. The counter can overflow.
|
7
|
+
# @attr [Fixnum] system
|
8
|
+
# Current counter of ticks spend in system. The counter can overflow.
|
9
|
+
# @attr [Fixnum] nice
|
10
|
+
# Current counter of ticks spend in nice. The counter can overflow.
|
11
|
+
# @attr [Fixnum] idle
|
12
|
+
# Current counter of ticks spend in idle. The counter can overflow.
|
2
13
|
class Cpu < Struct.new(:num, :user, :system, :nice, :idle)
|
3
14
|
end
|
4
15
|
end
|
data/lib/vmstat/disk.rb
CHANGED
@@ -1,18 +1,42 @@
|
|
1
1
|
module Vmstat
|
2
|
+
# Gathered disk statistics snapshot.
|
3
|
+
# @attr [Symbol] type
|
4
|
+
# The file system name e. g. *hfs*.
|
5
|
+
# @attr [String] origin
|
6
|
+
# The location of the device e.g. */dev/disk0*.
|
7
|
+
# @attr [String] mount
|
8
|
+
# The mount point of the device e.g. */mnt/store*.
|
9
|
+
# @attr [Fixnum] block_size
|
10
|
+
# Size of file system blocks in bytes.
|
11
|
+
# @attr [Fixnum] free_blocks
|
12
|
+
# Free blocks in the file system.
|
13
|
+
# @attr [Fixnum] available_blocks
|
14
|
+
# Available blocks in the file system.
|
15
|
+
# @attr [Fixnum] total_blocks
|
16
|
+
# Total number of blocks in the file system.
|
2
17
|
class Disk < Struct.new(:type, :origin, :mount, :block_size,
|
3
18
|
:free_blocks, :available_blocks, :total_blocks)
|
19
|
+
# Calculates the number of free bytes for the file system.
|
20
|
+
# @return [Fixnum] number of free bytes
|
4
21
|
def free_bytes
|
5
22
|
free_blocks * block_size
|
6
23
|
end
|
7
24
|
|
25
|
+
# Calculates the number of available bytes for the file system.
|
26
|
+
# @return [Fixnum] number of available bytes
|
8
27
|
def available_bytes
|
9
28
|
available_blocks * block_size
|
10
29
|
end
|
11
30
|
|
31
|
+
# Calculates the number of used bytes for the file system.
|
32
|
+
# @return [Fixnum] number of used bytes
|
12
33
|
def used_bytes
|
13
34
|
(total_blocks - free_blocks) * block_size
|
14
35
|
end
|
15
36
|
|
37
|
+
# Calculates the number of total bytes for the file system. This is the max.
|
38
|
+
# number of bytes possible on the device.
|
39
|
+
# @return [Fixnum] number of total bytes
|
16
40
|
def total_bytes
|
17
41
|
total_blocks * block_size
|
18
42
|
end
|
data/lib/vmstat/linux_disk.rb
CHANGED
@@ -22,9 +22,16 @@ module Vmstat
|
|
22
22
|
}.freeze
|
23
23
|
|
24
24
|
# Mainly a wrapper for the {Vmstat::Disk} class constructor. This constructor
|
25
|
-
# handles the file system type mapping
|
26
|
-
|
27
|
-
|
25
|
+
# handles the file system type mapping (based on the magic codes defined in
|
26
|
+
# {LinuxDisk::FS_CODES}).
|
27
|
+
# @param [Fixnum] fs the type or magix number of the disk.
|
28
|
+
# @param [String] path the path to the disk
|
29
|
+
# @param [Fixnum] block_size size of a file system block
|
30
|
+
# @param [Fixnum] free_blocks the number of free blocks
|
31
|
+
# @param [Fixnum] available_blocks the number of available blocks
|
32
|
+
# @param [Fixnum] total_blocks the number of total blocks
|
33
|
+
def initialize(fs = nil, path = nil, block_size = nil, free_blocks = nil,
|
34
|
+
available_blocks = nil, total_blocks = nil)
|
28
35
|
@fs = fs
|
29
36
|
super FS_CODES[@fs], path, path, block_size,
|
30
37
|
free_blocks, available_blocks, total_blocks
|
data/lib/vmstat/load_average.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
module Vmstat
|
2
|
+
# In UNIX computing, the system load is a measure of the amount of
|
3
|
+
# computational work that a computer system performs. The load average
|
4
|
+
# represents the average system load over a period of time.
|
5
|
+
# Source: wikipedia(en).
|
6
|
+
# @attr [Float] one_minute The load for the last minute.
|
7
|
+
# @attr [Float] five_minutes The load for the last five minutes.
|
8
|
+
# @attr [Float] fifteen_minutes The load for the last fifteen minutes.
|
2
9
|
class LoadAverage < Struct.new(:one_minute, :five_minutes, :fifteen_minutes)
|
3
10
|
end
|
4
11
|
end
|
data/lib/vmstat/memory.rb
CHANGED
@@ -1,22 +1,41 @@
|
|
1
1
|
module Vmstat
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
# Gathered memory data snapshot.
|
3
|
+
# @attr [Fixnum] pagesize
|
4
|
+
# The page size of the memory in bytes.
|
5
|
+
# @attr [Fixnum] wired
|
6
|
+
# The number of wired pages in the system.
|
7
|
+
# @attr [Fixnum] active
|
8
|
+
# The number of active pages in the system.
|
9
|
+
# @attr [Fixnum] inactive
|
10
|
+
# The number of inactive pages in the system.
|
11
|
+
# @attr [Fixnum] free
|
12
|
+
# The number of free pages in the system.
|
13
|
+
# @attr [Fixnum] pageins
|
14
|
+
# The number of pageins.
|
15
|
+
# @attr [Fixnum] pageouts
|
16
|
+
# The number of pageouts.
|
17
|
+
class Memory < Struct.new(:pagesize, :wired, :active, :inactive, :free,
|
18
|
+
:pageins, :pageouts)
|
19
|
+
# Calculate the wired bytes based of the wired pages.
|
20
|
+
# @return [Fixnum] wired bytes
|
8
21
|
def wired_bytes
|
9
22
|
wired * pagesize
|
10
23
|
end
|
11
24
|
|
25
|
+
# Calculate the active bytes based of the active pages.
|
26
|
+
# @return [Fixnum] active bytes
|
12
27
|
def active_bytes
|
13
28
|
active * pagesize
|
14
29
|
end
|
15
30
|
|
31
|
+
# Calculate the inactive bytes based of the inactive pages.
|
32
|
+
# @return [Fixnum] inactive bytes
|
16
33
|
def inactive_bytes
|
17
34
|
inactive * pagesize
|
18
35
|
end
|
19
36
|
|
37
|
+
# Calculate the free bytes based of the free pages.
|
38
|
+
# @return [Fixnum] free bytes
|
20
39
|
def free_bytes
|
21
40
|
free * pagesize
|
22
41
|
end
|
@@ -1,4 +1,12 @@
|
|
1
1
|
module Vmstat
|
2
|
+
# Gathered the network interface information.
|
3
|
+
# @attr [Symbol] name the system name for the network interface.
|
4
|
+
# @attr [Fixnum] in_bytes the number od bytes that where received inbound.
|
5
|
+
# @attr [Fixnum] in_errors the number of errors that where received inbound.
|
6
|
+
# @attr [Fixnum] in_drops the number of drops that where received inbound.
|
7
|
+
# @attr [Fixnum] out_bytes the number od bytes that where send outbound.
|
8
|
+
# @attr [Fixnum] out_errors the number od errors that where send outbound.
|
9
|
+
# @attr [Fixnum] type the type of the interface (bsd numbers)
|
2
10
|
class NetworkInterface < Struct.new(:name, :in_bytes, :in_errors, :in_drops,
|
3
11
|
:out_bytes, :out_errors, :type)
|
4
12
|
|
@@ -8,10 +16,16 @@ module Vmstat
|
|
8
16
|
# The type of loopback devices on freebsd/mac os x
|
9
17
|
LOOPBACK_TYPE = 0x18
|
10
18
|
|
19
|
+
# Checks if this network interface is a loopback device.
|
20
|
+
# @return [TrueClass, FalseClass] true if it is a loopback device, false
|
21
|
+
# otherwise.
|
11
22
|
def loopback?
|
12
23
|
type == LOOPBACK_TYPE
|
13
24
|
end
|
14
25
|
|
26
|
+
# Checks if this network interface is a ethernet device.
|
27
|
+
# @return [TrueClass, FalseClass] true if it is a ethernet device, false
|
28
|
+
# otherwise.
|
15
29
|
def ethernet?
|
16
30
|
type == ETHERNET_TYPE
|
17
31
|
end
|
data/lib/vmstat/procfs.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
module Vmstat
|
2
|
+
# Implementation of performance metrics gathering for linux and other os with
|
3
|
+
# the proc file system.
|
2
4
|
module ProcFS
|
3
5
|
# Grep from the man procfs about cpu data in stat file:
|
4
6
|
# @example Format
|
@@ -84,14 +86,32 @@ module Vmstat
|
|
84
86
|
netifcs = []
|
85
87
|
procfs_file("net", "dev") do |file|
|
86
88
|
file.read.scan(NET_DATA) do |columns|
|
89
|
+
type = case columns[0]
|
90
|
+
when /^eth/ then NetworkInterface::ETHERNET_TYPE
|
91
|
+
when /^lo/ then NetworkInterface::LOOPBACK_TYPE
|
92
|
+
end
|
93
|
+
|
87
94
|
netifcs << NetworkInterface.new(columns[0].to_sym, columns[1].to_i,
|
88
95
|
columns[3].to_i, columns[4].to_i,
|
89
|
-
columns[9].to_i, columns[11].to_i
|
96
|
+
columns[9].to_i, columns[11].to_i,
|
97
|
+
type)
|
90
98
|
end
|
91
99
|
end
|
92
100
|
netifcs
|
93
101
|
end
|
94
102
|
|
103
|
+
# Fetches the current process cpu and memory data.
|
104
|
+
# @return [Vmstat::Task] the task data for the current process
|
105
|
+
def task
|
106
|
+
@pagesize ||= Vmstat.pagesize
|
107
|
+
|
108
|
+
procfs_file("self", "stat") do |file|
|
109
|
+
data = file.read.split(/ /)
|
110
|
+
Task.new(data[22].to_i / @pagesize, data[23].to_i,
|
111
|
+
data[13].to_i * 1000, data[14].to_i * 1000)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
95
115
|
# Fetches the boot time of the system.
|
96
116
|
# @return [Time] the boot time as regular time object.
|
97
117
|
# @example
|
data/lib/vmstat/snapshot.rb
CHANGED
@@ -1,12 +1,28 @@
|
|
1
1
|
module Vmstat
|
2
|
+
# Snapshots help to gather information about the whole system quickly.
|
3
|
+
# @attr [Time] at the timestamp, when the snapshot was created.
|
4
|
+
# @attr [Time] boot_time the timestamp, when the system booted.
|
5
|
+
# @attr [Array<Vmstat::Cpu>] cpus the data of each and every cpu.
|
6
|
+
# @attr [Array<Vmstat::Disk>] disks the disks that are part of the snapshot.
|
7
|
+
# @attr [Vmstat::LoadAverage] load_average current load average at the time
|
8
|
+
# when the snapshot toke place.
|
9
|
+
# @attr [Vmstat::Memory] memory the memory data snapshot.
|
10
|
+
# @attr [Array<Vmstat::NetworkInterface>] network_interfaces the network
|
11
|
+
# interface data snapshots per network interface.
|
12
|
+
# @attr [Vmstat::Task] task optionally the information for the current task
|
13
|
+
# @example Creating a snapshot
|
14
|
+
# snapshop = Vmstat::Snapshop.new(["/dev/disk0", "/dev/disk1"])
|
2
15
|
class Snapshot
|
3
|
-
attr_reader :at, :boot_time, :
|
16
|
+
attr_reader :at, :boot_time, :cpus, :disks, :load_average,
|
4
17
|
:memory, :network_interfaces, :task
|
5
18
|
|
19
|
+
# Create a new snapshot for system informations. The passed paths array,
|
20
|
+
# should contain the disk paths to create a snapshot for.
|
21
|
+
# @param [Array<String>] paths the paths to create snapshots for
|
6
22
|
def initialize(paths = [])
|
7
23
|
@at = Time.now
|
8
24
|
@boot_time = Vmstat.boot_time
|
9
|
-
@
|
25
|
+
@cpus = Vmstat.cpu
|
10
26
|
@disks = paths.map { |path| Vmstat.disk(path) }
|
11
27
|
@load_average = Vmstat.load_average
|
12
28
|
@memory = Vmstat.memory
|
data/lib/vmstat/stub.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
module Vmstat
|
2
|
+
# This is a stub module that should be replaced by system specific
|
3
|
+
# implementations of the different functions. This can either be native or
|
4
|
+
# with other modules like {ProcFS}.
|
2
5
|
module Stub
|
3
6
|
# Fetches the boot time of the system.
|
4
7
|
# @return [Time] the boot time as regular time object.
|
data/lib/vmstat/task.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module Vmstat
|
2
|
-
|
2
|
+
# Per task performance metrics snapshot.
|
3
|
+
# @attr [Fixnum] virtual_size
|
4
|
+
# The number of virtual pages for the task.
|
5
|
+
# @attr [Fixnum] resident_size
|
6
|
+
# The number of resident pages for the task
|
7
|
+
# @attr [Fixnum] user_time_ms
|
8
|
+
# The total user run time for terminated threads within the task.
|
9
|
+
# @attr [Fixnum] system_time_ms
|
10
|
+
# The total system run time for terminated threads within the task.
|
11
|
+
class Task < Struct.new(:virtual_size, :resident_size,
|
3
12
|
:user_time_ms, :system_time_ms)
|
4
13
|
end
|
5
14
|
end
|
6
|
-
|
data/lib/vmstat/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
1587 (bash) S 1586 1587 1492 34816 1662 4202496 1405 6289 0 2 2 0 0 7 20 0 1 0 7017 19689472 515 18446744073709551615 4194304 5082140 140736936765952 140736936764896 139925747992062 0 65536 3686404 1266761467 0 0 0 17 0 0 0 0 0 0
|
data/spec/vmstat/cpu_spec.rb
CHANGED
data/spec/vmstat/disk_spec.rb
CHANGED
@@ -1,12 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vmstat::Disk do
|
4
|
+
context "sample" do
|
5
|
+
let(:disk) { described_class.new :hfs, "/dev/disk0", "/mnt/test",
|
6
|
+
4096, 100, 200, 600 }
|
7
|
+
subject { disk }
|
8
|
+
|
9
|
+
its(:type) { should == :hfs }
|
10
|
+
its(:origin) { should == "/dev/disk0" }
|
11
|
+
its(:mount) { should == "/mnt/test" }
|
12
|
+
|
13
|
+
its(:block_size) { should == 4096 }
|
14
|
+
its(:free_blocks) { should == 100 }
|
15
|
+
its(:available_blocks) { should == 200 }
|
16
|
+
its(:total_blocks) { should == 600 }
|
17
|
+
|
18
|
+
its(:free_bytes) { should == 409600 }
|
19
|
+
its(:available_bytes) { should == 819200 }
|
20
|
+
its(:used_bytes) { should == 2048000 }
|
21
|
+
its(:total_bytes) { should == 2457600 }
|
22
|
+
end
|
23
|
+
|
4
24
|
context "Vmstat#disk" do
|
5
25
|
let(:disk) { Vmstat.disk("/") }
|
6
26
|
subject { disk }
|
7
27
|
|
8
28
|
it "should be a vmstat disk object" do
|
9
|
-
should be_a(
|
29
|
+
should be_a(described_class)
|
10
30
|
end
|
11
31
|
|
12
32
|
context "methods" do
|
data/spec/vmstat/memory_spec.rb
CHANGED
@@ -1,12 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Vmstat::Memory do
|
4
|
+
context "sample" do
|
5
|
+
let(:disk) { described_class.new 4096, 775581, 196146, 437495, 685599,
|
6
|
+
1560532, 0 }
|
7
|
+
subject { disk }
|
8
|
+
|
9
|
+
its(:pagesize) { should == 4096 }
|
10
|
+
|
11
|
+
its(:wired) { should == 775581 }
|
12
|
+
its(:active) { should == 196146 }
|
13
|
+
its(:inactive) { should == 437495 }
|
14
|
+
its(:free) { should == 685599 }
|
15
|
+
|
16
|
+
its(:wired_bytes) { should == 3176779776 }
|
17
|
+
its(:active_bytes) { should == 803414016 }
|
18
|
+
its(:inactive_bytes) { should == 1791979520 }
|
19
|
+
its(:free_bytes) { should == 2808213504 }
|
20
|
+
|
21
|
+
its(:pageins) { should == 1560532 }
|
22
|
+
its(:pageouts) { should == 0 }
|
23
|
+
end
|
24
|
+
|
4
25
|
context "Vmstat#memory" do
|
5
26
|
let(:memory) { Vmstat.memory }
|
6
27
|
subject { memory }
|
7
28
|
|
8
29
|
it "should be a vmstat memory object" do
|
9
|
-
should be_a(
|
30
|
+
should be_a(described_class)
|
10
31
|
end
|
11
32
|
|
12
33
|
context "methods" do
|
@@ -15,14 +36,13 @@ describe Vmstat::Memory do
|
|
15
36
|
it { should respond_to(:active) }
|
16
37
|
it { should respond_to(:inactive) }
|
17
38
|
it { should respond_to(:free) }
|
39
|
+
it { should respond_to(:pageins) }
|
40
|
+
it { should respond_to(:pageouts) }
|
41
|
+
|
18
42
|
it { should respond_to(:wired_bytes) }
|
19
43
|
it { should respond_to(:active_bytes) }
|
20
44
|
it { should respond_to(:inactive_bytes) }
|
21
45
|
it { should respond_to(:free_bytes) }
|
22
|
-
it { should respond_to(:zero_filled) }
|
23
|
-
it { should respond_to(:reactivated) }
|
24
|
-
it { should respond_to(:faults) }
|
25
|
-
it { should respond_to(:copy_on_write_faults) }
|
26
46
|
end
|
27
47
|
|
28
48
|
context "content" do
|
@@ -31,14 +51,13 @@ describe Vmstat::Memory do
|
|
31
51
|
its(:active) { should be_a_kind_of(Numeric) }
|
32
52
|
its(:inactive) { should be_a_kind_of(Numeric) }
|
33
53
|
its(:free) { should be_a_kind_of(Numeric) }
|
54
|
+
its(:pageins) { should be_a_kind_of(Numeric) }
|
55
|
+
its(:pageouts) { should be_a_kind_of(Numeric) }
|
56
|
+
|
34
57
|
its(:wired_bytes) { should be_a_kind_of(Numeric) }
|
35
58
|
its(:active_bytes) { should be_a_kind_of(Numeric) }
|
36
59
|
its(:inactive_bytes) { should be_a_kind_of(Numeric) }
|
37
60
|
its(:free_bytes) { should be_a_kind_of(Numeric) }
|
38
|
-
its(:zero_filled) { should be_a_kind_of(Numeric) }
|
39
|
-
its(:reactivated) { should be_a_kind_of(Numeric) }
|
40
|
-
its(:faults) { should be_a_kind_of(Numeric) }
|
41
|
-
its(:copy_on_write_faults) { should be_a_kind_of(Numeric) }
|
42
61
|
end
|
43
62
|
end
|
44
|
-
end
|
63
|
+
end
|
data/spec/vmstat/network_spec.rb
CHANGED
data/spec/vmstat/procfs_spec.rb
CHANGED
@@ -53,10 +53,20 @@ describe Vmstat::ProcFS do
|
|
53
53
|
it { should be_a(Array) }
|
54
54
|
it do
|
55
55
|
should == [
|
56
|
-
Vmstat::NetworkInterface.new(:lo, 3224, 0, 0, 3224, 0
|
57
|
-
|
58
|
-
Vmstat::NetworkInterface.new(:
|
56
|
+
Vmstat::NetworkInterface.new(:lo, 3224, 0, 0, 3224, 0,
|
57
|
+
Vmstat::NetworkInterface::LOOPBACK_TYPE),
|
58
|
+
Vmstat::NetworkInterface.new(:eth1, 0, 1, 2, 0, 3,
|
59
|
+
Vmstat::NetworkInterface::ETHERNET_TYPE),
|
60
|
+
Vmstat::NetworkInterface.new(:eth0, 33660, 0, 0, 36584, 0,
|
61
|
+
Vmstat::NetworkInterface::ETHERNET_TYPE)
|
59
62
|
]
|
60
63
|
end
|
61
64
|
end
|
65
|
+
|
66
|
+
context "#task" do
|
67
|
+
subject { procfs.task }
|
68
|
+
|
69
|
+
it { should be_a(Vmstat::Task) }
|
70
|
+
it { should == Vmstat::Task.new(4807, 515, 2000, 0) }
|
71
|
+
end
|
62
72
|
end
|
@@ -6,13 +6,13 @@ describe Vmstat::Snapshot do
|
|
6
6
|
subject { snapshot }
|
7
7
|
|
8
8
|
it "should be an vmstat load snapshot object" do
|
9
|
-
should be_a(
|
9
|
+
should be_a(described_class)
|
10
10
|
end
|
11
11
|
|
12
12
|
context "methods" do
|
13
13
|
it { should respond_to(:at) }
|
14
14
|
it { should respond_to(:boot_time) }
|
15
|
-
it { should respond_to(:
|
15
|
+
it { should respond_to(:cpus) }
|
16
16
|
it { should respond_to(:disks) }
|
17
17
|
it { should respond_to(:load_average) }
|
18
18
|
it { should respond_to(:memory) }
|
@@ -23,7 +23,7 @@ describe Vmstat::Snapshot do
|
|
23
23
|
context "content" do
|
24
24
|
its(:at) { should be_a(Time) }
|
25
25
|
its(:boot_time) { should be_a(Time) }
|
26
|
-
its(:
|
26
|
+
its(:cpus) { should be_a(Array) }
|
27
27
|
its(:disks) { should be_a(Array) }
|
28
28
|
its(:load_average) { should be_a(Vmstat::LoadAverage) }
|
29
29
|
its(:memory) { should be_a(Vmstat::Memory) }
|
@@ -31,7 +31,7 @@ describe Vmstat::Snapshot do
|
|
31
31
|
its(:task) { should be_a(Vmstat::Task) }
|
32
32
|
|
33
33
|
context "first of cpu" do
|
34
|
-
subject { snapshot.
|
34
|
+
subject { snapshot.cpus.first }
|
35
35
|
it { should be_a(Vmstat::Cpu) }
|
36
36
|
end
|
37
37
|
|
data/spec/vmstat/task_spec.rb
CHANGED
@@ -6,11 +6,10 @@ describe Vmstat::Task do
|
|
6
6
|
subject { task }
|
7
7
|
|
8
8
|
it "should be a vmstat task object" do
|
9
|
-
should be_a(
|
9
|
+
should be_a(described_class)
|
10
10
|
end
|
11
11
|
|
12
12
|
context "methods" do
|
13
|
-
it { should respond_to(:suspend_count) }
|
14
13
|
it { should respond_to(:virtual_size) }
|
15
14
|
it { should respond_to(:resident_size) }
|
16
15
|
it { should respond_to(:user_time_ms) }
|
@@ -18,7 +17,6 @@ describe Vmstat::Task do
|
|
18
17
|
end
|
19
18
|
|
20
19
|
context "content" do
|
21
|
-
its(:suspend_count) { should be_a_kind_of(Numeric) }
|
22
20
|
its(:virtual_size) { should be_a_kind_of(Numeric) }
|
23
21
|
its(:resident_size) { should be_a_kind_of(Numeric) }
|
24
22
|
its(:user_time_ms) { should be_a_kind_of(Numeric) }
|
data/spec/vmstat_spec.rb
CHANGED
data/vmstat.gemspec
CHANGED
@@ -9,10 +9,10 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.authors = ["Vincent Landgraf"]
|
10
10
|
gem.email = ["vilandgr@googlemail.com"]
|
11
11
|
gem.description = %q{
|
12
|
-
A focused and fast library
|
12
|
+
A focused and fast library to gather memory,
|
13
13
|
cpu, network, load avg and disk information
|
14
14
|
}
|
15
|
-
gem.summary = %q{A focused and fast library
|
15
|
+
gem.summary = %q{A focused and fast library to gather system information}
|
16
16
|
gem.homepage = "http://threez.github.com/ruby-vmstat/"
|
17
17
|
|
18
18
|
gem.files = `git ls-files`.split($/)
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.require_paths = ["lib"]
|
22
22
|
gem.extensions = ["ext/vmstat/extconf.rb"]
|
23
23
|
|
24
|
+
gem.add_development_dependency('rake')
|
24
25
|
gem.add_development_dependency('rspec')
|
25
26
|
gem.add_development_dependency('rake-compiler')
|
26
27
|
gem.add_development_dependency('guard-rspec')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmstat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rspec
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,7 +91,7 @@ dependencies:
|
|
75
91
|
- - ! '>='
|
76
92
|
- !ruby/object:Gem::Version
|
77
93
|
version: '0'
|
78
|
-
description: ! "\n A focused and fast library
|
94
|
+
description: ! "\n A focused and fast library to gather memory, \n cpu, network,
|
79
95
|
load avg and disk information\n "
|
80
96
|
email:
|
81
97
|
- vilandgr@googlemail.com
|
@@ -87,6 +103,7 @@ files:
|
|
87
103
|
- .gitignore
|
88
104
|
- .rspec
|
89
105
|
- .rvmrc
|
106
|
+
- .travis.yml
|
90
107
|
- Gemfile
|
91
108
|
- Guardfile
|
92
109
|
- LICENSE.txt
|
@@ -115,6 +132,7 @@ files:
|
|
115
132
|
- spec/procfs/loadavg
|
116
133
|
- spec/procfs/meminfo
|
117
134
|
- spec/procfs/net/dev
|
135
|
+
- spec/procfs/self/stat
|
118
136
|
- spec/procfs/stat
|
119
137
|
- spec/procfs/uptime
|
120
138
|
- spec/procfs/vmstat
|
@@ -143,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
161
|
version: '0'
|
144
162
|
segments:
|
145
163
|
- 0
|
146
|
-
hash: -
|
164
|
+
hash: -3973347779729246928
|
147
165
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
166
|
none: false
|
149
167
|
requirements:
|
@@ -152,17 +170,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
170
|
version: '0'
|
153
171
|
segments:
|
154
172
|
- 0
|
155
|
-
hash: -
|
173
|
+
hash: -3973347779729246928
|
156
174
|
requirements: []
|
157
175
|
rubyforge_project:
|
158
176
|
rubygems_version: 1.8.24
|
159
177
|
signing_key:
|
160
178
|
specification_version: 3
|
161
|
-
summary: A focused and fast library
|
179
|
+
summary: A focused and fast library to gather system information
|
162
180
|
test_files:
|
163
181
|
- spec/procfs/loadavg
|
164
182
|
- spec/procfs/meminfo
|
165
183
|
- spec/procfs/net/dev
|
184
|
+
- spec/procfs/self/stat
|
166
185
|
- spec/procfs/stat
|
167
186
|
- spec/procfs/uptime
|
168
187
|
- spec/procfs/vmstat
|