vmstator 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +57 -15
- data/lib/vmstator/disk.rb +7 -7
- data/lib/vmstator/version.rb +1 -1
- data/lib/vmstator.rb +18 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b593666503181d0bb66d1c68a4834d62fbff3bd5
|
4
|
+
data.tar.gz: 297d3af6c94cde231888477dff7c1407c5f8d759
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 582a2eba336e5ca0dca10392306f99c43566dbbef54a360daeba8f8a14c8a1d26c1d467613207811dc5ea6a795183a2a59ec73017fbee676fb03984288b9dbe4
|
7
|
+
data.tar.gz: 21d844a2b549883cb605469f161c02a377ae433ebeb53b78e5d8840fa6b6a1a32c7f1b0620ed47ba974359b035c5a95904518c87294da95325ea992d54917703
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -6,9 +6,7 @@ Vmstator is a Ruby API for [vmstat](https://en.wikipedia.org/wiki/Vmstat). It pr
|
|
6
6
|
|
7
7
|
This gem is still in development, but has more or less working code! :)
|
8
8
|
|
9
|
-
![screenshot](http://
|
10
|
-
|
11
|
-
![screenshot2](http://i.imgur.com/D9TNIpY.png "Screen Shot2")
|
9
|
+
![screenshot](http://imgur.com/a/eMpO2 "Screen Shot")
|
12
10
|
|
13
11
|
## Installation
|
14
12
|
|
@@ -39,18 +37,62 @@ Still working on this bit, but, for the mean time...
|
|
39
37
|
```ruby
|
40
38
|
require 'vmstator'
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
40
|
+
parser = Vmstator::Parser.new
|
41
|
+
|
42
|
+
# Parse command-line arguments to vmstat.
|
43
|
+
parser.parse("-a")
|
44
|
+
|
45
|
+
# Access the command-line arguments directly as methods.
|
46
|
+
parser.active
|
47
|
+
|
48
|
+
# Other Vmstator methods for vmstat:
|
49
|
+
parser.active
|
50
|
+
parser.average
|
51
|
+
parser.disk_statistics
|
52
|
+
parser.disk_summary
|
53
|
+
parser.event_counter_statistics
|
54
|
+
parser.forks
|
55
|
+
parser.parse
|
56
|
+
parser.slab_info
|
57
|
+
parser.version
|
58
|
+
|
59
|
+
# If returns a Vmstator object, for example, for active memory "-a" ...
|
60
|
+
active_memory = parser.active
|
61
|
+
|
62
|
+
# Example, the available methods to access data about Vmstator::ActiveMemory objects.
|
63
|
+
active_memory.blocks_recv
|
64
|
+
active_memory.buffer
|
65
|
+
active_memory.cntxt_swtchs
|
66
|
+
active_memory.idle_time
|
67
|
+
active_memory.kernel
|
68
|
+
active_memory.runnable
|
69
|
+
active_memory.swapped_in
|
70
|
+
active_memory.uninter
|
71
|
+
active_memory.used
|
72
|
+
active_memory.blocks_sent
|
73
|
+
active_memory.cache
|
74
|
+
active_memory.free
|
75
|
+
active_memory.interrupts
|
76
|
+
active_memory.non_kernel
|
77
|
+
active_memory.stolen
|
78
|
+
active_memory.swapped_to
|
79
|
+
active_memory.update
|
80
|
+
active_memory.waiting
|
81
|
+
|
82
|
+
# Types of Vmstator objects:
|
83
|
+
ActiveMemory
|
84
|
+
Cache
|
85
|
+
DiskStatistics
|
86
|
+
EventCounterStatistics
|
87
|
+
Memory
|
88
|
+
SlabInfo
|
89
|
+
AverageMemory
|
90
|
+
Disk
|
91
|
+
DiskSummary
|
92
|
+
Parser
|
93
|
+
Stats
|
94
|
+
VmstatError
|
95
|
+
|
54
96
|
```
|
55
97
|
|
56
98
|
## License
|
data/lib/vmstator/disk.rb
CHANGED
@@ -18,13 +18,13 @@ module Vmstator
|
|
18
18
|
|
19
19
|
def update(data)
|
20
20
|
if data
|
21
|
-
@ms = data[:ms]
|
22
|
-
@cur = data[:cur]
|
23
|
-
@sec = data[:sec]
|
24
|
-
@name = data[:name]
|
25
|
-
@total = data[:total]
|
26
|
-
@merged = data[:merged]
|
27
|
-
@sectors = data[:sectors]
|
21
|
+
@ms = data[:ms]
|
22
|
+
@cur = data[:cur]
|
23
|
+
@sec = data[:sec]
|
24
|
+
@name = data[:name]
|
25
|
+
@total = data[:total]
|
26
|
+
@merged = data[:merged]
|
27
|
+
@sectors = data[:sectors]
|
28
28
|
else
|
29
29
|
return false
|
30
30
|
end
|
data/lib/vmstator/version.rb
CHANGED
data/lib/vmstator.rb
CHANGED
@@ -17,6 +17,7 @@ require "vmstator/version"
|
|
17
17
|
module Vmstator
|
18
18
|
|
19
19
|
class Parser
|
20
|
+
|
20
21
|
# parse() parses the the vmstat command
|
21
22
|
# with optional vmstat command-line flags
|
22
23
|
# which is passed in as a string
|
@@ -67,7 +68,7 @@ module Vmstator
|
|
67
68
|
|
68
69
|
# active() will run the -a flag and return the data
|
69
70
|
def active(flags=false)
|
70
|
-
flags
|
71
|
+
flags = "-a" unless flags
|
71
72
|
output = `vmstat #{flags}`.split("\n")
|
72
73
|
labels = output[1]
|
73
74
|
stats = output[2]
|
@@ -106,7 +107,7 @@ module Vmstator
|
|
106
107
|
end
|
107
108
|
|
108
109
|
# disk_statistics() will run the -d flag and return that data.
|
109
|
-
def disk_statistics(flags=
|
110
|
+
def disk_statistics(flags=false)
|
110
111
|
flags = "-d" unless flags
|
111
112
|
disk_stats = Vmstator::DiskStatistics.new
|
112
113
|
output = `vmstat #{flags}`.split("\n")
|
@@ -115,25 +116,31 @@ module Vmstator
|
|
115
116
|
output.shift
|
116
117
|
output.each do |line|
|
117
118
|
name, total, merged, sectors, ms, total, merged, sectors, ms, cur, sec = line.split
|
118
|
-
data = {:name => name,
|
119
|
-
|
119
|
+
data = { :name => name,
|
120
|
+
:totoal => total.to_i,
|
121
|
+
:merged => merged.to_i,
|
122
|
+
:sectors => sectors.to_i,
|
123
|
+
:ms => ms.to_i,
|
124
|
+
:cur => cur.to_i,
|
125
|
+
:sec => sec.to_i }
|
120
126
|
disk_stats.update(data)
|
121
127
|
end
|
122
128
|
disk_stats
|
123
129
|
end
|
124
130
|
|
125
131
|
# slab_info() will run the -m flag and return that data
|
126
|
-
def slab_info(flags=
|
127
|
-
|
128
|
-
|
129
|
-
# You need sudo permission to run this flag.
|
130
|
-
flags = "-m" if flags.empty?
|
132
|
+
def slab_info(flags=false)
|
133
|
+
raise VmstatError("This must be run with root privileges!") unless Process.uid == 0
|
134
|
+
flags = "-m" unless flags
|
131
135
|
slab_info = Vmstator::SlabInfo.new
|
132
136
|
`sudo vmstat #{flags}`.split("\n").each do |info|
|
133
137
|
next if info == "Cache Num Total Size Pages"
|
134
138
|
name, num, total, size, pages = info.split
|
135
|
-
data = { :name => name,
|
136
|
-
:
|
139
|
+
data = { :name => name,
|
140
|
+
:num => num.to_i,
|
141
|
+
:total => total.to_i,
|
142
|
+
:size => size.to_i,
|
143
|
+
:pages => pages.to_i }
|
137
144
|
slab_info.update(data)
|
138
145
|
end
|
139
146
|
slab_info
|