Code Monkey home page Code Monkey logo

ruby-vmstat's Introduction

Vmstat Build Status Code Climate

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.

require "vmstat"

Vmstat.snapshot # => #<Vmstat::Snapshot:0x007fe5f22df660
#	 @at=2012-10-09 21:48:57 +0200,
#	 @boot_time=2012-10-09 18:42:37 +0200,
#	 @cpus=
#	  [#<struct Vmstat::Cpu
#	    num=0,
#	    user=187167,
#	    system=144466,
#	    nice=0,
#	    idle=786622>,
#	   #<struct Vmstat::Cpu num=1, user=2819, system=1641, nice=0, idle=1113782>,
#	   #<struct Vmstat::Cpu num=2, user=158698, system=95186, nice=0, idle=864359>,
#	   #<struct Vmstat::Cpu num=3, user=2702, system=1505, nice=0, idle=1114035>,
#	   #<struct Vmstat::Cpu num=4, user=140231, system=78248, nice=0, idle=899764>,
#	   #<struct Vmstat::Cpu num=5, user=2468, system=1314, nice=0, idle=1114460>,
#	   #<struct Vmstat::Cpu num=6, user=120764, system=66284, nice=0, idle=931195>,
#	   #<struct Vmstat::Cpu num=7, user=2298, system=1207, nice=0, idle=1114737>],
#	 @disks=
#	  [#<struct Vmstat::Disk
#	    type=:hfs,
#	    origin="/dev/disk0s2",
#	    mount="/",
#	    block_size=4096,
#	    free_blocks=51470668,
#	    available_blocks=51406668,
#	    total_blocks=61069442>],
#	 @load_average=
#	  #<struct Vmstat::LoadAverage
#	   one_minute=1.74072265625,
#	   five_minutes=1.34326171875,
#	   fifteen_minutes=1.1845703125>,
#	 @memory=
#	  #<struct Vmstat::Memory
#	   pagesize=4096,
#	   wired=1037969,
#	   active=101977,
#	   inactive=484694,
#	   free=470582,
#	   pageins=102438,
#	   pageouts=0>,
#	 @network_interfaces=
#	  [#<struct Vmstat::NetworkInterface
#	    name=:lo0,
#	    in_bytes=6209398,
#	    in_errors=0,
#	    in_drops=0,
#	    out_bytes=6209398,
#	    out_errors=0,
#	    type=24>,
#	   #<struct Vmstat::NetworkInterface
#	    name=:gif0,
#	    in_bytes=0,
#	    in_errors=0,
#	    in_drops=0,
#	    out_bytes=0,
#	    out_errors=0,
#	    type=55>,
#	   #<struct Vmstat::NetworkInterface
#	    name=:stf0,
#	    in_bytes=0,
#	    in_errors=0,
#	    in_drops=0,
#	    out_bytes=0,
#	    out_errors=0,
#	    type=57>,
#	   #<struct Vmstat::NetworkInterface
#	    name=:en0,
#	    in_bytes=1321276010,
#	    in_errors=0,
#	    in_drops=0,
#	    out_bytes=410426678,
#	    out_errors=0,
#	    type=6>,
#	   #<struct Vmstat::NetworkInterface
#	    name=:p2p0,
#	    in_bytes=0,
#	    in_errors=0,
#	    in_drops=0,
#	    out_bytes=0,
#	    out_errors=0,
#	    type=6>],
#	 @task=
#	  #<struct Vmstat::Task
#	   suspend_count=0,
#	   virtual_size=2551554048,
#	   resident_size=19628032,
#	   user_time_ms=28,
#	   system_time_ms=83>>

Test

Development

docker-compose up

Single test build and run:

docker build -t ruby-vmstat .
docker run --rm -ti ruby-vmstat rake spec

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

ruby-vmstat's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ruby-vmstat's Issues

network interface type detection under Linux is unreliable

Hi, assuming the interface type from their name is misleading, since interfaces can have arbitrary names.

