vmstator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d945feb142744013ddd6b191caebe82e19e599e6
4
+ data.tar.gz: eaf212ddbdfa8023e51f0f40a50983fbea83c103
5
+ SHA512:
6
+ metadata.gz: 87c6801d7ac51d7d273eaf1ce30be069451bd0e0a30c360d4d4bafdb6724c790ee624dd5f78b4f3dd3688cf09ca894f3017f8efbe832d03cca1c78418333d54f
7
+ data.tar.gz: 93c819c1d3a4660dbb7bf0d5699a9239db6c542c3eb010f93fec2fa2dc41aacc1439953c443938bac839b13d91ba9336b5443fa08c2b130ea62c6c73cb30cd14
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at kgruber1@emich.edu. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vmstator.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vmstator (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.4.2)
11
+ rspec (3.5.0)
12
+ rspec-core (~> 3.5.0)
13
+ rspec-expectations (~> 3.5.0)
14
+ rspec-mocks (~> 3.5.0)
15
+ rspec-core (3.5.3)
16
+ rspec-support (~> 3.5.0)
17
+ rspec-expectations (3.5.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.5.0)
20
+ rspec-mocks (3.5.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.5.0)
23
+ rspec-support (3.5.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.12)
30
+ rake (~> 10.0)
31
+ rspec (~> 3.0)
32
+ vmstator!
33
+
34
+ BUNDLED WITH
35
+ 1.12.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kent Gruber
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Vmstator
2
+
3
+ Vmstator is a Ruby API for [vmstat](https://en.wikipedia.org/wiki/Vmstat). It provides an [OO](https://www.tutorialspoint.com/ruby/ruby_object_oriented.htm) interface to be able to parse the contents of the output of vmstat and access that infromation intuitively.
4
+
5
+ #### Note
6
+
7
+ This gem is still in development, but has more or less working code! :)
8
+
9
+ ![screenshot](http://i.imgur.com/XUrUBV8.png "Screen Shot")
10
+
11
+ ## Installation
12
+
13
+ ### Gemfile
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'vmstator'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ ### Gem Install
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install vmstator
30
+
31
+ ## Usage
32
+
33
+ Still working on this bit, but, for the mean time...
34
+
35
+ ### Typical Use
36
+
37
+ ```ruby
38
+ require 'vmstator'
39
+
40
+ ```
41
+
42
+ ## License
43
+
44
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
45
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "vmstator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ # Path setting slight of hand:
2
+ $: << File.expand_path("../../lib", __FILE__)
3
+ require 'vmstator'
4
+ require 'pry'
5
+
6
+ binding.pry
@@ -0,0 +1,18 @@
1
+ module Vmstator
2
+
3
+ # VmstatError handles the custom error handling for this Gem
4
+ #
5
+ # == Example
6
+ #
7
+ # # Typical use case
8
+ # raise VmstatError("This is a custom error!")
9
+ #
10
+ class VmstatError < StandardError
11
+ attr_reader :problem
12
+ def initialize(problem="Vmstat eems to have encountered a problem.")
13
+ @problem = problem
14
+ super(@problem)
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,3 @@
1
+ module Vmstator
2
+ VERSION = "1.0.0"
3
+ end
data/lib/vmstator.rb ADDED
@@ -0,0 +1,193 @@
1
+ require "vmstator/errors"
2
+ require "vmstator/version"
3
+
4
+ module Vmstator
5
+
6
+ # The Stats class does most of the work for this gem
7
+ # by providing an interface to parse vmstat, process
8
+ # flags for the vmstat command, and a way to access the
9
+ # result of that data.
10
+ class Stats
11
+ # Comand-line Flags
12
+ attr_accessor :flags
13
+ # Output of command and all parsed data
14
+ attr_reader :output, :data
15
+ # Parsed Data
16
+ attr_reader :r, :runnable # number of runnable processes
17
+ attr_reader :b, :uninter # number of processes in uninterruptible sleep
18
+ attr_reader :swpd, :used # amount of virtual memory used
19
+ attr_reader :free, :free # amount of idle memory
20
+ attr_reader :buff, :buffer # amount of memory used as buffers
21
+ attr_reader :c, :cache # amount of memory used as cache
22
+ attr_reader :si, :swapped_in # amount of memory swapped in from disk (/s)
23
+ attr_reader :so, :swapped_to # amount memory swapped to disk (/s)
24
+ attr_reader :bi, :blocs_recv # blocks received from a block device (blocks/s)
25
+ attr_reader :bo, :blocks_sent # blocks sent to a block device (blocks/s)
26
+ attr_reader :in, :interrupts # number of interrupts (/s)
27
+ attr_reader :cs, :cntxt_swtchs # number of context switches (/s)
28
+ attr_reader :us, :non_kernel # time spent running non-kernel code
29
+ attr_reader :sy, :kernel # time spent running kernel code
30
+ attr_reader :id, :idle_time # time spent idle
31
+ attr_reader :wa, :waiting # time spent waiting for IO
32
+ attr_reader :st, :stolen # time stolen from a virtual machine
33
+
34
+ # initialize() handles the initialization of a new
35
+ # Vmstator::Stats object which takes in an optional
36
+ # set of arguments that can be passed in as a hash.
37
+ #
38
+ # == Example
39
+ #
40
+ # # Typical use case:
41
+ # vmstats = Vmstator::Stats.new(:flags => "-S m", :parse => true )
42
+ # # => true
43
+ #
44
+ def initialize(args=false)
45
+ unless vmstat_exists?
46
+ Vmstator::VmstatError.new("Vmstat was not found on this system!")
47
+ end
48
+ if args
49
+ process_flags(args[:flags]) if args[:flags]
50
+ parse if args[:parse]
51
+ end
52
+ true
53
+ end
54
+
55
+ # dry_run() runs the vmstat command with the available flags or
56
+ # will raise a custom Vmstator::VmstatError
57
+ def dry_run
58
+ unless system("vmstat #{@flags} > /dev/null 2>&1")
59
+ raise Vmstator::VmstatError.new("Vmstat ran into a problem with the flag(s): #{@flags}")
60
+ end
61
+ end
62
+
63
+ # forks() will run the -f flag and return that data.
64
+ def forks
65
+ `vmstat -f`.split.first
66
+ end
67
+
68
+ # active() will parse the results of active
69
+ # and inactive memory information.
70
+ def active
71
+ parse("-a")
72
+ end
73
+
74
+ # version() will run the -V flag and return the version
75
+ # number from that information.
76
+ def vmstat_version
77
+ `vmstat -V`.split.last
78
+ end
79
+
80
+ # version() will run the -d flag and return the parsed
81
+ # informatio from that command.
82
+ def disk_info
83
+ @disk_info = {}
84
+ output = `vmstat -d`.split("\n")
85
+ # remove first two lines of the output
86
+ output.shift
87
+ output.shift
88
+ @disk_info[:disk_count] = output.count
89
+ output.each do |line|
90
+ disk, total, merged, sectors, ms, total, merged, sectors, ms, cur, sec = line.split
91
+ @disk_info[disk.to_sym] = { :totoal => total, :merged => merged, :sectors => sectors,
92
+ :ms => ms, :cur => cur, :sec => sec }
93
+ end
94
+ @disk_info
95
+ end
96
+
97
+ # event_counter_statistics() will return the event
98
+ # count statistics in the form of a hash
99
+ def event_counter_statistics(flags=@flags)
100
+ output = `vmstat #{flags}`.split("\n")
101
+ keys = output.split(/\d/).compact.join.split("\n").map(&:strip)
102
+ values = output.split(/[A-z]/).compact.join.split("\n").map(&:strip)
103
+ Hash[keys.zip values]
104
+ end
105
+
106
+ # slab_info() will run the -m flag and return that data
107
+ def slab_info
108
+ # TODO : may go back, make this an option to use sudo or not.
109
+ # You need sudo permission to run this flag.
110
+ @slab_info = {}
111
+ `sudo vmstat -m`.split("\n").each do |info|
112
+ next if info == "Cache Num Total Size Pages"
113
+ cache, num, total, size, pages = info.split
114
+ @slab_info[cache] = {}
115
+ @slab_info[cache][:num] = num
116
+ @slab_info[cache][:total] = total
117
+ @slab_info[cache][:size] = size
118
+ @slab_info[cache][:pages] = pages
119
+ end
120
+ @slab_info
121
+ end
122
+
123
+ # parse() is probably the main work horse of this class. It parses the
124
+ # the vmstat command after a dry run is done to check the command. It
125
+ # does quite few things: including parsing all of the vmstat information
126
+ # into a hash stored in @data; and will then store the relevant information
127
+ # into the appropriate attr_reader
128
+ #
129
+ # == Example
130
+ #
131
+ # # Typical use case to parse a vmstat command.
132
+ # vmstats = Vmstator::Stats.new(:flags => "-S m")
133
+ # vmstats.parse
134
+ # # => true
135
+ #
136
+ def parse(flags=@flags)
137
+ if flags =~ /(-d|--disk)/
138
+ return disk_statistics
139
+ elsif flags =~ /(-f|--forks)/
140
+ return forks
141
+ elsif flags =~ /(-s|--stats)/
142
+ return event_counter_statistics
143
+ end
144
+ dry_run
145
+ @output = `vmstat #{flags}`.split("\n")
146
+ labels = @output[1]
147
+ stats = @output[2]
148
+ @data = Hash[labels.split.map(&:to_sym).zip stats.split]
149
+ @swpd, @used = @data[:swpd], @data[:swpd]
150
+ @buff, @buffer = @data[:buff], @data[:buff]
151
+ @r, @runnable = @data[:r], @data[:r]
152
+ @b, @uninter = @data[:b], @data[:b]
153
+ @si, @swapped_in = @data[:si], @data[:si]
154
+ @so, @swapped_to = @data[:so], @data[:so]
155
+ @bi, @blocs_recv = @data[:bi], @data[:bi]
156
+ @bo, @blocks_sent = @data[:bo], @data[:bo]
157
+ @in, @interrupts = @data[:in], @data[:in]
158
+ @cs, @cntxt_swtchs = @data[:cs], @data[:cs]
159
+ @us, @non_kernel = @data[:us], @data[:us]
160
+ @sy, @kernel = @data[:sy], @data[:sy]
161
+ @id, @idle_time = @data[:id], @data[:id]
162
+ @wa, @waiting = @data[:wa], @data[:wa]
163
+ @st, @stolen = @data[:st], @data[:st]
164
+ @cache = @data[:cache]
165
+ @free = @data[:free]
166
+ true
167
+ end
168
+
169
+ private
170
+
171
+ # vmstat_exists?() checks if vmstat exists
172
+ # or not returning true or false for the command.
173
+ def vmstat_exists?
174
+ system("which vmstat > /dev/null 2>&1")
175
+ end
176
+
177
+ # process_flags() allows the flags argument that is passed
178
+ # in to be either an array or a string. That way the flags
179
+ # argument can be processed intuitively as either a string
180
+ # of flags or simple an array of those flags.
181
+ def process_flags(flags)
182
+ if flags.is_a? String
183
+ @flags = flags
184
+ elsif flags.is_a? Array
185
+ @flags = flags.join(" ")
186
+ else
187
+ false
188
+ end
189
+ end
190
+
191
+ end
192
+
193
+ end
Binary file
Binary file
data/vmstator.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vmstator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vmstator"
8
+ spec.version = Vmstator::VERSION
9
+ spec.authors = ["Kent 'picat' Gruber"]
10
+ spec.email = ["kgruber1@emich.edu"]
11
+
12
+ spec.summary = %q{Vmstator is a Ruby API for vmstat to monitor virtual memory statistics.}
13
+ spec.description = %q{Vmstator is a Ruby API for vmstat to monitor virtual memory statistics. It provides an OO interface to be able to parse the contents of the output of vmstat and access that infromation intuitively.}
14
+ spec.homepage = "https://github.com/picatz/Vmstator"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vmstator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kent 'picat' Gruber
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Vmstator is a Ruby API for vmstat to monitor virtual memory statistics.
56
+ It provides an OO interface to be able to parse the contents of the output of vmstat
57
+ and access that infromation intuitively.
58
+ email:
59
+ - kgruber1@emich.edu
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - CODE_OF_CONDUCT.md
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - examples/basic_example.rb
73
+ - lib/vmstator.rb
74
+ - lib/vmstator/errors.rb
75
+ - lib/vmstator/version.rb
76
+ - pkg/vmstator-0.1.0.gem
77
+ - pkg/vmstator-1.0.0.gem
78
+ - vmstator.gemspec
79
+ homepage: https://github.com/picatz/Vmstator
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Vmstator is a Ruby API for vmstat to monitor virtual memory statistics.
103
+ test_files: []