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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ecd3e9cb253790a7875af885738d58676054f933
4
- data.tar.gz: 99ed4992498808ff8531ccb356fa8e01dd343609
3
+ metadata.gz: b593666503181d0bb66d1c68a4834d62fbff3bd5
4
+ data.tar.gz: 297d3af6c94cde231888477dff7c1407c5f8d759
5
5
  SHA512:
6
- metadata.gz: d600e96a80e3dfd9ae41989e6bf15fd0c11f5d40ab350b5d6c091ac9031a7120d3d7409f699940c9627dfe9c3c389a9a783f05844225ac8638a2a3ae3a14c372
7
- data.tar.gz: 26ac32611230939c5c86436a37e9f9bb08d86b8a4eec2e6e8149ada836f12bde9cd5d531f50b56eb0be40be37f84b38fca0b6ed18cc9b936bd06d9f62c5871e7
6
+ metadata.gz: 582a2eba336e5ca0dca10392306f99c43566dbbef54a360daeba8f8a14c8a1d26c1d467613207811dc5ea6a795183a2a59ec73017fbee676fb03984288b9dbe4
7
+ data.tar.gz: 21d844a2b549883cb605469f161c02a377ae433ebeb53b78e5d8840fa6b6a1a32c7f1b0620ed47ba974359b035c5a95904518c87294da95325ea992d54917703
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vmstator (2.0.1)
4
+ vmstator (2.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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://i.imgur.com/spjIhpy.png "Screen Shot")
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
- vmstats = Vmstator::Stats.new
43
- vmstats.flags = "-S M"
44
- vmstats.parse
45
-
46
- puts vmstats.data
47
- puts vmstats.buffer
48
- puts vmstats.cache
49
- puts vmstats.forks
50
- puts vmstats.active
51
- puts vmstats.disk_info
52
- puts vmstats.event_counter_statistics
53
- puts vmstats.slab_info
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] if data[:ms]
22
- @cur = data[:cur] if data[:cur]
23
- @sec = data[:sec] if data[:sec]
24
- @name = data[:name] if data[:name]
25
- @total = data[:total] if data[:total]
26
- @merged = data[:merged] if data[:merged]
27
- @sectors = data[:sectors] if 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
@@ -1,3 +1,3 @@
1
1
  module Vmstator
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
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 = "-a" unless 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, :totoal => total.to_i, :merged => merged.to_i, :sectors => sectors.to_i,
119
- :ms => ms.to_i, :cur => cur.to_i, :sec => sec.to_i }
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
- flags = "-m" unless flags
128
- # TODO : may go back, make this an option to use sudo or not.
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, :num => num.to_i, :total => total.to_i,
136
- :size => size.to_i, :pages => pages.to_i }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmstator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kent 'picat' Gruber