type = case columns[0]
  when /^eth/ then NetworkInterface::ETHERNET_TYPE
  when /^lo/  then NetworkInterface::LOOPBACK_TYPE
end

also, the test for the the loopback filtering assumes there is always a single loopback interface. For example, when vmstat was being built for the Debian mips architecture, the machine running the build had 5 loopback interfaces (for reasons that are not relevant here), and that made the tests fail:

Failures:

  1) Vmstat Vmstat#filter_devices should filter loopback devices
     Failure/Error: Vmstat.loopback_devices.size.should == 1

       expected: 1
            got: 5 (using ==)
     # ./spec/vmstat_spec.rb:25:in `block (3 levels) in <top (required)>'

maybe that test should look for at least, but not exactly, one loopback. or perhaps actually testing the type of the returned interfaces, instead of how many of them are returned.

Incorrect number of CPUs reported

Overview

We're running on 2 x Intel(R) Xeon(R) CPU E5-2697 v3 CPU - which has 14 physical cores, each core can run 2 threads, so each physical CPU has a total of 28 logical cores.

This server is running two Xeon CPUs, so 28 logical cores in each x 2 = 56 logical cores. (physical id : 0 and 1 (see cpuinfo))

Expected behavior

Vmstat should report 28 physical cores or 14 cores for each physical CPU.

Actual behavior

Vmstat reports 10 CPUs

Technical Information

Output of /proc/cpuinfo

https://gist.github.com/MrChrisW/1fe39621beea884b108fa960fc3abc15

Output of Vmstat.cpu

