vmstat-2.3.1/0000755000004100000410000000000013433303705013064 5ustar www-datawww-datavmstat-2.3.1/Gemfile.lock0000644000004100000410000000264613433303705015316 0ustar www-datawww-dataPATH remote: . specs: vmstat (2.3.1) GEM remote: https://rubygems.org/ specs: coderay (1.1.1) diff-lcs (1.2.5) ffi (1.9.14) formatador (0.2.5) guard (2.14.0) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) lumberjack (~> 1.0) nenv (~> 0.1) notiffany (~> 0.0) pry (>= 0.9.12) shellany (~> 0.0) thor (>= 0.18.1) guard-compat (1.2.1) guard-rspec (4.7.3) guard (~> 2.1) guard-compat (~> 1.1) rspec (>= 2.99.0, < 4.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) ruby_dep (~> 1.2) lumberjack (1.0.10) method_source (0.8.2) nenv (0.3.0) notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) rake (11.3.0) rake-compiler (1.0.3) rake rb-fsevent (0.9.8) rb-inotify (0.9.7) ffi (>= 0.5.0) rspec (2.99.0) rspec-core (~> 2.99.0) rspec-expectations (~> 2.99.0) rspec-mocks (~> 2.99.0) rspec-core (2.99.2) rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) rspec-mocks (2.99.4) ruby_dep (1.5.0) shellany (0.0.1) slop (3.6.0) thor (0.19.4) timecop (0.8.1) PLATFORMS ruby DEPENDENCIES guard-rspec rake (~> 11.3) rake-compiler rspec (~> 2.9) timecop vmstat! BUNDLED WITH 1.13.6 vmstat-2.3.1/.travis.yml0000644000004100000410000000010613433303705015172 0ustar www-datawww-datalanguage: ruby os: - linux rvm: - ruby-2.2.6 env: - TRAVIS=true vmstat-2.3.1/.rspec0000644000004100000410000000003213433303705014174 0ustar www-datawww-data--color --format progress vmstat-2.3.1/README.md0000644000004100000410000001014413433303705014343 0ustar www-datawww-data# 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) This is a focused and fast library to get system information like: * _Memory_ (free, active, ...) * _Network Interfaces_ (name, in bytes, out bytes, ...) * _CPU_ (user, system, nice, idle) * _Load_ Average * _Disk_ (type, disk path, free bytes, total bytes, ...) * _Boot Time_ * _Current Task_ (used bytes and usage time *MAC OS X / Linux ONLY*) *It currently supports:* * FreeBSD * MacOS X * Linux (>= 2.6) * OpenBSD * NetBSD * Solaris/SmartOS *It might support (but not tested):* * Older versions of linux ## Installation Add this line to your application's Gemfile: gem 'vmstat' And then execute: $ bundle Or install it yourself as: $ gem install vmstat ## Usage Just require the library and make a snapshot or use the distinct methods to just capture parts of the statistics. For further information have a look at the [rdoc](http://rdoc.info/gems/vmstat/frames). require "vmstat" Vmstat.snapshot # => #, # #, # #, # #, # #, # #, # #, # #], # @disks= # [#], # @load_average= # #, # @memory= # #, # @network_interfaces= # [#, # #, # #, # #, # #], # @task= # #> ## Todo * Swap information * Support more platforms (hp ux, aix, ...) * Optimize performance for OpenBSD, NetBSD using `uvmexp` etc. directly * Optimize performance for solaris, smartos using `kstat` etc. directly * Server performance/system information (open file handles, cache sizes, number of inodes ...) ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request vmstat-2.3.1/spec/0000755000004100000410000000000013433303705014016 5ustar www-datawww-datavmstat-2.3.1/spec/vmstat/0000755000004100000410000000000013433303705015334 5ustar www-datawww-datavmstat-2.3.1/spec/vmstat/cpu_spec.rb0000644000004100000410000000152513433303705017465 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::Cpu do context "Vmstat#cpu" do let(:cpu) { Vmstat.cpu } it "should return an array of ethernet information" do cpu.should be_a(Array) end context "first cpu" do let(:first_cpu) { cpu.first } subject { first_cpu } it "should return a vmstat cpu object" do should be_a(described_class) end context "methods" do it { should respond_to(:user) } it { should respond_to(:system) } it { should respond_to(:nice) } it { should respond_to(:idle) } end context "content" do its(:user) { should be_a_kind_of(Numeric) } its(:system) { should be_a_kind_of(Numeric) } its(:nice) { should be_a_kind_of(Numeric) } its(:idle) { should be_a_kind_of(Numeric) } end end end end vmstat-2.3.1/spec/vmstat/solaris_spec.rb0000644000004100000410000002575513433303705020365 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::Solaris do let(:solaris) do c = Vmstat::Solaris def c.`(cmd) if cmd == 'kstat -p "cpu_stat:::/idle|kernel|user/"' "cpu_stat:0:cpu_stat0:idle 2325343762 cpu_stat:0:cpu_stat0:idlethread 776439232 cpu_stat:0:cpu_stat0:kernel 89137335 cpu_stat:0:cpu_stat0:kernel_asflt 1 cpu_stat:0:cpu_stat0:user 64919001 cpu_stat:1:cpu_stat1:idle 2322767706 cpu_stat:1:cpu_stat1:idlethread 125993797 cpu_stat:1:cpu_stat1:kernel 78457429 cpu_stat:1:cpu_stat1:kernel_asflt 34 cpu_stat:1:cpu_stat1:user 78174710 cpu_stat:2:cpu_stat2:idle 2390178542 cpu_stat:2:cpu_stat2:idlethread 3368087417 cpu_stat:2:cpu_stat2:kernel 50617796 cpu_stat:2:cpu_stat2:kernel_asflt 0 cpu_stat:2:cpu_stat2:user 38603497 cpu_stat:3:cpu_stat3:idle 2390802861 cpu_stat:3:cpu_stat3:idlethread 1772145290 cpu_stat:3:cpu_stat3:kernel 46044221 cpu_stat:3:cpu_stat3:kernel_asflt 0 cpu_stat:3:cpu_stat3:user 42552751 cpu_stat:4:cpu_stat4:idle 2436590263 cpu_stat:4:cpu_stat4:idlethread 2145015281 cpu_stat:4:cpu_stat4:kernel 23983506 cpu_stat:4:cpu_stat4:kernel_asflt 0 cpu_stat:4:cpu_stat4:user 18826062 cpu_stat:5:cpu_stat5:idle 2435969240 cpu_stat:5:cpu_stat5:idlethread 3720145695 cpu_stat:5:cpu_stat5:kernel 25630307 cpu_stat:5:cpu_stat5:kernel_asflt 0 cpu_stat:5:cpu_stat5:user 17800281 cpu_stat:6:cpu_stat6:idle 2432659504 cpu_stat:6:cpu_stat6:idlethread 3012624014 cpu_stat:6:cpu_stat6:kernel 24414413 cpu_stat:6:cpu_stat6:kernel_asflt 0 cpu_stat:6:cpu_stat6:user 22325909 cpu_stat:7:cpu_stat7:idle 2430409364 cpu_stat:7:cpu_stat7:idlethread 1931519381 cpu_stat:7:cpu_stat7:kernel 28094309 cpu_stat:7:cpu_stat7:kernel_asflt 0 cpu_stat:7:cpu_stat7:user 20896150 cpu_stat:8:cpu_stat8:idle 2443187236 cpu_stat:8:cpu_stat8:idlethread 1900014542 cpu_stat:8:cpu_stat8:kernel 20799721 cpu_stat:8:cpu_stat8:kernel_asflt 0 cpu_stat:8:cpu_stat8:user 15412864 cpu_stat:9:cpu_stat9:idle 2440596009 cpu_stat:9:cpu_stat9:idlethread 3703869451 cpu_stat:9:cpu_stat9:kernel 23787482 cpu_stat:9:cpu_stat9:kernel_asflt 0 cpu_stat:9:cpu_stat9:user 15016328 cpu_stat:10:cpu_stat10:idle 2427567910 cpu_stat:10:cpu_stat10:idlethread 3191481058 cpu_stat:10:cpu_stat10:kernel 30059932 cpu_stat:10:cpu_stat10:kernel_asflt 5 cpu_stat:10:cpu_stat10:user 21771975 cpu_stat:11:cpu_stat11:idle 2431827979 cpu_stat:11:cpu_stat11:idlethread 1824361353 cpu_stat:11:cpu_stat11:kernel 27388335 cpu_stat:11:cpu_stat11:kernel_asflt 0 cpu_stat:11:cpu_stat11:user 20183500 cpu_stat:12:cpu_stat12:idle 2442824569 cpu_stat:12:cpu_stat12:idlethread 2037054756 cpu_stat:12:cpu_stat12:kernel 21276397 cpu_stat:12:cpu_stat12:kernel_asflt 0 cpu_stat:12:cpu_stat12:user 15298846 cpu_stat:13:cpu_stat13:idle 2443388458 cpu_stat:13:cpu_stat13:idlethread 3442886390 cpu_stat:13:cpu_stat13:kernel 22081759 cpu_stat:13:cpu_stat13:kernel_asflt 0 cpu_stat:13:cpu_stat13:user 13929592 cpu_stat:14:cpu_stat14:idle 2434768696 cpu_stat:14:cpu_stat14:idlethread 2856867656 cpu_stat:14:cpu_stat14:kernel 23352419 cpu_stat:14:cpu_stat14:kernel_asflt 0 cpu_stat:14:cpu_stat14:user 21278693 cpu_stat:15:cpu_stat15:idle 2432514522 cpu_stat:15:cpu_stat15:idlethread 1703823954 cpu_stat:15:cpu_stat15:kernel 27050642 cpu_stat:15:cpu_stat15:kernel_asflt 16 cpu_stat:15:cpu_stat15:user 19834642 cpu_stat:16:cpu_stat16:idle 2436582325 cpu_stat:16:cpu_stat16:idlethread 1983802071 cpu_stat:16:cpu_stat16:kernel 21833225 cpu_stat:16:cpu_stat16:kernel_asflt 0 cpu_stat:16:cpu_stat16:user 20984253 cpu_stat:17:cpu_stat17:idle 2432250902 cpu_stat:17:cpu_stat17:idlethread 307297399 cpu_stat:17:cpu_stat17:kernel 29580663 cpu_stat:17:cpu_stat17:kernel_asflt 0 cpu_stat:17:cpu_stat17:user 17568236 cpu_stat:18:cpu_stat18:idle 2447310538 cpu_stat:18:cpu_stat18:idlethread 1473510287 cpu_stat:18:cpu_stat18:kernel 18480841 cpu_stat:18:cpu_stat18:kernel_asflt 5 cpu_stat:18:cpu_stat18:user 13608419 cpu_stat:19:cpu_stat19:idle 2446462748 cpu_stat:19:cpu_stat19:idlethread 2882237650 cpu_stat:19:cpu_stat19:kernel 20384068 cpu_stat:19:cpu_stat19:kernel_asflt 0 cpu_stat:19:cpu_stat19:user 12552980 cpu_stat:20:cpu_stat20:idle 2439710143 cpu_stat:20:cpu_stat20:idlethread 2513415319 cpu_stat:20:cpu_stat20:kernel 20976077 cpu_stat:20:cpu_stat20:kernel_asflt 0 cpu_stat:20:cpu_stat20:user 18713575 cpu_stat:21:cpu_stat21:idle 2434565830 cpu_stat:21:cpu_stat21:idlethread 1574993351 cpu_stat:21:cpu_stat21:kernel 26063716 cpu_stat:21:cpu_stat21:kernel_asflt 0 cpu_stat:21:cpu_stat21:user 18770245 cpu_stat:22:cpu_stat22:idle 2447896586 cpu_stat:22:cpu_stat22:idlethread 1566290884 cpu_stat:22:cpu_stat22:kernel 18718466 cpu_stat:22:cpu_stat22:kernel_asflt 0 cpu_stat:22:cpu_stat22:user 12784738 cpu_stat:23:cpu_stat23:idle 2444823222 cpu_stat:23:cpu_stat23:idlethread 3286395080 cpu_stat:23:cpu_stat23:kernel 21510594 cpu_stat:23:cpu_stat23:kernel_asflt 0 cpu_stat:23:cpu_stat23:user 13065972 cpu_stat:24:cpu_stat24:idle 2437316848 cpu_stat:24:cpu_stat24:idlethread 2628739060 cpu_stat:24:cpu_stat24:kernel 22266295 cpu_stat:24:cpu_stat24:kernel_asflt 0 cpu_stat:24:cpu_stat24:user 19816643 cpu_stat:25:cpu_stat25:idle 2433451000 cpu_stat:25:cpu_stat25:idlethread 1604646150 cpu_stat:25:cpu_stat25:kernel 26748441 cpu_stat:25:cpu_stat25:kernel_asflt 0 cpu_stat:25:cpu_stat25:user 19200341 cpu_stat:26:cpu_stat26:idle 2446405472 cpu_stat:26:cpu_stat26:idlethread 1573139378 cpu_stat:26:cpu_stat26:kernel 19619834 cpu_stat:26:cpu_stat26:kernel_asflt 0 cpu_stat:26:cpu_stat26:user 13374474 cpu_stat:27:cpu_stat27:idle 2444019515 cpu_stat:27:cpu_stat27:idlethread 3275705315 cpu_stat:27:cpu_stat27:kernel 21816225 cpu_stat:27:cpu_stat27:kernel_asflt 0 cpu_stat:27:cpu_stat27:user 13564039 cpu_stat:28:cpu_stat28:idle 2435784523 cpu_stat:28:cpu_stat28:idlethread 2628201319 cpu_stat:28:cpu_stat28:kernel 23125551 cpu_stat:28:cpu_stat28:kernel_asflt 0 cpu_stat:28:cpu_stat28:user 20489701 cpu_stat:29:cpu_stat29:idle 2432230501 cpu_stat:29:cpu_stat29:idlethread 1635408506 cpu_stat:29:cpu_stat29:kernel 27198273 cpu_stat:29:cpu_stat29:kernel_asflt 0 cpu_stat:29:cpu_stat29:user 19970999 cpu_stat:30:cpu_stat30:idle 2444413183 cpu_stat:30:cpu_stat30:idlethread 1644573224 cpu_stat:30:cpu_stat30:kernel 20310412 cpu_stat:30:cpu_stat30:kernel_asflt 0 cpu_stat:30:cpu_stat30:user 14676176 cpu_stat:31:cpu_stat31:idle 2442483106 cpu_stat:31:cpu_stat31:idlethread 3345414215 cpu_stat:31:cpu_stat31:kernel 22515695 cpu_stat:31:cpu_stat31:kernel_asflt 0 cpu_stat:31:cpu_stat31:user 14400967\n" elsif cmd == "kstat -p unix:::boot_time" "unix:0:system_misc:boot_time 1470765992\n" elsif cmd == "kstat -p -n system_pages" "unix:0:system_pages:availrmem 70121 unix:0:system_pages:crtime 116.1198523 unix:0:system_pages:desfree 3744 unix:0:system_pages:desscan 25 unix:0:system_pages:econtig 176160768 unix:0:system_pages:fastscan 137738 unix:0:system_pages:freemem 61103 unix:0:system_pages:kernelbase 16777216 unix:0:system_pages:lotsfree 7488 unix:0:system_pages:minfree 1872 unix:0:system_pages:nalloc 26859076 unix:0:system_pages:nalloc_calls 11831 unix:0:system_pages:nfree 25250198 unix:0:system_pages:nfree_calls 7888 unix:0:system_pages:nscan 0 unix:0:system_pages:pagesfree 61103 unix:0:system_pages:pageslocked 409145 unix:0:system_pages:pagestotal 479266 unix:0:system_pages:physmem 489586 unix:0:system_pages:pp_kernel 438675 unix:0:system_pages:slowscan 100 unix:0:system_pages:snaptime 314313.3248461\n" elsif cmd == "kstat -p link:::" "link:0:e1000g0:ierrors 0 link:0:e1000g0:oerrors 1 link:0:e1000g0:rbytes64 1000 link:0:e1000g0:obytes64 2000\n" else raise "Unknown cmd: '#{cmd}'" end end c end context "#cpu" do subject { solaris.cpu } it { should be_a(Array)} it do should == [ Vmstat::Cpu.new(0, 64919001, 89137335, 0, 2325343762), Vmstat::Cpu.new(1, 78174710, 78457429, 0, 2322767706), Vmstat::Cpu.new(2, 38603497, 50617796, 0, 2390178542), Vmstat::Cpu.new(3, 42552751, 46044221, 0, 2390802861), Vmstat::Cpu.new(4, 18826062, 23983506, 0, 2436590263), Vmstat::Cpu.new(5, 17800281, 25630307, 0, 2435969240), Vmstat::Cpu.new(6, 22325909, 24414413, 0, 2432659504), Vmstat::Cpu.new(7, 20896150, 28094309, 0, 2430409364), Vmstat::Cpu.new(8, 15412864, 20799721, 0, 2443187236), Vmstat::Cpu.new(9, 15016328, 23787482, 0, 2440596009), Vmstat::Cpu.new(10, 21771975, 30059932, 0, 2427567910), Vmstat::Cpu.new(11, 20183500, 27388335, 0, 2431827979), Vmstat::Cpu.new(12, 15298846, 21276397, 0, 2442824569), Vmstat::Cpu.new(13, 13929592, 22081759, 0, 2443388458), Vmstat::Cpu.new(14, 21278693, 23352419, 0, 2434768696), Vmstat::Cpu.new(15, 19834642, 27050642, 0, 2432514522), Vmstat::Cpu.new(16, 20984253, 21833225, 0, 2436582325), Vmstat::Cpu.new(17, 17568236, 29580663, 0, 2432250902), Vmstat::Cpu.new(18, 13608419, 18480841, 0, 2447310538), Vmstat::Cpu.new(19, 12552980, 20384068, 0, 2446462748), Vmstat::Cpu.new(20, 18713575, 20976077, 0, 2439710143), Vmstat::Cpu.new(21, 18770245, 26063716, 0, 2434565830), Vmstat::Cpu.new(22, 12784738, 18718466, 0, 2447896586), Vmstat::Cpu.new(23, 13065972, 21510594, 0, 2444823222), Vmstat::Cpu.new(24, 19816643, 22266295, 0, 2437316848), Vmstat::Cpu.new(25, 19200341, 26748441, 0, 2433451000), Vmstat::Cpu.new(26, 13374474, 19619834, 0, 2446405472), Vmstat::Cpu.new(27, 13564039, 21816225, 0, 2444019515), Vmstat::Cpu.new(28, 20489701, 23125551, 0, 2435784523), Vmstat::Cpu.new(29, 19970999, 27198273, 0, 2432230501), Vmstat::Cpu.new(30, 14676176, 20310412, 0, 2444413183), Vmstat::Cpu.new(31, 14400967, 22515695, 0, 2442483106) ] end end context "#memory" do subject { solaris.memory } it { should be_a(Vmstat::Memory) } if `getconf PAGESIZE`.chomp.to_i == 4096 it do should == Vmstat::Memory.new(4096, 409145, 9018, 0, 61103, 0, 0) end end end context "#boot_time" do subject { solaris.boot_time } it { should be_a(Time) } it { should == Time.at(1470765992) } end context "#network_interfaces" do subject { solaris.network_interfaces } it { should be_a(Array) } it do should == [ Vmstat::NetworkInterface.new(:e1000g0, 1000, 0, 0, 2000, 1, Vmstat::NetworkInterface::ETHERNET_TYPE) ] end end end vmstat-2.3.1/spec/vmstat/network_spec.rb0000644000004100000410000000225113433303705020364 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::NetworkInterface do context "Vmstat#network" do let(:network) { Vmstat.network_interfaces } it "should return the enthernet and loopback network data as an array" do network.should be_a(Array) end context "loopback device" do let(:loopback) { network.find { |interface| interface.loopback? } } subject { loopback } it "should be a vmstat network interface object" do should be_a(described_class) end context "methods" do it { should respond_to(:in_bytes) } it { should respond_to(:out_bytes) } it { should respond_to(:in_errors) } it { should respond_to(:out_errors) } it { should respond_to(:in_drops) } it { should respond_to(:type) } end context "content" do its(:in_bytes) { should be_a_kind_of(Numeric) } its(:out_bytes) { should be_a_kind_of(Numeric) } its(:in_errors) { should be_a_kind_of(Numeric) } its(:out_errors) { should be_a_kind_of(Numeric) } its(:in_drops) { should be_a_kind_of(Numeric) } its(:type) { should be_a_kind_of(Numeric) } end end end end vmstat-2.3.1/spec/vmstat/procfs_spec.rb0000644000004100000410000000365413433303705020177 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::ProcFS do let(:procfs) do Class.new do extend Vmstat::ProcFS def self.procfs_path File.expand_path("../../procfs", __FILE__) end end end subject { procfs } context "#cpu" do subject { procfs.cpu } it { should be_a(Array)} it do should == [ Vmstat::Cpu.new(0, 311, 966, 0, 26788), Vmstat::Cpu.new(1, 351, 862, 0, 27263), Vmstat::Cpu.new(2, 324, 1092, 0, 26698), Vmstat::Cpu.new(30, 326, 838, 0, 27581) ] end end context "#memory" do subject { procfs.memory } it { should be_a(Vmstat::Memory) } if `getconf PAGESIZE`.chomp.to_i == 4096 it do should == Vmstat::Memory.new(4096, 4906, 6508, 8405, 107017, 64599, 1104) end it "should have the right total" do (subject.wired_bytes + subject.active_bytes + subject.inactive_bytes + subject.free_bytes).should == 507344 * 1024 end end end context "#boot_time" do subject { procfs.boot_time } it { should be_a(Time) } it { Timecop.freeze(Time.now) { should == Time.now - 355.63 } } end context "#network_interfaces" do subject { procfs.network_interfaces } it { should be_a(Array) } it do should == [ Vmstat::NetworkInterface.new(:lo, 3224, 0, 0, 3224, 0, Vmstat::NetworkInterface::LOOPBACK_TYPE), Vmstat::NetworkInterface.new(:eth1, 0, 1, 2, 0, 3, Vmstat::NetworkInterface::ETHERNET_TYPE), Vmstat::NetworkInterface.new(:eth0, 33660, 0, 0, 36584, 0, Vmstat::NetworkInterface::ETHERNET_TYPE) ] end end context "#task" do subject { procfs.task } it { should be_a(Vmstat::Task) } if `getconf PAGESIZE`.chomp.to_i == 4096 it { should == Vmstat::Task.new(4807, 515, 2000, 0) } end end end vmstat-2.3.1/spec/vmstat/memavail_spec.rb0000644000004100000410000000133613433303705020471 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::LinuxMemory do let(:procfs) do Class.new do extend Vmstat::ProcFS def self.procfs_path File.expand_path("../../memavail_procfs", __FILE__) end end end context "#memory" do subject { procfs.memory } it { should be_a(Vmstat::LinuxMemory) } if `getconf PAGESIZE`.chomp.to_i == 4096 it do should == Vmstat::LinuxMemory.new(4096, 36522, 326978, 44494, 63113, 64599, 1104) end it "should have the right total" do (subject.wired_bytes + subject.active_bytes + subject.inactive_bytes + subject.free_bytes).should == 1929654272 end end end end vmstat-2.3.1/spec/vmstat/snapshot_spec.rb0000644000004100000410000000274013433303705020535 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::Snapshot do context "Vmstat#snapshot" do let(:snapshot) { Vmstat.snapshot } subject { snapshot } it "should be an vmstat load snapshot object" do should be_a(described_class) end context "methods" do it { should respond_to(:at) } it { should respond_to(:boot_time) } it { should respond_to(:cpus) } it { should respond_to(:disks) } it { should respond_to(:load_average) } it { should respond_to(:memory) } it { should respond_to(:network_interfaces) } it { should respond_to(:task) } end context "content" do its(:at) { should be_a(Time) } its(:boot_time) { should be_a(Time) } its(:cpus) { should be_a(Array) } its(:disks) { should be_a(Array) } its(:load_average) { should be_a(Vmstat::LoadAverage) } its(:memory) { should be_a(Vmstat::Memory) } its(:network_interfaces) { should be_a(Array) } if RUBY_PLATFORM =~ /darwin|linux/ its(:task) { should be_a(Vmstat::Task) } end context "first of cpu" do subject { snapshot.cpus.first } it { should be_a(Vmstat::Cpu) } end context "first of disks" do subject { snapshot.disks.first } it { should be_a(Vmstat::Disk) } end context "first of network interfaces" do subject { snapshot.network_interfaces.first } it { should be_a(Vmstat::NetworkInterface) } end end end end vmstat-2.3.1/spec/vmstat/memory_spec.rb0000644000004100000410000000415113433303705020204 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::Memory do context "sample" do let(:disk) { described_class.new 4096, 775581, 196146, 437495, 685599, 1560532, 0 } subject { disk } its(:pagesize) { should == 4096 } its(:wired) { should == 775581 } its(:active) { should == 196146 } its(:inactive) { should == 437495 } its(:free) { should == 685599 } its(:wired_bytes) { should == 3176779776 } its(:active_bytes) { should == 803414016 } its(:inactive_bytes) { should == 1791979520 } its(:free_bytes) { should == 2808213504 } its(:total_bytes) { should == 8580386816 } its(:pageins) { should == 1560532 } its(:pageouts) { should == 0 } end context "Vmstat#memory" do let(:memory) { Vmstat.memory } subject { memory } it "should be a vmstat memory object" do should be_a(described_class) end context "methods" do it { should respond_to(:pagesize) } it { should respond_to(:wired) } it { should respond_to(:active) } it { should respond_to(:inactive) } it { should respond_to(:free) } it { should respond_to(:pageins) } it { should respond_to(:pageouts) } it { should respond_to(:wired_bytes) } it { should respond_to(:active_bytes) } it { should respond_to(:inactive_bytes) } it { should respond_to(:free_bytes) } it { should respond_to(:total_bytes)} end context "content" do its(:pagesize) { should be_a_kind_of(Numeric) } its(:wired) { should be_a_kind_of(Numeric) } its(:active) { should be_a_kind_of(Numeric) } its(:inactive) { should be_a_kind_of(Numeric) } its(:free) { should be_a_kind_of(Numeric) } its(:pageins) { should be_a_kind_of(Numeric) } its(:pageouts) { should be_a_kind_of(Numeric) } its(:wired_bytes) { should be_a_kind_of(Numeric) } its(:active_bytes) { should be_a_kind_of(Numeric) } its(:inactive_bytes) { should be_a_kind_of(Numeric) } its(:free_bytes) { should be_a_kind_of(Numeric) } its(:total_bytes) { should be_a_kind_of(Numeric) } end end end vmstat-2.3.1/spec/vmstat/task_spec.rb0000644000004100000410000000136213433303705017637 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::Task do context "Vmstat#task" do let(:task) { Vmstat.task } subject { task } it "should be a vmstat task object" do should be_a(described_class) end context "methods" do it { should respond_to(:virtual_size) } it { should respond_to(:resident_size) } it { should respond_to(:user_time_ms) } it { should respond_to(:system_time_ms) } end context "content" do its(:virtual_size) { should be_a_kind_of(Numeric) } its(:resident_size) { should be_a_kind_of(Numeric) } its(:user_time_ms) { should be_a_kind_of(Numeric) } its(:system_time_ms) { should be_a_kind_of(Numeric) } end end end if RUBY_PLATFORM =~ /darwin|linux/ vmstat-2.3.1/spec/vmstat/load_average_spec.rb0000644000004100000410000000111013433303705021275 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::LoadAverage do context "Vmstat#load_average" do subject { Vmstat.load_average } it "should be an vmstat load average object" do should be_a(described_class) end context "methods" do it { should respond_to(:one_minute) } it { should respond_to(:five_minutes) } it { should respond_to(:fifteen_minutes) } end context "content" do its(:one_minute) { should be_a(Float) } its(:five_minutes) { should be_a(Float) } its(:fifteen_minutes) { should be_a(Float) } end end end vmstat-2.3.1/spec/vmstat/disk_spec.rb0000644000004100000410000000310013433303705017617 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat::Disk do context "sample" do let(:disk) { described_class.new :hfs, "/dev/disk0", "/mnt/test", 4096, 100, 200, 600 } subject { disk } its(:type) { should == :hfs } its(:origin) { should == "/dev/disk0" } its(:mount) { should == "/mnt/test" } its(:block_size) { should == 4096 } its(:free_blocks) { should == 100 } its(:available_blocks) { should == 200 } its(:total_blocks) { should == 600 } its(:free_bytes) { should == 409600 } its(:available_bytes) { should == 819200 } its(:used_bytes) { should == 2048000 } its(:total_bytes) { should == 2457600 } end context "Vmstat#disk" do let(:disk) { Vmstat.disk("/") } subject { disk } it "should be a vmstat disk object" do should be_a(described_class) end context "methods" do it { should respond_to(:type) } it { should respond_to(:origin) } it { should respond_to(:mount) } it { should respond_to(:free_bytes) } it { should respond_to(:available_bytes) } it { should respond_to(:used_bytes) } it { should respond_to(:total_bytes) } end context "content" do its(:type) { should be_a(Symbol) } its(:origin) { should be_a(String) } its(:mount) { should be_a(String) } its(:free_bytes) { should be_a_kind_of(Numeric) } its(:available_bytes) { should be_a_kind_of(Numeric) } its(:used_bytes) { should be_a_kind_of(Numeric) } its(:total_bytes) { should be_a_kind_of(Numeric) } end end end vmstat-2.3.1/spec/memavail_procfs/0000755000004100000410000000000013433303705017165 5ustar www-datawww-datavmstat-2.3.1/spec/memavail_procfs/meminfo0000644000004100000410000000225613433303705020547 0ustar www-datawww-dataMemTotal: 1884428 kB MemFree: 252452 kB MemAvailable: 458368 kB Buffers: 76 kB Cached: 321752 kB SwapCached: 4 kB Active: 1307912 kB Inactive: 177976 kB Active(anon): 1074332 kB Inactive(anon): 106548 kB Active(file): 233580 kB Inactive(file): 71428 kB Unevictable: 21100 kB Mlocked: 21100 kB SwapTotal: 2097148 kB SwapFree: 2097140 kB Dirty: 60 kB Writeback: 0 kB AnonPages: 1185204 kB Mapped: 101384 kB Shmem: 8760 kB Slab: 59380 kB SReclaimable: 27064 kB SUnreclaim: 32316 kB KernelStack: 4528 kB PageTables: 21592 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 3039360 kB Committed_AS: 2906080 kB VmallocTotal: 34359738367 kB VmallocUsed: 269704 kB VmallocChunk: 34359466492 kB HardwareCorrupted: 0 kB AnonHugePages: 659456 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 26624 kB DirectMap2M: 2070528 kB vmstat-2.3.1/spec/memavail_procfs/vmstat0000644000004100000410000000333113433303705020426 0ustar www-datawww-datanr_free_pages 107062 nr_inactive_anon 60 nr_active_anon 1557 nr_inactive_file 8341 nr_active_file 4939 nr_unevictable 0 nr_mlock 0 nr_anon_pages 1579 nr_mapped 1461 nr_file_pages 13346 nr_dirty 1 nr_writeback 0 nr_slab_reclaimable 1628 nr_slab_unreclaimable 1885 nr_page_table_pages 101 nr_kernel_stack 88 nr_unstable 0 nr_bounce 0 nr_vmscan_write 0 nr_vmscan_immediate_reclaim 0 nr_writeback_temp 0 nr_isolated_anon 0 nr_isolated_file 0 nr_shmem 67 nr_dirtied 185 nr_written 182 nr_anon_transparent_hugepages 0 nr_dirty_threshold 24392 nr_dirty_background_threshold 12196 pgpgin 64599 pgpgout 1104 pswpin 0 pswpout 0 pgalloc_dma 2 pgalloc_normal 190973 pgalloc_high 0 pgalloc_movable 0 pgfree 298439 pgactivate 5802 pgdeactivate 0 pgfault 581461 pgmajfault 42 pgrefill_dma 0 pgrefill_normal 0 pgrefill_high 0 pgrefill_movable 0 pgsteal_dma 0 pgsteal_normal 0 pgsteal_high 0 pgsteal_movable 0 pgscan_kswapd_dma 0 pgscan_kswapd_normal 0 pgscan_kswapd_high 0 pgscan_kswapd_movable 0 pgscan_direct_dma 0 pgscan_direct_normal 0 pgscan_direct_high 0 pgscan_direct_movable 0 pginodesteal 0 slabs_scanned 0 kswapd_steal 0 kswapd_inodesteal 0 kswapd_low_wmark_hit_quickly 0 kswapd_high_wmark_hit_quickly 0 kswapd_skip_congestion_wait 0 pageoutrun 1 allocstall 0 pgrotated 0 compact_blocks_moved 0 compact_pages_moved 0 compact_pagemigrate_failed 0 compact_stall 0 compact_fail 0 compact_success 0 htlb_buddy_alloc_success 0 htlb_buddy_alloc_fail 0 unevictable_pgs_culled 0 unevictable_pgs_scanned 0 unevictable_pgs_rescued 0 unevictable_pgs_mlocked 0 unevictable_pgs_munlocked 0 unevictable_pgs_cleared 0 unevictable_pgs_stranded 0 unevictable_pgs_mlockfreed 0 thp_fault_alloc 0 thp_fault_fallback 0 thp_collapse_alloc 0 thp_collapse_alloc_failed 0 thp_split 0 vmstat-2.3.1/spec/procfs/0000755000004100000410000000000013433303705015312 5ustar www-datawww-datavmstat-2.3.1/spec/procfs/meminfo0000644000004100000410000000237413433303705016675 0ustar www-datawww-dataMemTotal: 507344 kB MemFree: 428068 kB Buffers: 13104 kB Cached: 40296 kB SwapCached: 0 kB Active: 26032 kB Inactive: 33620 kB Active(anon): 6276 kB Inactive(anon): 240 kB Active(file): 19756 kB Inactive(file): 33380 kB Unevictable: 0 kB Mlocked: 0 kB HighTotal: 0 kB HighFree: 0 kB LowTotal: 507344 kB LowFree: 428068 kB SwapTotal: 521212 kB SwapFree: 521212 kB Dirty: 8 kB Writeback: 0 kB AnonPages: 6240 kB Mapped: 5844 kB Shmem: 268 kB Slab: 14012 kB SReclaimable: 6476 kB SUnreclaim: 7536 kB KernelStack: 688 kB PageTables: 468 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 774884 kB Committed_AS: 48400 kB VmallocTotal: 512056 kB VmallocUsed: 2228 kB VmallocChunk: 509236 kB HardwareCorrupted: 0 kB AnonHugePages: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 34752 kB DirectMap2M: 489472 kB vmstat-2.3.1/spec/procfs/uptime0000644000004100000410000000001713433303705016536 0ustar www-datawww-data355.63 1302.86 vmstat-2.3.1/spec/procfs/vmstat0000644000004100000410000000333113433303705016553 0ustar www-datawww-datanr_free_pages 107062 nr_inactive_anon 60 nr_active_anon 1557 nr_inactive_file 8341 nr_active_file 4939 nr_unevictable 0 nr_mlock 0 nr_anon_pages 1579 nr_mapped 1461 nr_file_pages 13346 nr_dirty 1 nr_writeback 0 nr_slab_reclaimable 1628 nr_slab_unreclaimable 1885 nr_page_table_pages 101 nr_kernel_stack 88 nr_unstable 0 nr_bounce 0 nr_vmscan_write 0 nr_vmscan_immediate_reclaim 0 nr_writeback_temp 0 nr_isolated_anon 0 nr_isolated_file 0 nr_shmem 67 nr_dirtied 185 nr_written 182 nr_anon_transparent_hugepages 0 nr_dirty_threshold 24392 nr_dirty_background_threshold 12196 pgpgin 64599 pgpgout 1104 pswpin 0 pswpout 0 pgalloc_dma 2 pgalloc_normal 190973 pgalloc_high 0 pgalloc_movable 0 pgfree 298439 pgactivate 5802 pgdeactivate 0 pgfault 581461 pgmajfault 42 pgrefill_dma 0 pgrefill_normal 0 pgrefill_high 0 pgrefill_movable 0 pgsteal_dma 0 pgsteal_normal 0 pgsteal_high 0 pgsteal_movable 0 pgscan_kswapd_dma 0 pgscan_kswapd_normal 0 pgscan_kswapd_high 0 pgscan_kswapd_movable 0 pgscan_direct_dma 0 pgscan_direct_normal 0 pgscan_direct_high 0 pgscan_direct_movable 0 pginodesteal 0 slabs_scanned 0 kswapd_steal 0 kswapd_inodesteal 0 kswapd_low_wmark_hit_quickly 0 kswapd_high_wmark_hit_quickly 0 kswapd_skip_congestion_wait 0 pageoutrun 1 allocstall 0 pgrotated 0 compact_blocks_moved 0 compact_pages_moved 0 compact_pagemigrate_failed 0 compact_stall 0 compact_fail 0 compact_success 0 htlb_buddy_alloc_success 0 htlb_buddy_alloc_fail 0 unevictable_pgs_culled 0 unevictable_pgs_scanned 0 unevictable_pgs_rescued 0 unevictable_pgs_mlocked 0 unevictable_pgs_munlocked 0 unevictable_pgs_cleared 0 unevictable_pgs_stranded 0 unevictable_pgs_mlockfreed 0 thp_fault_alloc 0 thp_fault_fallback 0 thp_collapse_alloc 0 thp_collapse_alloc_failed 0 thp_split 0 vmstat-2.3.1/spec/procfs/net/0000755000004100000410000000000013433303705016100 5ustar www-datawww-datavmstat-2.3.1/spec/procfs/net/dev0000644000004100000410000000107113433303705016600 0ustar www-datawww-dataInter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 3224 40 0 0 0 0 0 0 3224 40 0 0 0 0 0 0 eth1: 0 0 1 2 0 0 0 0 0 0 3 4 0 0 0 0 eth0: 33660 227 0 0 0 0 0 0 36584 167 0 0 0 0 0 0 vmstat-2.3.1/spec/procfs/loadavg0000644000004100000410000000003113433303705016644 0ustar www-datawww-data0.24 0.32 0.21 1/79 2621 vmstat-2.3.1/spec/procfs/self/0000755000004100000410000000000013433303705016243 5ustar www-datawww-datavmstat-2.3.1/spec/procfs/self/stat0000644000004100000410000000034513433303705017143 0ustar www-datawww-data1587 (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 0vmstat-2.3.1/spec/procfs/stat0000644000004100000410000000333613433303705016215 0ustar www-datawww-datacpu 1312 0 3760 108331 788 0 169 0 0 0 cpu0 311 0 966 26788 520 0 109 0 0 0 cpu1 351 0 862 27263 162 0 15 0 0 0 cpu2 324 0 1092 26698 74 0 32 0 0 0 cpu30 326 0 838 27581 31 0 12 0 0 0 intr 39520 61 9 0 0 0 0 0 0 0 0 0 0 133 0 0 352 0 0 0 394 0 1864 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ctxt 29527 btime 1349885697 processes 1560 procs_running 1 procs_blocked 0 softirq 52656 0 26117 54 429 2037 0 3 6623 75 17318 vmstat-2.3.1/spec/vmstat_spec.rb0000644000004100000410000000276413433303705016704 0ustar www-datawww-datarequire 'spec_helper' describe Vmstat do context "#boot_time" do let(:boot_time) { Vmstat.boot_time } it "should be an array" do boot_time.should be_a(Time) end it "has to be a time before now" do boot_time.should < Time.now end end context "Vmstat#filter_devices" do unless travis? # no external ethernet devices on travis ci it "should filter ethernet devices" do Vmstat.ethernet_devices.size.should >= 1 end end it "should filter loopback devices" do Vmstat.loopback_devices.size.should >= 1 end end context "performance" do percent = RUBY_VERSION.to_i == 2 ? 26 : 10 shared_examples "a not memory leaking method" do |method_name, *args| it "should not grow the memory in method #{method_name} " + "more than #{percent}% " do mem_before = Vmstat.task.resident_size 10000.times { Vmstat.send(method_name, *args) } mem_after = Vmstat.task.resident_size mem_after.should < (mem_before * (1 + percent / 100.0)) end end it_should_behave_like "a not memory leaking method", :network_interfaces it_should_behave_like "a not memory leaking method", :cpu it_should_behave_like "a not memory leaking method", :memory it_should_behave_like "a not memory leaking method", :disk, "/" it_should_behave_like "a not memory leaking method", :boot_time it_should_behave_like "a not memory leaking method", :load_average end if ENV['PERF'] == "1" end vmstat-2.3.1/spec/spec_helper.rb0000644000004100000410000000156013433303705016636 0ustar www-datawww-data# This file was generated by the `rspec --init` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # Require this file using `require "spec_helper"` to ensure that it is only # loaded once. # # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration $:.unshift(File.expand_path("../lib", __FILE__)) require 'vmstat' require 'ostruct' require 'timecop' def travis? ENV['TRAVIS'] == 'true' end RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true config.filter_run :focus # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 config.order = 'random' end vmstat-2.3.1/.gitignore0000644000004100000410000000030513433303705015052 0ustar www-datawww-data*.gem *.rbc .bundle .config .yardoc .DS_Store InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp lib/vmstat/vmstat.bundle lib/vmstat/vmstat.so vmstat-2.3.1/examples/0000755000004100000410000000000013433303705014702 5ustar www-datawww-datavmstat-2.3.1/examples/rtop0000755000004100000410000000353713433303705015624 0ustar www-datawww-data#!/usr/bin/env ruby $:.unshift File.expand_path('../../lib', __FILE__) require 'vmstat' last = Vmstat.snapshot system 'clear' WIDTH = 60 class String def black; "\033[30m#{self}\033[0m" end def red; "\033[31m#{self}\033[0m" end def green; "\033[32m#{self}\033[0m" end def brown; "\033[33m#{self}\033[0m" end def blue; "\033[34m#{self}\033[0m" end def magenta; "\033[35m#{self}\033[0m" end def cyan; "\033[36m#{self}\033[0m" end def gray; "\033[37m#{self}\033[0m" end def bg_black; "\033[40m#{self}\033[0m" end def bg_red; "\033[41m#{self}\033[0m" end def bg_green; "\033[42m#{self}\033[0m" end def bg_brown; "\033[43m#{self}\033[0m" end def bg_blue; "\033[44m#{self}\033[0m" end def bg_magenta; "\033[45m#{self}\033[0m" end def bg_cyan; "\033[46m#{self}\033[0m" end def bg_gray; "\033[47m#{self}\033[0m" end def bold; "\033[1m#{self}\033[22m" end def reverse_color; "\033[7m#{self}\033[27m" end end MB = 1024 ** 2 loop do current = Vmstat.snapshot memory = current.memory free = (memory.free_bytes + memory.inactive_bytes) / MB used = (memory.active_bytes + memory.wired_bytes) / MB print "\033[0;0H" print "Memory Free: #{free.to_s.bg_gray.black} MB" print "\tUsed: #{used.to_s.bg_gray.black} MB" print "\tWired: #{(memory.wired_bytes / MB).to_s.bg_gray.black} MB" puts "\tTotal: #{(memory.total_bytes / MB).to_s.bg_gray.black} MB" current.cpus.each_with_index do |cpu, i| user = cpu.user - last.cpus[i].user system = cpu.system - last.cpus[i].system idle = cpu.idle - last.cpus[i].idle print "CPU #{i + 1} " print " ".bg_red * (system.to_f / 100.0 * WIDTH) print " ".bg_green * (user.to_f / 100.0 * WIDTH) print " " * (idle.to_f / 100.0 * WIDTH) puts end last = current sleep 1 end vmstat-2.3.1/Rakefile0000644000004100000410000000063213433303705014532 0ustar www-datawww-data#!/usr/bin/env rake require 'bundler/gem_tasks' require 'rake/extensiontask' require 'rspec/core/rake_task' Rake::ExtensionTask.new(:vmstat) do |ext| ext.lib_dir = 'lib/vmstat' end desc "Run specs" RSpec::Core::RakeTask.new(:spec => :compile) desc "Open an irb session preloaded with smartstat" task :console do sh "irb -rubygems -I ./lib -r vmstat" end desc 'Default: run specs.' task :default => :specvmstat-2.3.1/lib/0000755000004100000410000000000013433303705013632 5ustar www-datawww-datavmstat-2.3.1/lib/vmstat/0000755000004100000410000000000013433303705015150 5ustar www-datawww-datavmstat-2.3.1/lib/vmstat/version.rb0000644000004100000410000000004613433303705017162 0ustar www-datawww-datamodule Vmstat VERSION = "2.3.1" end vmstat-2.3.1/lib/vmstat/linux_memory.rb0000644000004100000410000000064313433303705020227 0ustar www-datawww-data# @attr [Fixnum] available # The estimated available memory (linux) # See: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773 class Vmstat::LinuxMemory < Vmstat::Memory attr_accessor :available # Calculate the available bytes based of the active pages. # @return [Fixnum] active bytes def available_bytes available * pagesize end end vmstat-2.3.1/lib/vmstat/snapshot.rb0000644000004100000410000000302213433303705017331 0ustar www-datawww-datamodule Vmstat # Snapshots help to gather information about the whole system quickly. # @attr [Time] at the timestamp, when the snapshot was created. # @attr [Time] boot_time the timestamp, when the system booted. # @attr [Array] cpus the data of each and every cpu. # @attr [Array] disks the disks that are part of the snapshot. # @attr [Vmstat::LoadAverage] load_average current load average at the time # when the snapshot toke place. # @attr [Vmstat::Memory] memory the memory data snapshot. # @attr [Array] network_interfaces the network # interface data snapshots per network interface. # @attr [Vmstat::Task] task optionally the information for the current task # @example Creating a snapshot # snapshop = Vmstat::Snapshop.new(["/dev/disk0", "/dev/disk1"]) class Snapshot attr_reader :at, :boot_time, :cpus, :disks, :load_average, :memory, :network_interfaces, :task # Create a new snapshot for system informations. The passed paths array, # should contain the disk paths to create a snapshot for. # @param [Array] paths the paths to create snapshots for def initialize(paths = []) @at = Time.now @boot_time = Vmstat.boot_time @cpus = Vmstat.cpu @disks = paths.map { |path| Vmstat.disk(path) } @load_average = Vmstat.load_average @memory = Vmstat.memory @network_interfaces = Vmstat.network_interfaces @task = Vmstat.task if Vmstat.respond_to? :task end end end vmstat-2.3.1/lib/vmstat/disk.rb0000644000004100000410000000272413433303705016434 0ustar www-datawww-datamodule Vmstat # Gathered disk statistics snapshot. # @attr [Symbol] type # The file system name e. g. *hfs*. # @attr [String] origin # The location of the device e.g. */dev/disk0*. # @attr [String] mount # The mount point of the device e.g. */mnt/store*. # @attr [Fixnum] block_size # Size of file system blocks in bytes. # @attr [Fixnum] free_blocks # Free blocks in the file system. # @attr [Fixnum] available_blocks # Available blocks in the file system. # @attr [Fixnum] total_blocks # Total number of blocks in the file system. class Disk < Struct.new(:type, :origin, :mount, :block_size, :free_blocks, :available_blocks, :total_blocks) # Calculates the number of free bytes for the file system. # @return [Fixnum] number of free bytes def free_bytes free_blocks * block_size end # Calculates the number of available bytes for the file system. # @return [Fixnum] number of available bytes def available_bytes available_blocks * block_size end # Calculates the number of used bytes for the file system. # @return [Fixnum] number of used bytes def used_bytes (total_blocks - free_blocks) * block_size end # Calculates the number of total bytes for the file system. This is the max. # number of bytes possible on the device. # @return [Fixnum] number of total bytes def total_bytes total_blocks * block_size end end end vmstat-2.3.1/lib/vmstat/procfs.rb0000644000004100000410000001266613433303705017004 0ustar www-datawww-datamodule Vmstat # Implementation of performance metrics gathering for linux and other os with # the proc file system. module ProcFS # Grep from the man procfs about cpu data in stat file: # @example Format # (num) user nice system idle iowait irq softirq steal # @example manpage # iowait - time waiting for I/O to complete (since 2.5.41) # irq - time servicing interrupts (since 2.6.0-test4) # softirq - time servicing softirqs (since 2.6.0-test4) # Since Linux 2.6.11: # steal - stolen time, which is the time spent in other operating # systems when running in a virtualized environment # Since Linux 2.6.24: # guest - which is the time spent running a virtual CPU for guest # operating systems under the control of the Linux kernel. CPU_DATA = /cpu(\d+)#{'\s+(\d+)' * 4}/.freeze # Grep the network stats from the procfs. # @example Format (from /proc/net/dev) # Inter-| Receive | Transmit # face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed # @example Data # eth0: 33660 227 0 0 0 0 0 0 36584 167 0 0 0 0 0 0 NET_DATA = /(\w+):#{'\s*(\d+)' * 16}/ # Fetches the cpu statistics (usage counter for user, nice, system and idle) # @return [Array] the array of cpu counter # @example # Vmstat.cpu # => [#, #] def cpu cpus = [] procfs_file("stat") do |file| file.read.scan(CPU_DATA) do |i, user, nice, system, idle| cpus << Cpu.new(i.to_i, user.to_i, system.to_i, nice.to_i, idle.to_i) end end cpus end # Fetches the memory usage information. # @return [Vmstat::Memory] the memory data like free, used und total. # @example # Vmstat.memory # => # def memory @pagesize ||= Vmstat.pagesize has_available = false total = free = active = inactive = pageins = pageouts = available = 0 procfs_file("meminfo") do |file| content = file.read(2048) # the requested information is in the first bytes content.scan(/(\w+):\s+(\d+) kB/) do |name, kbytes| pages = (kbytes.to_i * 1024) / @pagesize case name when "MemTotal" then total = pages when "MemFree" then free = pages when "MemAvailable" available = pages has_available = true when "Active" then active = pages when "Inactive" then inactive = pages end end end procfs_file("vmstat") do |file| content = file.read if content =~ /pgpgin\s+(\d+)/ pageins = $1.to_i end if content =~ /pgpgout\s+(\d+)/ pageouts = $1.to_i end end mem_klass = has_available ? LinuxMemory : Memory mem_klass.new(@pagesize, total-free-active-inactive, active, inactive, free, pageins, pageouts).tap do |mem| mem.available = available if has_available end end # Fetches the information for all available network devices. # @return [Array] the network device information # @example # Vmstat.network_interfaces # => [#, ...] def network_interfaces netifcs = [] procfs_file("net", "dev") do |file| file.read.scan(NET_DATA) do |columns| type = case columns[0] when /^eth/ then NetworkInterface::ETHERNET_TYPE when /^lo/ then NetworkInterface::LOOPBACK_TYPE end netifcs << NetworkInterface.new(columns[0].to_sym, columns[1].to_i, columns[3].to_i, columns[4].to_i, columns[9].to_i, columns[11].to_i, type) end end netifcs end # Fetches the current process cpu and memory data. # @return [Vmstat::Task] the task data for the current process def task @pagesize ||= Vmstat.pagesize procfs_file("self", "stat") do |file| data = file.read.split(/ /) Task.new(data[22].to_i / @pagesize, data[23].to_i, data[13].to_i * 1000, data[14].to_i * 1000) end end # Fetches the boot time of the system. # @return [Time] the boot time as regular time object. # @example # Vmstat.boot_time # => 2012-10-09 18:42:37 +0200 def boot_time raw = procfs_file("uptime") { |file| file.read } Time.now - raw.split(/\s/).first.to_f end # @return [String] the path to the proc file system # @example # procfs_path # => "/proc" # @api private def procfs_path "/proc".freeze end # Opens a proc file system file handle and returns the handle in the # passed block. Closes the file handle. # @see File#open # @param [Array] names parts of the path to the procfs file # @example # procfs_file("net", "dev") { |file| } # procfs_file("stat") { |file| } # @yieldparam [IO] file the file handle # @api private def procfs_file(*names, &block) path = File.join(procfs_path, *names) File.open(path, "r", &block) end end end vmstat-2.3.1/lib/vmstat/memory.rb0000644000004100000410000000347013433303705017011 0ustar www-datawww-datamodule Vmstat # Gathered memory data snapshot. # @attr [Fixnum] pagesize # The page size of the memory in bytes. # @attr [Fixnum] wired # The number of wired pages in the system. # @attr [Fixnum] active # The number of active pages in the system. # @attr [Fixnum] inactive # The number of inactive pages in the system. # @attr [Fixnum] free # The number of free pages in the system. # @attr [Fixnum] pageins # The number of pageins. # @attr [Fixnum] pageouts # The number of pageouts. class Memory < Struct.new(:pagesize, :wired, :active, :inactive, :free, :pageins, :pageouts) # Calculate the wired bytes based of the wired pages. # @return [Fixnum] wired bytes def wired_bytes wired * pagesize end # Calculate the active bytes based of the active pages. # @return [Fixnum] active bytes def active_bytes active * pagesize end # Calculate the inactive bytes based of the inactive pages. # @return [Fixnum] inactive bytes def inactive_bytes inactive * pagesize end # Calculate the free bytes based of the free pages. # @return [Fixnum] free bytes def free_bytes free * pagesize end # Calculate the total bytes based of all pages # @return [Fixnum] total bytes def total_bytes (wired + active + inactive + free) * pagesize end end # @attr [Fixnum] available # The estimated available memory (linux) # See: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773 class LinuxMemory < Memory attr_accessor :available # Calculate the available bytes based of the active pages. # @return [Fixnum] active bytes def available_bytes available * pagesize end end end vmstat-2.3.1/lib/vmstat/cpu.rb0000644000004100000410000000113713433303705016266 0ustar www-datawww-datamodule Vmstat # Gathered cpu performance statistics snapshot. # @attr [Fixnum] num # The number of the cpu starting at 0 for the first cpu. # @attr [Fixnum] user # Current counter of ticks spend in user. The counter can overflow. # @attr [Fixnum] system # Current counter of ticks spend in system. The counter can overflow. # @attr [Fixnum] nice # Current counter of ticks spend in nice. The counter can overflow. # @attr [Fixnum] idle # Current counter of ticks spend in idle. The counter can overflow. class Cpu < Struct.new(:num, :user, :system, :nice, :idle) end end vmstat-2.3.1/lib/vmstat/netopenbsd.rb0000644000004100000410000000347013433303705017642 0ustar www-datawww-datamodule Vmstat def self.cpu cptime = `sysctl kern.cp_time`.split(/=/).last user, nice, sys, irq, idle = cptime.split(/,/).map(&:to_i) [Cpu.new(0, user, sys + irq, nice, idle)] end def self.memory uvmexp = `vmstat -s` Memory.new( # pagesize call is not used to avoid double shell out pagesize, # pagesize extract_uvm_val(uvmexp, 'pages managed'), # wired extract_uvm_val(uvmexp, 'pages active'), # active extract_uvm_val(uvmexp, 'pages inactive'), # inactive extract_uvm_val(uvmexp, 'pages free'), # free extract_uvm_val(uvmexp, 'pagein operations'), # pageins extract_uvm_val(uvmexp, 'pages being paged out') # pageouts ) end def self.network_interfaces bytes = `netstat -ibq`.lines.grep(//) # bytes pkgs = `netstat -iqd`.lines.grep(//) # packages itf = Hash.new { |h, k| h[k] = NetworkInterface.new(k) } bytes.each do |line| # Name Mtu Network Address Ibytes Obytes name, _, _, _, ibytes, obytes = line.split(/\s+/) itf[name].in_bytes = ibytes.to_i itf[name].out_bytes = obytes.to_i end pkgs.each do |line| # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Colls Drop name, _, _, _, _, ierrs, _, oerrs, _, drop = line.split(/\s+/) itf[name].in_errors = ierrs.to_i itf[name].in_drops = drop.to_i itf[name].out_errors = oerrs.to_i end itf.each do |name, nic| if name =~ /lo\d+/ nic.type = NetworkInterface::LOOPBACK_TYPE else nic.type = NetworkInterface::ETHERNET_TYPE end end itf.values end def self.extract_uvm_val(uvmexp, name) regexp = Regexp.new('(\d+)\s' + name) uvmexp.lines.grep(regexp) do |line| return $1.to_i end end end vmstat-2.3.1/lib/vmstat/solaris.rb0000644000004100000410000000412413433303705017152 0ustar www-datawww-datamodule Vmstat module Solaris module ClassMethods def cpu kstat = `kstat -p "cpu_stat:::/idle|kernel|user/"` cpus = Hash.new { |h, k| h[k] = Hash.new } kstat.lines.each do |line| _, cpu, _, key, value = line.strip.split(/:|\s+/) cpus[cpu.to_i][key] = value end cpus.map do |num, v| Cpu.new(num, v["user"].to_i, v["kernel"].to_i, 0, v["idle"].to_i) end end def boot_time Time.at(`kstat -p unix:::boot_time`.strip.split(/\s+/).last.to_i) end def memory kstat = `kstat -p -n system_pages` values = Hash.new kstat.lines.each do |line| _, _, _, key, value = line.strip.split(/:|\s+/) values[key] = value end total = values['pagestotal'].to_i free = values['pagesfree'].to_i locked = values['pageslocked'].to_i Memory.new(Vmstat.pagesize, locked, # wired total - free - locked, # active 0, # inactive free, # free 0, #pageins 0) #pageouts end def network_interfaces kstat = `kstat -p link:::` itfs = Hash.new { |h, k| h[k] = Hash.new } kstat.lines.each do |line| _, _, name, key, value = line.strip.split(/:|\s+/) itfs[name.to_sym][key] = value end itfs.map do |k, v| NetworkInterface.new(k, v['rbytes64'].to_i, v['ierrors'].to_i, 0, v['obytes64'].to_i, v['oerrors'].to_i, NetworkInterface::ETHERNET_TYPE) end end end extend ClassMethods def self.included base base.instance_eval do def cpu; Vmstat::Solaris.cpu end def boot_time; Vmstat::Solaris.boot_time end def memory; Vmstat::Solaris.memory end def network_interfaces; Vmstat::Solaris.network_interfaces end end end end end vmstat-2.3.1/lib/vmstat/task.rb0000644000004100000410000000104713433303705016441 0ustar www-datawww-datamodule Vmstat # Per task performance metrics snapshot. # @attr [Fixnum] virtual_size # The number of virtual pages for the task. # @attr [Fixnum] resident_size # The number of resident pages for the task # @attr [Fixnum] user_time_ms # The total user run time for terminated threads within the task. # @attr [Fixnum] system_time_ms # The total system run time for terminated threads within the task. class Task < Struct.new(:virtual_size, :resident_size, :user_time_ms, :system_time_ms) end end vmstat-2.3.1/lib/vmstat/linux_disk.rb0000644000004100000410000000414313433303705017650 0ustar www-datawww-datamodule Vmstat # Since on linux the type and mount information are note available in the # statfs library, we have to use constants to find out the file system type. # The mount point and the path will allways be the same, because we don't have # the mount information. But one can still either use the device or mountpoint # to get the information. class LinuxDisk < Disk # Mapping of file system type codes to file system names. FS_CODES = { 44533=>:adfs, 44543=>:affs, 1111905073=>:befs, 464386766=>:bfs, 4283649346=>:cifs_number, 1937076805=>:coda, 19920823=>:coh, 684539205=>:cramfs, 4979=>:devfs, 4278867=>:efs, 4989=>:ext, 61265=>:ext2_old, 61267=>:ext4, 16964=>:hfs, 4187351113=>:hpfs, 2508478710=>:hugetlbfs, 38496=>:isofs, 29366=>:jffs2, 827541066=>:jfs, 4991=>:minix, 9320=>:minix2, 9336=>:minix22, 19780=>:msdos, 22092=>:ncp, 26985=>:nfs, 1397118030=>:ntfs_sb, 40865=>:openprom, 40864=>:proc, 47=>:qnx4, 1382369651=>:reiserfs, 29301=>:romfs, 20859=>:smb, 19920822=>:sysv2, 19920821=>:sysv4, 16914836=>:tmpfs, 352400198=>:udf, 72020=>:ufs, 7377 => :devpts, 40866=>:usbdevice, 2768370933=>:vxfs, 19920820=>:xenix, 1481003842=>:xfs, 19911021=>:xiafs, 1448756819=>:reiserfs, 1650812274 => :sysfs }.freeze # Mainly a wrapper for the {Vmstat::Disk} class constructor. This constructor # handles the file system type mapping (based on the magic codes defined in # {LinuxDisk::FS_CODES}). # @param [Fixnum] fs the type or magix number of the disk. # @param [String] path the path to the disk # @param [Fixnum] block_size size of a file system block # @param [Fixnum] free_blocks the number of free blocks # @param [Fixnum] available_blocks the number of available blocks # @param [Fixnum] total_blocks the number of total blocks def initialize(fs = nil, path = nil, block_size = nil, free_blocks = nil, available_blocks = nil, total_blocks = nil) @fs = fs super FS_CODES[@fs], path, path, block_size, free_blocks, available_blocks, total_blocks end end end vmstat-2.3.1/lib/vmstat/network_interface.rb0000644000004100000410000000245313433303705021212 0ustar www-datawww-datamodule Vmstat # Gathered the network interface information. # @attr [Symbol] name the system name for the network interface. # @attr [Fixnum] in_bytes the number od bytes that where received inbound. # @attr [Fixnum] in_errors the number of errors that where received inbound. # @attr [Fixnum] in_drops the number of drops that where received inbound. # @attr [Fixnum] out_bytes the number od bytes that where send outbound. # @attr [Fixnum] out_errors the number od errors that where send outbound. # @attr [Fixnum] type the type of the interface (bsd numbers) class NetworkInterface < Struct.new(:name, :in_bytes, :in_errors, :in_drops, :out_bytes, :out_errors, :type) # The type of ethernet devices on freebsd/mac os x ETHERNET_TYPE = 0x06 # The type of loopback devices on freebsd/mac os x LOOPBACK_TYPE = 0x18 # Checks if this network interface is a loopback device. # @return [TrueClass, FalseClass] true if it is a loopback device, false # otherwise. def loopback? type == LOOPBACK_TYPE end # Checks if this network interface is a ethernet device. # @return [TrueClass, FalseClass] true if it is a ethernet device, false # otherwise. def ethernet? type == ETHERNET_TYPE end end end vmstat-2.3.1/lib/vmstat/load_average.rb0000644000004100000410000000102613433303705020105 0ustar www-datawww-datamodule Vmstat # In UNIX computing, the system load is a measure of the amount of # computational work that a computer system performs. The load average # represents the average system load over a period of time. # Source: wikipedia(en). # @attr [Float] one_minute The load for the last minute. # @attr [Float] five_minutes The load for the last five minutes. # @attr [Float] fifteen_minutes The load for the last fifteen minutes. class LoadAverage < Struct.new(:one_minute, :five_minutes, :fifteen_minutes) end end vmstat-2.3.1/lib/vmstat/stub.rb0000644000004100000410000000436313433303705016460 0ustar www-datawww-datamodule Vmstat # This is a stub module that should be replaced by system specific # implementations of the different functions. This can either be native or # with other modules like {ProcFS}. module Stub # Fetches the boot time of the system. # @return [Time] the boot time as regular time object. # @example # Vmstat.boot_time # => 2012-10-09 18:42:37 +0200 def self.boot_time nil end # Fetches the cpu statistics (usage counter for user, nice, system and idle) # @return [Array] the array of cpu counter # @example # Vmstat.cpu # => [#, #] def self.cpu [] end # Fetches the usage data and other useful disk information for the given path. # @param [String] path the path (mount point or device path) to the disk # @return [Vmstat::Disk] the disk information # @example # Vmstat.disk("/") # => # def self.disk(path) nil end # Fetches the load average for the current system. # @return [Vmstat::LoadAverage] the load average data # @example # Vmstat.load_average # => # def self.load_average nil end # Fetches the memory usage information. # @return [Vmstat::Memory] the memory data like free, used und total. # @example # Vmstat.memory # => # def self.memory nil end # Fetches the information for all available network devices. # @return [Array] the network device information # @example # Vmstat.network_interfaces # => [#, ...] def self.network_interfaces [] end # Fetches pagesize of the current system. # @return [Fixnum] the pagesize of the current system in bytes. # @example # Vmstat.pagesize # => 4096 def self.pagesize 4096 end # Fetches time and memory usage for the current process. # @note Currently only on Mac OS X # @return [Array] the network device information # @example # Vmstat.task # => # def self.task nil end end end vmstat-2.3.1/lib/vmstat.rb0000644000004100000410000000764713433303705015513 0ustar www-datawww-datarequire "vmstat/version" # This is a focused and fast library to get system information like: # # * _Memory_ (free, active, ...) # * _Network_ _Interfaces_ (name, in bytes, out bytes, ...) # * _CPU_ (user, system, nice, idle) # * _Load_ Average # * _Disk_ (type, disk path, free bytes, total bytes, ...) # * _Boot_ _Time_ # * _Current_ _Task_ (used bytes and usage time *MACOSX* or *LINUX* *ONLY*) module Vmstat autoload :Cpu, "vmstat/cpu" autoload :NetworkInterface, "vmstat/network_interface" autoload :Disk, "vmstat/disk" autoload :LinuxDisk, "vmstat/linux_disk" autoload :Memory, "vmstat/memory" autoload :LinuxMemory, "vmstat/linux_memory" autoload :Task, "vmstat/task" autoload :LoadAverage, "vmstat/load_average" autoload :ProcFS, "vmstat/procfs" autoload :Stub, "vmstat/stub" autoload :Snapshot, "vmstat/snapshot" autoload :Solaris, "vmstat/solaris" extend Stub # the default empty implementation # @!method self.boot_time # Fetches the boot time of the system. # @return [Time] the boot time as regular time object. # @example # Vmstat.boot_time # => 2012-10-09 18:42:37 +0200 # @!method self.cpu # Fetches the cpu statistics (usage counter for user, nice, system and idle) # @return [Array] the array of cpu counter # @example # Vmstat.cpu # => [#, #] # @!method self.disk(path) # Fetches the usage data and other useful disk information for the given path. # @param [String] path the path (mount point or device path) to the disk # @return [Vmstat::Disk] the disk information # @example # Vmstat.disk("/") # => # # @!method self.load_average # Fetches the load average for the current system. # @return [Vmstat::LoadAverage] the load average data # @example # Vmstat.load_average # => # # @!method self.memory # Fetches the memory usage information. # @return [Vmstat::Memory] the memory data like free, used und total. # @example # Vmstat.memory # => # # @!method self.network_interfaces # Fetches the information for all available network devices. # @return [Array] the network device information # @example # Vmstat.network_interfaces # => [#, ...] # @!method self.pagesize # Fetches pagesize of the current system. # @return [Fixnum] the pagesize of the current system in bytes. # @example # Vmstat.pagesize # => 4096 # @!method self.task # Fetches time and memory usage for the current process. # @note Currently only on Mac OS X # @return [Array] the network device information # @example # Vmstat.task # => # # Creates a full snapshot of the systems hardware statistics. # @param [Array] paths the paths to the disks to snapshot. # @return [Vmstat::Snapshot] a snapshot of all statistics. # @example # Vmstat.snapshot # => # def self.snapshot(paths = ["/"]) Snapshot.new(paths) end # Filters all available ethernet devices. # @return [Array] the ethernet devices def self.ethernet_devices network_interfaces.select(&:ethernet?) end # Filters all available loopback devices. # @return [Array] the loopback devices def self.loopback_devices network_interfaces.select(&:loopback?) end end require "vmstat/vmstat" # native lib if RUBY_PLATFORM =~ /linux/ Vmstat.send(:extend, Vmstat::ProcFS) elsif RUBY_PLATFORM =~ /(net|open)bsd/ # command based implementation of mem, net, cpu require "vmstat/netopenbsd" elsif RUBY_PLATFORM =~ /solaris|smartos/ # command based implementation of mem, net, cpu Vmstat.send(:include, Vmstat::Solaris) end vmstat-2.3.1/Guardfile0000644000004100000410000000035613433303705014715 0ustar www-datawww-data# A sample Guardfile # More info at https://github.com/guard/guard#readme guard 'rspec' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } end vmstat-2.3.1/.ruby-gemset0000644000004100000410000000000713433303705015325 0ustar www-datawww-datavmstat vmstat-2.3.1/vmstat.gemspec0000644000004100000410000000215713433303705015754 0ustar www-datawww-data# -*- encoding: utf-8 -*- lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'vmstat/version' Gem::Specification.new do |gem| gem.name = "vmstat" gem.version = Vmstat::VERSION gem.authors = ["Vincent Landgraf"] gem.email = ["vilandgr@googlemail.com"] gem.description = %q{ A focused and fast library to gather memory, cpu, network, load avg and disk information } gem.summary = %q{A focused and fast library to gather system information} gem.homepage = "http://threez.github.com/ruby-vmstat/" gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] gem.extensions = ["ext/vmstat/extconf.rb"] gem.add_development_dependency('rake', '~> 11.3') gem.add_development_dependency('rspec', '~> 2.9') gem.add_development_dependency('rake-compiler') gem.add_development_dependency('guard-rspec') gem.add_development_dependency('timecop') end vmstat-2.3.1/_config.yml0000644000004100000410000000003313433303705015207 0ustar www-datawww-datatheme: jekyll-theme-tactilevmstat-2.3.1/Gemfile0000644000004100000410000000022613433303705014357 0ustar www-datawww-datasource 'https://rubygems.org' # Specify your gem's dependencies in vmstat.gemspec gemspec gem 'rb-fsevent', '~> 0.9.1' if RUBY_PLATFORM =~ /darwin/ vmstat-2.3.1/.ruby-version0000644000004100000410000000000613433303705015525 0ustar www-datawww-data2.2.6 vmstat-2.3.1/ext/0000755000004100000410000000000013433303705013664 5ustar www-datawww-datavmstat-2.3.1/ext/vmstat/0000755000004100000410000000000013433303705015202 5ustar www-datawww-datavmstat-2.3.1/ext/vmstat/vmstat.c0000644000004100000410000000251413433303705016666 0ustar www-datawww-data#include #include #include #include #include #include void Init_vmstat() { VALUE vmstat = rb_define_module("Vmstat"); /* * Below the list of platform implementations. The Platforms in square * brackets are implemented in ruby not in c. */ // MAC, FreeBSD, [LINUX] #if defined(VMSTAT_NETWORK_INTERFACES) rb_define_singleton_method(vmstat, "network_interfaces", vmstat_network_interfaces, 0); #endif // MAC, FreeBSD, [LINUX] #if defined(VMSTAT_CPU) rb_define_singleton_method(vmstat, "cpu", vmstat_cpu, 0); #endif // MAC, FreeBSD, [LINUX] #if defined(VMSTAT_MEMORY) rb_define_singleton_method(vmstat, "memory", vmstat_memory, 0); #endif // MAC, FreeBSD, LINUX #if defined(VMSTAT_DISK) rb_define_singleton_method(vmstat, "disk", vmstat_disk, 1); #endif // MAC, FreeBSD, LINUX #if defined(VMSTAT_LOAD_AVERAGE) rb_define_singleton_method(vmstat, "load_average", vmstat_load_average, 0); #endif // MAC, FreeBSD, [LINUX] #if defined(VMSTAT_BOOT_TIME) rb_define_singleton_method(vmstat, "boot_time", vmstat_boot_time, 0); #endif // MAC #if defined(VMSTAT_TASK) rb_define_singleton_method(vmstat, "task", vmstat_task, 0); #endif // MAC, FreeBSD, LINUX #if defined(VMSTAT_PAGESIZE) rb_define_singleton_method(vmstat, "pagesize", vmstat_pagesize, 0); #endif } vmstat-2.3.1/ext/vmstat/extconf.rb0000644000004100000410000000445213433303705017202 0ustar www-datawww-datarequire 'mkmf' # posix.h have_header 'unistd.h' have_func 'getpagesize', 'unistd.h' have_header 'stdlib.h' if have_header 'sys/loadavg.h' have_func 'getloadavg', 'sys/loadavg.h' else have_func 'getloadavg' end # mach.h have_header 'mach/mach.h' have_header 'mach/mach_host.h' have_func 'host_processor_info' have_func 'mach_host_self' have_func 'mach_task_self' have_func 'vm_deallocate' have_func 'mach_error_string' have_func 'task_info' mach_headers = ['mach/mach.h', 'mach/mach_host.h'] have_const 'KERN_SUCCESS', mach_headers have_const 'TASK_BASIC_INFO', mach_headers have_const 'HOST_VM_INFO', mach_headers have_const 'CPU_STATE_MAX', mach_headers have_const 'PROCESSOR_CPU_LOAD_INFO', mach_headers have_const 'CPU_STATE_USER', mach_headers have_const 'CPU_STATE_SYSTEM', mach_headers have_const 'CPU_STATE_NICE', mach_headers have_const 'CPU_STATE_IDLE', mach_headers # statfs.h have_header 'sys/param.h' have_header 'sys/mount.h' have_header 'sys/statfs.h' have_func 'statfs' have_struct_member('struct statfs', 'f_type', ['sys/param.h', 'sys/mount.h', 'sys/statfs.h']) have_struct_member('struct statfs', 'f_fstypename', ['sys/param.h', 'sys/mount.h']) have_func 'statvfs', ['sys/types.h', 'sys/statvfs.h'] have_struct_member('struct statvfs', 'f_basetype', ['sys/types.h', 'sys/statvfs.h']) # sysctl.h sys_headers = ['unistd.h', 'sys/sysctl.h', 'sys/types.h', 'sys/socket.h', 'net/if.h', 'net/if_types.h'] sys_headers.each { |header| have_header header } sys_headers << 'net/if_mib.h' if not have_header('net/if_mib.h') puts "-> net/if_mib.h can't be checked individually, apply workaround for macOS mojave" have_header 'net/if_mib.h', ['net/if_types.h', 'net/if.h'] end have_func 'getloadavg' have_func 'sysctl' have_type 'struct ifmibdata', sys_headers have_const 'CTL_NET', sys_headers have_const 'PF_LINK', sys_headers have_const 'NETLINK_GENERIC', sys_headers have_const 'IFMIB_IFDATA', sys_headers have_const 'IFDATA_GENERAL', sys_headers have_const 'CTL_KERN', ['sys/sysctl.h', 'sys/types.h'] have_const 'KERN_BOOTTIME', ['sys/sysctl.h', 'sys/types.h'] # bsd.h # only if we have *bsd like stats check for sysctlbyname if xsystem 'sysctl vm.stats.vm.v_page_size' have_header 'sys/sysctl.h' have_header 'sys/types.h' have_func 'sysctlbyname' end create_header create_makefile 'vmstat/vmstat'vmstat-2.3.1/ext/vmstat/vmstat.h0000644000004100000410000000061313433303705016671 0ustar www-datawww-data#include #ifndef _VMSTAT_H_ #define _VMSTAT_H_ #define AVGCOUNT 3 VALUE vmstat_network_interfaces(VALUE self); VALUE vmstat_cpu(VALUE self); VALUE vmstat_memory(VALUE self); VALUE vmstat_disk(VALUE self, VALUE path); VALUE vmstat_load_average(VALUE self); VALUE vmstat_boot_time(VALUE self); VALUE vmstat_task(VALUE self); VALUE vmstat_pagesize(VALUE self); #endif /* _VMSTAT_H_ */ vmstat-2.3.1/ext/vmstat/hw/0000755000004100000410000000000013433303705015620 5ustar www-datawww-datavmstat-2.3.1/ext/vmstat/hw/mach.h0000644000004100000410000000630513433303705016705 0ustar www-datawww-data#if defined(HAVE_MACH_MACH_H) #include #include #include #ifndef VMSTAT_CPU #define VMSTAT_CPU VALUE vmstat_cpu(VALUE self) { VALUE cpus = rb_ary_new(); processor_info_array_t cpuInfo; mach_msg_type_number_t numCpuInfo; natural_t numCPUsU = 0U; kern_return_t err = host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numCPUsU, &cpuInfo, &numCpuInfo); if(err == KERN_SUCCESS) { unsigned i; for(i = 0U; i < numCPUsU; ++i) { int pos = CPU_STATE_MAX * i; VALUE cpu = rb_funcall(rb_path2class("Vmstat::Cpu"), rb_intern("new"), 5, ULL2NUM(i), ULL2NUM(cpuInfo[pos + CPU_STATE_USER]), ULL2NUM(cpuInfo[pos + CPU_STATE_SYSTEM]), ULL2NUM(cpuInfo[pos + CPU_STATE_NICE]), ULL2NUM(cpuInfo[pos + CPU_STATE_IDLE])); rb_ary_push(cpus, cpu); } err = vm_deallocate(mach_task_self(), (vm_address_t)cpuInfo, (vm_size_t)sizeof(*cpuInfo) * numCpuInfo); if (err != KERN_SUCCESS) { rb_bug("vm_deallocate: %s\n", mach_error_string(err)); } } return cpus; } #endif #ifndef VMSTAT_MEMORY #define VMSTAT_MEMORY VALUE vmstat_memory(VALUE self) { VALUE memory = Qnil; vm_size_t pagesize; uint host_count = HOST_VM_INFO_COUNT; kern_return_t err; vm_statistics_data_t vm_stat; err = host_page_size(mach_host_self(), &pagesize); if (err == KERN_SUCCESS) { err = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stat, &host_count); if (err == KERN_SUCCESS) { memory = rb_funcall(rb_path2class("Vmstat::Memory"), rb_intern("new"), 7, ULL2NUM(pagesize), ULL2NUM(vm_stat.active_count), ULL2NUM(vm_stat.inactive_count), ULL2NUM(vm_stat.wire_count), ULL2NUM(vm_stat.free_count), ULL2NUM(vm_stat.pageins), ULL2NUM(vm_stat.pageouts)); } err = vm_deallocate(mach_task_self(), (vm_address_t)pagesize, (vm_size_t)host_count); if (err != KERN_SUCCESS) { rb_bug("vm_deallocate: %s\n", mach_error_string(err)); } } return memory; } #endif #ifndef VMSTAT_TASK #define VMSTAT_TASK VALUE vmstat_task(VALUE self) { VALUE task = Qnil; struct task_basic_info info; kern_return_t err; mach_msg_type_number_t size = sizeof(info); err = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size); if (err == KERN_SUCCESS) { task = rb_funcall(rb_path2class("Vmstat::Task"), rb_intern("new"), 4, LONG2NUM(info.virtual_size), LONG2NUM(info.resident_size), LONG2NUM(info.user_time.seconds * 1000 + info.user_time.microseconds), LONG2NUM(info.system_time.seconds * 1000 + info.system_time.microseconds)); } else { rb_bug("task_info: %s\n", mach_error_string(err)); } return task; } #endif #endif vmstat-2.3.1/ext/vmstat/hw/posix.h0000644000004100000410000000136413433303705017137 0ustar www-datawww-data#if defined(HAVE_UNISTD_H) #include #endif #if defined(HAVE_GETPAGESIZE) #ifndef VMSTAT_PAGESIZE #define VMSTAT_PAGESIZE VALUE vmstat_pagesize(VALUE self) { return INT2NUM(getpagesize()); } #endif #endif #if defined(HAVE_SYS_LOADAVG_H) #include #endif #if defined(HAVE_GETLOADAVG) #ifndef VMSTAT_LOAD_AVERAGE #define VMSTAT_LOAD_AVERAGE VALUE vmstat_load_average(VALUE self) { VALUE load = Qnil; double loadavg[AVGCOUNT]; getloadavg(&loadavg[0], AVGCOUNT); load = rb_funcall(rb_path2class("Vmstat::LoadAverage"), rb_intern("new"), 3, rb_float_new(loadavg[0]), rb_float_new(loadavg[1]), rb_float_new(loadavg[2])); return load; } #endif #endif vmstat-2.3.1/ext/vmstat/hw/sysctl.h0000644000004100000410000000442513433303705017317 0ustar www-datawww-data#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYS_TYPES_H) && \ defined(HAVE_CONST_CTL_KERN) && defined(HAVE_CONST_KERN_BOOTTIME) #include #include #include #ifndef VMSTAT_BOOT_TIME #define VMSTAT_BOOT_TIME static int BOOT_TIME_MIB[] = { CTL_KERN, KERN_BOOTTIME }; VALUE vmstat_boot_time(VALUE self) { struct timeval tv; size_t size = sizeof(tv); if (sysctl(BOOT_TIME_MIB, 2, &tv, &size, NULL, 0) == 0) { return rb_time_new(tv.tv_sec, tv.tv_usec); } else { return Qnil; } } #endif // VMSTAT_BOOT_TIME #if defined(HAVE_SYS_SOCKET_H) && defined(HAVE_NET_IF_H) && \ defined(HAVE_NET_IF_MIB_H) && defined(HAVE_NET_IF_TYPES_H) && \ defined(HAVE_GETLOADAVG) && defined(HAVE_SYSCTL) && \ defined(HAVE_TYPE_STRUCT_IFMIBDATA) && defined(HAVE_CONST_CTL_NET) && \ defined(HAVE_CONST_PF_LINK) && defined(HAVE_CONST_NETLINK_GENERIC) && \ defined(HAVE_CONST_IFMIB_IFDATA) && defined(HAVE_CONST_IFDATA_GENERAL) #include #include #include #include #ifndef VMSTAT_NETWORK_INTERFACES #define VMSTAT_NETWORK_INTERFACES VALUE vmstat_network_interfaces(VALUE self) { VALUE devices = rb_ary_new(); int i, err; struct ifmibdata mibdata; size_t len = sizeof(mibdata); int ifmib_path[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, -1, IFDATA_GENERAL }; for (i = 1, err = 0; err == 0; i++) { ifmib_path[4] = i; // set the current row err = sysctl(ifmib_path, 6, &mibdata, &len, NULL, 0); if (err == 0) { VALUE device = rb_funcall(rb_path2class("Vmstat::NetworkInterface"), rb_intern("new"), 7, ID2SYM(rb_intern(mibdata.ifmd_name)), ULL2NUM(mibdata.ifmd_data.ifi_ibytes), ULL2NUM(mibdata.ifmd_data.ifi_ierrors), ULL2NUM(mibdata.ifmd_data.ifi_iqdrops), ULL2NUM(mibdata.ifmd_data.ifi_obytes), ULL2NUM(mibdata.ifmd_data.ifi_oerrors), ULL2NUM(mibdata.ifmd_data.ifi_type)); rb_ary_push(devices, device); } } return devices; } #endif // VMSTAT_NETWORK_INTERFACES #endif #endif vmstat-2.3.1/ext/vmstat/hw/statfs.h0000644000004100000410000000417413433303705017303 0ustar www-datawww-data#if defined(HAVE_STATFS) && (defined(HAVE_STRUCT_STATFS_F_TYPE) || defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)) #include #include #include // on linux require statfs too #if defined(HAVE_SYS_STATFS_H) #include #endif #ifndef VMSTAT_DISK #define VMSTAT_DISK VALUE vmstat_disk(VALUE self, VALUE path) { VALUE disk = Qnil; struct statfs stat; if (statfs(StringValueCStr(path), &stat) != -1) { #if defined(HAVE_SYS_STATFS_H) disk = rb_funcall(rb_path2class("Vmstat::LinuxDisk"), rb_intern("new"), 6, ULL2NUM(stat.f_type), path, ULL2NUM(stat.f_bsize), ULL2NUM(stat.f_bfree), ULL2NUM(stat.f_bavail), ULL2NUM(stat.f_blocks)); #else disk = rb_funcall(rb_path2class("Vmstat::Disk"), rb_intern("new"), 7, ID2SYM(rb_intern(stat.f_fstypename)), rb_str_new(stat.f_mntfromname, strlen(stat.f_mntfromname)), rb_str_new(stat.f_mntonname, strlen(stat.f_mntonname)), ULL2NUM(stat.f_bsize), ULL2NUM(stat.f_bfree), ULL2NUM(stat.f_bavail), ULL2NUM(stat.f_blocks)); #endif } return disk; } #endif #endif #if defined(HAVE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_BASETYPE) #include #include #include #ifndef VMSTAT_DISK #define VMSTAT_DISK VALUE vmstat_disk(VALUE self, VALUE path) { VALUE disk = Qnil; struct statvfs stat; if (statvfs(StringValueCStr(path), &stat) == 0) { disk = rb_funcall(rb_path2class("Vmstat::LinuxDisk"), rb_intern("new"), 6, ID2SYM(rb_intern(stat.f_basetype)), path, ULL2NUM(stat.f_bsize), ULL2NUM(stat.f_bfree), ULL2NUM(stat.f_bavail), ULL2NUM(stat.f_blocks)); } return disk; } #endif #endif vmstat-2.3.1/ext/vmstat/hw/bsd.h0000644000004100000410000000462113433303705016544 0ustar www-datawww-data#if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYS_TYPES_H) && \ defined(HAVE_SYSCTLBYNAME) #include #include #include // helper methods int system_int(const char *); unsigned int system_uint(const char *); typedef struct { long user; long nice; long system; long intr; long idle; } cpu_time_t; #ifndef VMSTAT_CPU #define VMSTAT_CPU VALUE vmstat_cpu(VALUE self) { VALUE cpus = rb_ary_new(); int cpu_count = system_int("hw.ncpu"); size_t len = sizeof(cpu_time_t) * cpu_count; cpu_time_t * cp_times = ALLOC_N(cpu_time_t, cpu_count); cpu_time_t * cp_time; int i; if (sysctlbyname("kern.cp_times", cp_times, &len, NULL, 0) == 0) { for (i = 0; i < cpu_count; i++) { cp_time = &cp_times[i]; VALUE cpu = rb_funcall(rb_path2class("Vmstat::Cpu"), rb_intern("new"), 5, ULL2NUM(i), ULL2NUM(cp_time->user), ULL2NUM(cp_time->system + cp_time->intr), ULL2NUM(cp_time->nice), ULL2NUM(cp_time->idle)); rb_ary_push(cpus, cpu); } } free(cp_times); return cpus; } int system_int(const char * name) { int number; size_t number_size = sizeof(number); sysctlbyname(name, &number, &number_size, NULL, 0); return number; } #endif #ifndef VMSTAT_MEMORY #define VMSTAT_MEMORY VALUE vmstat_memory(VALUE self) { VALUE memory = rb_funcall(rb_path2class("Vmstat::Memory"), rb_intern("new"), 7, ULL2NUM(system_uint("vm.stats.vm.v_page_size")), ULL2NUM(system_uint("vm.stats.vm.v_active_count")), ULL2NUM(system_uint("vm.stats.vm.v_wire_count")), ULL2NUM(system_uint("vm.stats.vm.v_inactive_count")), ULL2NUM(system_uint("vm.stats.vm.v_free_count")), ULL2NUM(system_uint("vm.stats.vm.v_vnodepgsin")), ULL2NUM(system_uint("vm.stats.vm.v_vnodepgsout"))); return memory; } unsigned int system_uint(const char * name) { unsigned int number; size_t number_size = sizeof(number); if (sysctlbyname(name, &number, &number_size, NULL, 0) == -1) { perror("sysctlbyname"); return -1; } else { return number; } } #endif #endif vmstat-2.3.1/LICENSE.txt0000644000004100000410000000206013433303705014705 0ustar www-datawww-dataCopyright (c) 2012 Vincent Landgraf MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.