irb(main):002:0> Vmstat.cpu
=> [#<struct Vmstat::Cpu num=0, user=6670188, system=3350134, nice=285, idle=1249452713>, #<struct Vmstat::Cpu num=1, user=3626442, system=915950, nice=372, idle=1255321773>, #<struct Vmstat::Cpu num=2, user=1420901, system=657141, nice=130, idle=1258164129>, #<struct Vmstat::Cpu num=3, user=692545, system=200045, nice=98, idle=1259680553>, #<struct Vmstat::Cpu num=4, user=415148, system=147003, nice=121, idle=1260108171>, #<struct Vmstat::Cpu num=5, user=283719, system=110583, nice=86, idle=1260302370>, #<struct Vmstat::Cpu num=6, user=196015, system=111590, nice=0, idle=1260432131>, #<struct Vmstat::Cpu num=7, user=524402, system=247161, nice=2, idle=1260021490>, #<struct Vmstat::Cpu num=8, user=371258, system=228459, nice=0, idle=1260230712>, #<struct Vmstat::Cpu num=9, user=598101, system=589628, nice=1, idle=1259667514>]

Output of /proc/stat

cat /proc/stat
cpu  59127305 12729 42849824 71380462321 199223 542 58918 0 0
cpu0 6978688 288 3405523 1264958668 2219 0 3480 0 0
cpu1 3886423 377 934882 1270919727 303 0 2036 0 0
cpu2 1496235 137 667992 1273960076 190 176 1210 0 0
cpu3 731190 98 204323 1275523732 42 0 1346 0 0
cpu4 435178 121 150150 1275972516 121 1 1678 0 0
cpu5 301513 86 113130 1276169606 195 0 906 0 0
cpu6 208126 0 114542 1276305044 16 0 143 0 0
cpu7 567913 2 257799 1275856944 308 5 1757 0 0
cpu8 398289 0 239233 1276082982 65 5 1367 0 0
cpu9 626366 1 604481 1275515286 817 5 3860 0 0
cpu10 495814 0 416112 1275828424 717 7 1819 0 0
cpu11 217915 0 314168 1276221522 256 0 68 0 0
cpu12 2235985 1 2621027 1271801834 3270 0 179 0 0
cpu13 150285 0 214429 1276388908 11 0 63 0 0
cpu14 8501763 340 5782043 1261602615 71930 280 13296 0 0
cpu15 3362259 398 978417 1271747045 2226 0 1945 0 0
cpu16 1374822 7 423827 1274604915 780 0 1373 0 0
cpu17 667758 0 214868 1275706697 174 0 187 0 0
cpu18 446475 0 136906 1276035674 49 0 109 0 0
cpu19 331355 4 117125 1276186194 45 0 85 0 0
cpu20 264908 0 99448 1276246027 112 0 68 0 0
cpu21 212667 0 85190 1276317421 20 0 68 0 0
cpu22 194719 0 83380 1276329122 14 0 72 0 0
cpu23 169304 0 85365 1276348447 30 0 70 0 0
cpu24 167971 0 90988 1276345815 20 0 61 0 0
cpu25 154778 0 85061 1276368561 13 0 72 0 0
cpu26 146729 0 117481 1276375748 14 0 72 0 0
cpu27 180384 1 114786 1276335512 58 0 63 0 0
cpu28 3843792 6 3332176 1269043371 558 0 1426 0 0
cpu29 3262730 4214 4559280 1267540964 676 0 1710 0 0
cpu30 781155 790 581097 1274917017 78 0 210 0 0
cpu31 377574 165 227103 1275927809 42 0 76 0 0
cpu32 231888 23 147314 1276219432 51 0 69 0 0
cpu33 155365 62 97331 1276361739 11 0 73 0 0
cpu34 123666 12 76141 1276402777 32 0 52 0 0
cpu35 170810 1 91245 1276306647 79 0 74 0 0
cpu36 169446 0 92013 1276315246 70 0 68 0 0
cpu37 564333 11 391544 1275555531 31079 15 3965 0 0
cpu38 636912 2 279216 1275594235 30757 16 3431 0 0
cpu39 561587 0 242071 1275805975 8053 2 1831 0 0
cpu40 3051022 5 3468539 1270073784 37344 21 4553 0 0
cpu41 88837 0 204266 1276443744 5 0 46 0 0
cpu42 4442699 12 4274383 1267501536 3247 0 1170 0 0
cpu43 3339198 4467 4525486 1267503503 1474 0 1758 0 0
cpu44 765228 775 592164 1275037372 930 0 229 0 0
cpu45 365206 185 221975 1275989262 274 0 81 0 0
cpu46 239064 37 146271 1276228455 131 0 72 0 0
cpu47 186072 77 84199 1276338567 48 0 62 0 0
cpu48 142728 0 71522 1276377667 26 0 57 0 0
cpu49 128556 5 71717 1276400425 123 0 67 0 0
cpu50 105891 0 65869 1276423088 7 0 61 0 0
cpu51 98325 0 68172 1276408729 20 0 58 0 0
cpu52 101847 0 69747 1276417701 18 0 56 0 0
cpu53 88266 0 68425 1276432986 26 0 81 0 0
cpu54 97748 0 62475 1276428563 6 0 52 0 0
cpu55 101521 0 65377 1276411107 18 0 48 0 0
intr 7595980219 360 3 0 131676 2 0 0 0 1 0 0 0 4 0 0 0 0 0 62 17105215 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 42570 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 23196695 15869819 41057038 5002702 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 13010087 2621256 3902926 3571436 2862453 13714285 5412924 4044442 9085002 6888793 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 12649065559
btime 1466603499
processes 163918052
procs_running 3
procs_blocked 0
softirq 13148068361 0 75205020 2558757 115292597 80785386 0 209636 1975545698 8920865 2299615810

add changelog

Would you consider adding a changelog to the project so it's clear what's changed in each release.

Vmstat.snapshot causes undefined method `network_interfaces' on macOS

I'm trying to run this lib on my mac running 10.14 Mojave, and Ruby 2.30

When I try to run this script:

require "vmstat"
test = Vmstat.snapshot

I get this result:

/Library/Ruby/Gems/2.3.0/gems/vmstat-2.3.0/lib/vmstat/snapshot.rb:29:in `initialize': undefined method `network_interfaces' for Vmstat:Module (NoMethodError)
	from /Library/Ruby/Gems/2.3.0/gems/vmstat-2.3.0/lib/vmstat.rb:83:in `new'
	from /Library/Ruby/Gems/2.3.0/gems/vmstat-2.3.0/lib/vmstat.rb:83:in `snapshot'
	from /Users/tomershemesh/RubymineProjects/vmstat_test/main.rb:4:in `<main>'

why the @memory.free it not equal the free command result?

Hi, i run free on ubuntu, it's report the free memory is 291M. but vmstat report it 72.046M, is it problem?

free -m
             total       used       free     shared    buffers     cached
Mem:          3953       3661        291          0        435        874
-/+ buffers/cache:       2351       1602
Swap:         4093        505       3588
2.0.0-p353 :001 > require 'vmstat'
 => true 
2.0.0-p353 :002 > Vmstat.snapshot
 => #<Vmstat::Snapshot:0x00000002416f98 @at=2014-04-25 10:54:43 +0800, @boot_time=2014-03-21 18:20:31 +0800, @cpus=[#<struct Vmstat::Cpu num=0, user=1505724, system=428605, nice=18475, idle=296399959>, #<struct Vmstat::Cpu num=1, user=1408257, system=367915, nice=11805, idle=296995241>, #<struct Vmstat::Cpu num=2, user=1241444, system=317692, nice=14167, idle=297237353>, #<struct Vmstat::Cpu num=3, user=1349585, system=342413, nice=10496, idle=297150395>], @disks=[#<struct Vmstat::LinuxDisk type=:ext4, origin="/", mount="/", block_size=4096, free_blocks=245113613, available_blocks=231740186, total_blocks=263158381>], @load_average=#<struct Vmstat::LoadAverage one_minute=0.02, five_minutes=0.05, fifteen_minutes=0.05>, @memory=#<struct Vmstat::Memory pagesize=4096, wired=221782, active=375840, inactive=342435, free=72046, pageins=58366033, pageouts=167523232>, @network_interfaces=[#<struct Vmstat::NetworkInterface name=:eth0, in_bytes=18760131266, in_errors=0, in_drops=988, out_bytes=11677543487, out_errors=0, type=6>, #<struct Vmstat::NetworkInterface name=:lo, in_bytes=8794265684, in_errors=0, in_drops=0, out_bytes=8794265684, out_errors=0, type=24>], @task=#<struct Vmstat::Task virtual_size=12986, resident_size=3403, user_time_ms=18000, system_time_ms=4000>> 
2.0.0-p353 :003 > Vmstat.memory.free
 => 72046

Snapshot.new crashes on OSX

Vmstat::Snapshot.new invocation crashes on OSX Mavericks:

/Library/Ruby/Gems/2.0.0/gems/vmstat-2.1.0/lib/vmstat/snapshot.rb:24:in `initialize': undefined method `boot_time' for Vmstat:Module (NoMethodError)

Support Solaris / SmartOs

Hi,

I'm having problems installing vmstat on SmartOs. This fails during gitlab upgrade.

[root@gitlab /home/git/gitlab]# uname -a
SunOS gitlab 5.11 joyent_20151015T063628Z i86pc i386 i86pc Solaris
[root@gitlab /home/git/gitlab]# sudo -u git -H gem install vmstat -v 2.1.1
Building native extensions.  This could take a while...
ERROR:  Error installing vmstat:
        ERROR: Failed to build gem native extension.

    /opt/local/bin/ruby215 extconf.rb
checking for unistd.h... yes
checking for getpagesize()... yes
checking for stdlib.h... yes
checking for getloadavg()... yes
checking for mach/mach.h... no
checking for mach/mach_host.h... no
checking for host_processor_info()... no
checking for mach_host_self()... no
checking for mach_task_self()... no
checking for vm_deallocate()... no
checking for mach_error_string()... no
checking for task_info()... no
checking for KERN_SUCCESS in mach/mach.h,mach/mach_host.h... no
checking for TASK_BASIC_INFO in mach/mach.h,mach/mach_host.h... no
checking for HOST_VM_INFO in mach/mach.h,mach/mach_host.h... no
checking for CPU_STATE_MAX in mach/mach.h,mach/mach_host.h... no
checking for PROCESSOR_CPU_LOAD_INFO in mach/mach.h,mach/mach_host.h... no
checking for CPU_STATE_USER in mach/mach.h,mach/mach_host.h... no
checking for CPU_STATE_SYSTEM in mach/mach.h,mach/mach_host.h... no
checking for CPU_STATE_NICE in mach/mach.h,mach/mach_host.h... no
checking for CPU_STATE_IDLE in mach/mach.h,mach/mach_host.h... no
checking for sys/param.h... yes
checking for sys/mount.h... yes
checking for sys/statfs.h... yes
checking for statfs()... yes
checking for unistd.h... yes
checking for sys/sysctl.h... no
checking for sys/types.h... yes
checking for sys/socket.h... yes
checking for net/if.h... yes
checking for net/if_mib.h... no
checking for net/if_types.h... yes
checking for getloadavg()... yes
checking for sysctl()... no
checking for struct ifmibdata in unistd.h,sys/sysctl.h,sys/types.h,sys/socket.h,net/if.h,net/if_mib.h,net/if_types.h... no
checking for CTL_NET in unistd.h,sys/sysctl.h,sys/types.h,sys/socket.h,net/if.h,net/if_mib.h,net/if_types.h... no
checking for PF_LINK in unistd.h,sys/sysctl.h,sys/types.h,sys/socket.h,net/if.h,net/if_mib.h,net/if_types.h... no
checking for NETLINK_GENERIC in unistd.h,sys/sysctl.h,sys/types.h,sys/socket.h,net/if.h,net/if_mib.h,net/if_types.h... no
checking for IFMIB_IFDATA in unistd.h,sys/sysctl.h,sys/types.h,sys/socket.h,net/if.h,net/if_mib.h,net/if_types.h... no
checking for IFDATA_GENERAL in unistd.h,sys/sysctl.h,sys/types.h,sys/socket.h,net/if.h,net/if_mib.h,net/if_types.h... no
checking for CTL_KERN in unistd.h,sys/sysctl.h,sys/types.h,sys/socket.h,net/if.h,net/if_mib.h,net/if_types.h... no
checking for KERN_BOOTTIME in unistd.h,sys/sysctl.h,sys/types.h,sys/socket.h,net/if.h,net/if_mib.h,net/if_types.h... no
creating extconf.h
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling vmstat.c
In file included from vmstat.c:3:0:
./hw/statfs.h: In function 'vmstat_disk':
./hw/statfs.h:17:7: error: too few arguments to function 'statfs'
   if (statfs(StringValueCStr(path), &stat) != -1) {
       ^
In file included from ./hw/statfs.h:8:0,
                 from vmstat.c:3:
/usr/include/sys/statfs.h:75:5: note: declared here
 int statfs(const char *, struct statfs *, int, int);
     ^
In file included from /opt/local/include/ruby-2.1.5/ruby.h:33:0,
                 from ./vmstat.h:1,
                 from vmstat.c:1:
./hw/statfs.h:20:45: error: 'struct statfs' has no member named 'f_type'
            rb_intern("new"), 6, ULL2NUM(stat.f_type),
                                             ^
/opt/local/include/ruby-2.1.5/ruby/ruby.h:245:32: note: in definition of macro 'ULL2NUM'
 #define ULL2NUM(v) rb_ull2inum(v)
                                ^
./hw/statfs.h:24:45: error: 'struct statfs' has no member named 'f_bavail'
                                 ULL2NUM(stat.f_bavail),
                                             ^
/opt/local/include/ruby-2.1.5/ruby/ruby.h:245:32: note: in definition of macro 'ULL2NUM'
 #define ULL2NUM(v) rb_ull2inum(v)
                                ^
Makefile:224: recipe for target 'vmstat.o' failed
make: *** [vmstat.o] Error 1

make failed, exit code 2

CPU count off by 2

Hello,

I've noticed an inconsistency between /etc/cpuinfo and Vmstat.snapshot.cpus.

/etc/cpuinfo reports 12 cores, with the last one being:

processor       : 11
vendor_id       : GenuineIntel
cpu family      : 6
model           : 45
model name      : Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz
stepping        : 7
microcode       : 0x705
cpu MHz         : 1200.000
cache size      : 12288 KB
physical id     : 0
siblings        : 12
core id         : 5
cpu cores       : 6
apicid          : 11
initial apicid  : 11
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm ida arat epb xsaveopt pln pts dtherm tpr_shadow vnmi flexpriority ept vpid
bogomips        : 6592.07
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:

Vmstat.snapshot.cpus reports 10:

    [9] {
           :num => 9,
          :user => 54308260,
        :system => 22791214,
          :nice => 368194,
          :idle => 1597384752
    }

Any idea?

Cheers

build failure on Ubuntu / ppc64el

Hi, seems that this package fails to detect the Vmstat:Memory on ppc64el
https://launchpadlibrarian.net/284514946/buildlog_ubuntu-yakkety-ppc64el.ruby-vmstat_2.2.0-2_BUILDING.txt.gz


Vmstat::Cpu
  Vmstat#cpu
    should return an array of ethernet information
    first cpu
      should return a vmstat cpu object
      methods
        should respond to #user
        should respond to #idle
        should respond to #system
        should respond to #nice
      content
        nice
          should be a kind of Numeric
        idle
          should be a kind of Numeric
        system
          should be a kind of Numeric
        user
          should be a kind of Numeric

Vmstat::Task
  Vmstat#task
    should be a vmstat task object
    content
      resident_size
        should be a kind of Numeric
      user_time_ms
        should be a kind of Numeric
      virtual_size
        should be a kind of Numeric
      system_time_ms
        should be a kind of Numeric
    methods
      should respond to #resident_size
      should respond to #system_time_ms
      should respond to #user_time_ms
      should respond to #virtual_size

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Vmstat Vmstat#filter_devices should filter ethernet devices
     # Temporarily skipped with xit
     # ./spec/vmstat_spec.rb:19

Failures:

  1) Vmstat::Solaris#memory should == #<struct Vmstat::Memory pagesize=4096, wired=409145, active=9018, inactive=0, free=61103, pageins=0, pageouts=0>
     Failure/Error: should == Vmstat::Memory.new(4096, 409145, 9018, 0, 61103, 0, 0)

       expected: #<struct Vmstat::Memory pagesize=4096, wired=409145, active=9018, inactive=0, free=61103, pageins=0, pageouts=0>
            got: #<struct Vmstat::Memory pagesize=65536, wired=409145, active=9018, inactive=0, free=61103, pageins=0, pageouts=0> (using ==)
       Diff:
       @@ -1,2 +1,2 @@
       -"#<struct Vmstat::Memory pagesize=4096, wired=409145, active=9018, inactive=0, free=61103, pageins=0, pageouts=0>"
       +"#<struct Vmstat::Memory pagesize=65536, wired=409145, active=9018, inactive=0, free=61103, pageins=0, pageouts=0>"
     # ./spec/vmstat/solaris_spec.rb:253:in `block (3 levels) in <top (required)>'

  2) Vmstat::ProcFS#task should == #<struct Vmstat::Task virtual_size=4807, resident_size=515, user_time_ms=2000, system_time_ms=0>
     Failure/Error: it { should == Vmstat::Task.new(4807, 515, 2000, 0) }

       expected: #<struct Vmstat::Task virtual_size=4807, resident_size=515, user_time_ms=2000, system_time_ms=0>
            got: #<struct Vmstat::Task virtual_size=300, resident_size=515, user_time_ms=2000, system_time_ms=0> (using ==)
       Diff:
       @@ -1,2 +1,2 @@
       -"#<struct Vmstat::Task virtual_size=4807, resident_size=515, user_time_ms=2000, system_time_ms=0>"
       +"#<struct Vmstat::Task virtual_size=300, resident_size=515, user_time_ms=2000, system_time_ms=0>"
     # ./spec/vmstat/procfs_spec.rb:70:in `block (3 levels) in <top (required)>'

  3) Vmstat::ProcFS#memory should have the right total
     Failure/Error:
       (subject.wired_bytes + subject.active_bytes + 
        subject.inactive_bytes + subject.free_bytes).should == 507344 * 1024

       expected: 519520256
            got: 519503872 (using ==)
     # ./spec/vmstat/procfs_spec.rb:39:in `block (3 levels) in <top (required)>'

  4) Vmstat::ProcFS#memory should == #<struct Vmstat::Memory pagesize=4096, wired=4906, active=6508, inactive=8405, free=107017, pageins=64599, pageouts=1104>
     Failure/Error: should == Vmstat::Memory.new(4096, 4906, 6508, 8405, 107017, 64599, 1104)

       expected: #<struct Vmstat::Memory pagesize=4096, wired=4906, active=6508, inactive=8405, free=107017, pageins=64599, pageouts=1104>
            got: #<struct Vmstat::Memory pagesize=65536, wired=308, active=406, inactive=525, free=6688, pageins=64599, pageouts=1104> (using ==)
       Diff:
       @@ -1,2 +1,2 @@
       -"#<struct Vmstat::Memory pagesize=4096, wired=4906, active=6508, inactive=8405, free=107017, pageins=64599, pageouts=1104>"
       +"#<struct Vmstat::Memory pagesize=65536, wired=308, active=406, inactive=525, free=6688, pageins=64599, pageouts=1104>"
     # ./spec/vmstat/procfs_spec.rb:34:in `block (3 levels) in <top (required)>'

Deprecation Warnings:

RSpec::Core::Configuration#treat_symbols_as_metadata_keys_with_true_values= is deprecated, it is now set to true as default and setting it to false has no effect.

Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /<<PKGBUILDDIR>>/spec/vmstat_spec.rb:8:in `block (3 levels) in <top (required)>'.


If you need more of the backtrace for any of these deprecations to
identify where to make the necessary changes, you can configure
`config.raise_errors_for_deprecations!`, and it will turn the
deprecation warnings into errors, giving you the full backtrace.

2 deprecation warnings total

Finished in 0.12744 seconds (files took 0.18087 seconds to load)
145 examples, 4 failures, 1 pending

Failed examples:

rspec ./spec/vmstat/solaris_spec.rb:252 # Vmstat::Solaris#memory should == #<struct Vmstat::Memory pagesize=4096, wired=409145, active=9018, inactive=0, free=61103, pageins=0, pageouts=0>
rspec ./spec/vmstat/procfs_spec.rb:70 # Vmstat::ProcFS#task should == #<struct Vmstat::Task virtual_size=4807, resident_size=515, user_time_ms=2000, system_time_ms=0>
rspec ./spec/vmstat/procfs_spec.rb:37 # Vmstat::ProcFS#memory should have the right total
rspec ./spec/vmstat/procfs_spec.rb:33 # Vmstat::ProcFS#memory should == #<struct Vmstat::Memory pagesize=4096, wired=4906, active=6508, inactive=8405, free=107017, pageins=64599, pageouts=1104>

Randomized with seed 17733

/usr/bin/ruby2.3 /usr/bin/rspec --pattern ./spec/\*\*/\*_spec.rb --format documentation failed
ERROR: Test "ruby2.3" failed. Exiting.
dh_auto_install: dh_ruby --install /<<PKGBUILDDIR>>/debian/ruby-vmstat returned exit code 1
debian/rules:6: recipe for target 'binary-arch' failed
make: *** [binary-arch] Error 1
dpkg-buildpackage: error: fakeroot debian/rules binary-arch gave error exit status 2

do you have any clue?

Calculate used memory percentage

Hi,
I'm going crazy trying to calculate used memory percentage. Vmstat gives me the following infos:

 pagesize=4096,
 wired=206705,
 active=1840031,
 inactive=1979580,
 free=80112,
 pageins=7268181,
 pageouts=122914456

But top gives me 16425712 total, 320760 free, 2994884 used. used / total * 100 gives 18% used.

Any suggestion?

Thank you,
Gjergji

two tests failing on debian sid

I'm packaging vmstat for debian and found two test failing

**Failures:

  1) Vmstat::Disk Vmstat#disk content type should be a kind of Symbol
     Failure/Error: its(:type) { should be_a(Symbol) }
       expected nil to be a kind of Symbol
     # ./spec/vmstat/disk_spec.rb:43:in `block (4 levels) in <top (required)>'

  2) Vmstat performance it should behave like a not memory leaking method should not grow the memory in method boot_time more than 26% 
     Failure/Error: mem_after.should < (mem_before * (1 + percent / 100.0))

       expected: < 5751.9
            got:   6636
     Shared Example Group: "a not memory leaking method" called from ./spec/vmstat_spec.rb:43
     # ./spec/vmstat_spec.rb:35:in `block (4 levels) in <top (required)>'

**
$ ruby -v
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
$ rspec -v
3.4.3

Vmstat.snapshot.memory different from free

Hi

My Vmstat.snapshot.memory and free is showing huge different. Could you please help understand the difference between them ? How do I find total memory with ruby-vmstat?

image

image

Adding the output of vmstat -s

image

Thanks

network interface detection test fails on s390x linux chroot

/sbin/ifconfig output on a linux s390x host chroot

uname -a
Linux zelenka 3.16.0-4-s390x #1 SMP Debian 3.16.36-1+deb8u1 (2016-09-03) s390x GNU/Linux
ext0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 80.245.147.40  netmask 255.255.255.255  broadcast 80.245.147.40
        inet6 fe80::be:afff:fe00:1b  prefixlen 64  scopeid 0x20<link>
        ether 02:be:af:00:00:1b  txqueuelen 1000  (Ethernet)
        RX packets 936904  bytes 1078522312 (1.0 GiB)   
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 519691  bytes 219196282 (209.0 MiB)  
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

and vmstat cannot detect this interface and test fails

Full build log https://buildd.debian.org/status/fetch.php?pkg=ruby-vmstat&arch=s390x&ver=2.2.0-1&stamp=1472145491

MemAvailable value in /proc/meminfo

In Linux kernel release 3.14 a new metric has been introduced in “/proc/meminfo” called "MemAvailable".

https://www.kernel.org/doc/Documentation/filesystems/proc.txt

MemAvailable: An estimate of how much memory is available for starting new
              applications, without swapping. Calculated from MemFree,
              SReclaimable, the size of the file LRU lists, and the low
              watermarks in each zone.
              The estimate takes into account that the system needs some
              page cache to function well, and that not all reclaimable
              slab will be reclaimable, due to items being in use. The
              impact of those factors will vary from system to system.

Further details in the original commit:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773

MemAvailable details the amount of memory that is available for a new workload without the need for swapping. In the past it was possible to calculate this figure by adding the "MemFree" and "Cached" values together, however this is is pretty much guaranteed to be wrong in systems running Kernels since 3.14.

Could this be added? The Slab allocation in the Linux Kernel tends to be higher giving inaccurate values in MemFree.

How to use this to get overall CPU usage?

Hey There,

I am looking to use this to aid in implementing throttling a rack based application based on CPU usage.

I see how to get the CPU counters but don't know how to use them to get an idle percentage.

1.9.2p320 :005 > Vmstat.cpu.first
=> #

I am guessing there is some sort of subtraction that I do but can you offer some guidance?

Thanks.

Test on 2.3.1

I don't know if 2.3.1 with OS X works on Travis, but since we'd like to upgrade to Ruby 2.3 at GitLab it'd be nice to know vmstat supports 2.3 :)

Alternatively, use a matrix and only test it on Linux?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.