vidibus-sysinfo 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2011 Andre Pankratz
1
+ MIT License
2
+
3
+ Copyright (c) 2011-2013 Andre Pankratz
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
@@ -1,67 +1,78 @@
1
- = Vidibus::Sysinfo
1
+ # Vidibus::Sysinfo
2
2
 
3
3
  Allows reading various system information.
4
4
 
5
+ This gem is part of the open source service-oriented {video framework}[http://vidibus.org] Vidibus.
5
6
 
6
- == Installation
7
+
8
+ ## Installation
7
9
 
8
10
  Add the dependency to the Gemfile of your application:
9
11
 
12
+ ```ruby
10
13
  gem "vidibus-sysinfo"
14
+ ```
11
15
 
12
16
  Then call bundle install on your console.
13
17
 
14
18
 
15
- == System requirements
19
+ ## System requirements
16
20
 
17
- This gem uses various tools to obtain system data. On Debian Lenny, installing
18
- those tools should be simple:
21
+ This gem uses various tools to obtain system data. Installing those tools should be simple, at least on Debian and Ubuntu:
19
22
 
20
- apt-get install sysstat vnstat
23
+ ```shell
24
+ apt-get install sysstat vnstat lscpu
21
25
  vnstat -u -i eth0
26
+ /etc/init.d/vnstat start
27
+ ```
22
28
 
29
+ ## Usage
23
30
 
24
- == Usage
25
-
26
- === CPU cores
31
+ ### CPU cores
27
32
 
28
33
  To get the number of CPU cores, call
29
34
 
35
+ ```ruby
30
36
  Vidibus::Sysinfo.core
31
- # => 8
32
-
37
+ # => 4
38
+ ```
33
39
 
34
- === CPU utilization
40
+ ### CPU utilization
35
41
 
36
42
  To get CPU utilization in percent, call
37
43
 
44
+ ```ruby
38
45
  Vidibus::Sysinfo.cpu
39
46
  # => 18.4 # percent
47
+ ```
40
48
 
41
-
42
- === System load
49
+ ### System load
43
50
 
44
51
  The system load value is divided by the number of CPU cores.
45
52
  To get the system load, call
46
53
 
54
+ ```ruby
47
55
  Vidibus::Sysinfo.load
48
56
  # => 0.39
57
+ ```
49
58
 
50
-
51
- === Monthly traffic
59
+ ### Monthly traffic
52
60
 
53
61
  To get the total traffic of this month in gigabytes, call
54
62
 
63
+ ```ruby
55
64
  Vidibus::Sysinfo.traffic
56
65
  # => 7992.15 # gigabytes
66
+ ```
57
67
 
58
-
59
- === Currently used bandwidth
68
+ ### Currently used bandwidth
60
69
 
61
70
  To get the currently used bandwidth in MBit/s, call
62
71
 
72
+ ```ruby
63
73
  Vidibus::Sysinfo.bandwidth
64
74
  # => 38.71 # MBit/s
75
+ ```
65
76
 
66
77
  Bandwidth detection is performed by analyzing the output of /proc/net/dev.
67
78
  To get the amount of traffic in a certain timespan, the analyzer gets
@@ -71,36 +82,41 @@ By default, bandwidth detection only waits one second, thus the results
71
82
  will be quite volatile. To get a more accurate result, you can provide
72
83
  an optional argument:
73
84
 
85
+ ```ruby
74
86
  Vidibus::Sysinfo.bandwidth(10)
75
87
  # => 33.28 # MBit/s
88
+ ```
76
89
 
77
-
78
- === Consumed storage
90
+ ### Consumed storage
79
91
 
80
92
  To get the consumed storage of the main device in gigabytes, call
81
93
 
94
+ ```ruby
82
95
  Vidibus::Sysinfo.storage
83
96
  # => 647.89 # gigabytes
97
+ ```
84
98
 
85
-
86
- === Used memory
99
+ ### Used memory
87
100
 
88
101
  To get the currently used memory in megabytes, call
89
102
 
103
+ ```ruby
90
104
  Vidibus::Sysinfo.memory
91
105
  # => 3281.38 # megabytes
106
+ ```
92
107
 
93
108
  This will ignore memory used for system caching.
94
109
 
95
110
 
96
- === Used swap
111
+ ### Used swap
97
112
 
98
113
  To get the currently used swap in megabytes, call
99
114
 
115
+ ```ruby
100
116
  Vidibus::Sysinfo.swap
101
117
  # => 0.0 # megabytes
118
+ ```
102
119
 
120
+ ## Copyright
103
121
 
104
- == Copyright
105
-
106
- Copyright (c) 2011 Andre Pankratz. See LICENSE for details.
122
+ Copyright (c) 2011-2013 Andre Pankratz. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,20 +1,16 @@
1
- require "bundler"
2
- require "rake/rdoctask"
3
- require "rspec"
4
- require "rspec/core/rake_task"
5
- Bundler::GemHelper.install_tasks
1
+ $:.unshift File.expand_path('../lib/', __FILE__)
6
2
 
7
- Rspec::Core::RakeTask.new(:rcov) do |t|
8
- t.pattern = "spec/**/*_spec.rb"
9
- t.rcov = true
10
- t.rcov_opts = ["--exclude", "^spec,/gems/"]
11
- end
3
+ require 'bundler'
4
+ require 'rdoc/task'
5
+ require 'rspec'
6
+ require 'rspec/core/rake_task'
7
+
8
+ Bundler::GemHelper.install_tasks
12
9
 
13
10
  Rake::RDocTask.new do |rdoc|
14
- require File.expand_path("../lib/vidibus/sysinfo/version.rb", __FILE__)
15
- rdoc.rdoc_dir = "rdoc"
16
- rdoc.title = "vidibus-sysinfo #{Vidibus::Sysinfo::VERSION}"
17
- rdoc.rdoc_files.include("README*")
18
- rdoc.rdoc_files.include("lib/**/*.rb")
19
- rdoc.options << "--charset=utf-8"
11
+ rdoc.rdoc_dir = 'rdoc'
12
+ rdoc.title = 'Vidibus::Sysinfo'
13
+ rdoc.rdoc_files.include('README*')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ rdoc.options << '--charset=utf-8'
20
16
  end
@@ -1,2 +1 @@
1
- $:.unshift(File.join(File.dirname(__FILE__), "vidibus"))
2
- require "sysinfo"
1
+ require 'vidibus/sysinfo'
@@ -1,13 +1,13 @@
1
- require "open3"
2
- require "sysinfo/base"
3
- require "sysinfo/core"
4
- require "sysinfo/cpu"
5
- require "sysinfo/load"
6
- require "sysinfo/traffic"
7
- require "sysinfo/bandwidth"
8
- require "sysinfo/storage"
9
- require "sysinfo/memory"
10
- require "sysinfo/swap"
1
+ require 'open3'
2
+ require 'vidibus/sysinfo/base'
3
+ require 'vidibus/sysinfo/core'
4
+ require 'vidibus/sysinfo/cpu'
5
+ require 'vidibus/sysinfo/load'
6
+ require 'vidibus/sysinfo/traffic'
7
+ require 'vidibus/sysinfo/bandwidth'
8
+ require 'vidibus/sysinfo/storage'
9
+ require 'vidibus/sysinfo/memory'
10
+ require 'vidibus/sysinfo/swap'
11
11
 
12
12
  module Vidibus
13
13
  module Sysinfo
@@ -52,13 +52,14 @@ module Vidibus
52
52
  end
53
53
 
54
54
  # Converts given amount from unit to megabytes.
55
+ # Treats GB and GiB identically because in our context GB == GiB.
55
56
  def megabytes(value, unit = "B")
56
57
  value = value.to_f
57
58
  case unit
58
- when "B" : value /= 1048576 # bytes
59
- when "K", "KB": value /= 1024 # kiloytes
60
- when "G", "GB": value *= 1024 # gigabytes
61
- when "T", "TB": value *= 1048576 # terabytes
59
+ when 'B' then value /= 1048576 # bytes
60
+ when 'K', 'KB', 'KiB' then value /= 1024 # kiloytes
61
+ when 'G', 'GB', 'GiB' then value *= 1024 # gigabytes
62
+ when 'T', 'TB', 'TiB' then value *= 1048576 # terabytes
62
63
  end
63
64
  round(value)
64
65
  end
@@ -3,25 +3,27 @@ module Vidibus
3
3
 
4
4
  # Returns number of cpu cores on this system.
5
5
  #
6
- # Analyzes /proc/cpuinfo
6
+ # Analyzes lscpu
7
7
  #
8
8
  module Core
9
9
  extend Base
10
10
 
11
11
  class << self
12
12
  def command
13
- "cat /proc/cpuinfo | grep processor | wc -l"
13
+ 'lscpu'
14
14
  end
15
15
 
16
16
  def parse(output)
17
- if output.match(/\d+/)
18
- output.to_i
17
+ cores = output[/Core\(s\) per socket:\s+(\d+)/, 1]
18
+ sockets = output[/Socket\(s\):\s+(\d+)/, 1]
19
+ if cores && sockets
20
+ cores.to_i * sockets.to_i
19
21
  end
20
22
  end
21
23
 
22
24
  def explain(error)
23
- if error.match("No such file or directory")
24
- return "This system does not provide /proc/cpuinfo"
25
+ if error.match('lscpu: command not found')
26
+ return 'lscup is not installed. On Debian you can install it with "apt-get install lscup"'
25
27
  end
26
28
  end
27
29
  end
@@ -18,7 +18,7 @@ module Vidibus
18
18
  end
19
19
 
20
20
  def parse(output)
21
- if output.match(/([\d\.]+)\s+[^\s]+$/)
21
+ if output.match(/([\d\.]+)$/)
22
22
  round(100.0 - $1.to_f)
23
23
  end
24
24
  end
@@ -19,7 +19,7 @@ module Vidibus
19
19
 
20
20
  def parse(output)
21
21
  month = /(\s*\w{3} \'\d{2})/
22
- traffic = /\s*(\d+(?:\.\d+)?) (kB|MB|GB|TB)\s*/
22
+ traffic = /\s*(\d+(?:\.\d+)?) (ki?B|Mi?B|Gi?B|Ti?B)\s*/
23
23
  last_month = output.split(/\r?\n/)[-3]
24
24
  if last_month and last_month.match(/#{month}#{traffic}\|#{traffic}\|#{traffic}+/m)
25
25
  amount = $6.to_f
@@ -1,5 +1,5 @@
1
1
  module Vidibus
2
2
  module Sysinfo
3
- VERSION = "0.0.2"
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,116 +1,118 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vidibus-sysinfo
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Andre Pankratz
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-11 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-09-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: bundler
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 1
32
- - 0
33
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 1.0.0
35
22
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
38
31
  name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
39
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
49
54
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rspec
53
55
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
55
65
  none: false
56
- requirements:
66
+ requirements:
57
67
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 62196427
60
- segments:
61
- - 2
62
- - 0
63
- - 0
64
- - beta
65
- - 20
66
- version: 2.0.0.beta.20
68
+ - !ruby/object:Gem::Version
69
+ version: '2'
67
70
  type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: rr
71
71
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rr
80
+ requirement: !ruby/object:Gem::Requirement
73
81
  none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
- version: "0"
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
81
86
  type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: relevance-rcov
85
87
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
87
89
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
95
102
  type: :development
96
- version_requirements: *id005
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
97
110
  description: Gets CPU usage, current load, consumed memory and some other figures.
98
111
  email: andre@vidibus.com
99
112
  executables: []
100
-
101
113
  extensions: []
102
-
103
114
  extra_rdoc_files: []
104
-
105
- files:
106
- - .gitignore
107
- - Gemfile
108
- - Gemfile.lock
109
- - LICENSE
110
- - README.rdoc
111
- - Rakefile
112
- - lib/vidibus-sysinfo.rb
113
- - lib/vidibus/sysinfo.rb
115
+ files:
114
116
  - lib/vidibus/sysinfo/bandwidth.rb
115
117
  - lib/vidibus/sysinfo/base.rb
116
118
  - lib/vidibus/sysinfo/core.rb
@@ -121,52 +123,37 @@ files:
121
123
  - lib/vidibus/sysinfo/swap.rb
122
124
  - lib/vidibus/sysinfo/traffic.rb
123
125
  - lib/vidibus/sysinfo/version.rb
124
- - spec/spec_helper.rb
125
- - spec/vidibus/sysinfo/bandwidth_spec.rb
126
- - spec/vidibus/sysinfo/core_spec.rb
127
- - spec/vidibus/sysinfo/cpu_spec.rb
128
- - spec/vidibus/sysinfo/load_spec.rb
129
- - spec/vidibus/sysinfo/memory_spec.rb
130
- - spec/vidibus/sysinfo/storage_spec.rb
131
- - spec/vidibus/sysinfo/swap_spec.rb
132
- - spec/vidibus/sysinfo/traffic_spec.rb
133
- - spec/vidibus/sysinfo_spec.rb
134
- - vidibus-sysinfo.gemspec
135
- has_rdoc: true
126
+ - lib/vidibus/sysinfo.rb
127
+ - lib/vidibus-sysinfo.rb
128
+ - LICENSE
129
+ - README.md
130
+ - Rakefile
136
131
  homepage: https://github.com/vidibus/vidibus-sysinfo
137
- licenses: []
138
-
132
+ licenses:
133
+ - MIT
139
134
  post_install_message:
140
135
  rdoc_options: []
141
-
142
- require_paths:
136
+ require_paths:
143
137
  - lib
144
- required_ruby_version: !ruby/object:Gem::Requirement
138
+ required_ruby_version: !ruby/object:Gem::Requirement
145
139
  none: false
146
- requirements:
147
- - - ">="
148
- - !ruby/object:Gem::Version
149
- hash: 3
150
- segments:
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ segments:
151
145
  - 0
152
- version: "0"
153
- required_rubygems_version: !ruby/object:Gem::Requirement
146
+ hash: -4146470171620647197
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
148
  none: false
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- hash: 23
159
- segments:
160
- - 1
161
- - 3
162
- - 6
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
163
152
  version: 1.3.6
164
153
  requirements: []
165
-
166
154
  rubyforge_project: vidibus-sysinfo
167
- rubygems_version: 1.3.7
155
+ rubygems_version: 1.8.24
168
156
  signing_key:
169
157
  specification_version: 3
170
158
  summary: Provides tools for obtaining information about the system
171
159
  test_files: []
172
-
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- pkg/*
2
- *.gem
3
- .bundle
4
- rdoc
5
- coverage
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source :gemcutter
2
-
3
- # Specify your gem's dependencies in vidibus-sysinfo.gemspec
4
- gemspec
data/Gemfile.lock DELETED
@@ -1,33 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- vidibus-sysinfo (0.0.2)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- diff-lcs (1.1.2)
10
- rake (0.8.7)
11
- relevance-rcov (0.9.2.1)
12
- rr (1.0.2)
13
- rspec (2.0.1)
14
- rspec-core (~> 2.0.1)
15
- rspec-expectations (~> 2.0.1)
16
- rspec-mocks (~> 2.0.1)
17
- rspec-core (2.0.1)
18
- rspec-expectations (2.0.1)
19
- diff-lcs (>= 1.1.2)
20
- rspec-mocks (2.0.1)
21
- rspec-core (~> 2.0.1)
22
- rspec-expectations (~> 2.0.1)
23
-
24
- PLATFORMS
25
- ruby
26
-
27
- DEPENDENCIES
28
- bundler (>= 1.0.0)
29
- rake
30
- relevance-rcov
31
- rr
32
- rspec (~> 2.0.0.beta.20)
33
- vidibus-sysinfo!
data/spec/spec_helper.rb DELETED
@@ -1,11 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__))
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
-
4
- require "rubygems"
5
- require "rspec"
6
- require "rr"
7
- require "vidibus-sysinfo"
8
-
9
- RSpec.configure do |config|
10
- config.mock_with :rr
11
- end
@@ -1,59 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo::Bandwidth" do
4
- let(:this) {Vidibus::Sysinfo::Bandwidth}
5
- let(:first_output) do
6
- " eth0:11987621067 183430993 0 0 0 0 0 0 639006876738 427999432 0 0 0 0 0 0"
7
- end
8
- let(:second_output) do
9
- " eth0:11987897466 183435418 0 0 0 0 0 0 639026477572 428012510 0 0 0 0 0 0"
10
- end
11
-
12
- describe ".command" do
13
- it "should return 'cat /proc/net/dev | grep eth0:'" do
14
- this.command.should eql("cat /proc/net/dev | grep eth0:")
15
- end
16
- end
17
-
18
- describe ".parse" do
19
- it "should return a float of megabytes from valid output" do
20
- this.parse(first_output).should eql(620836.73)
21
- end
22
-
23
- it "should return nil from invalid output" do
24
- this.parse("something").should be_nil
25
- end
26
- end
27
-
28
- describe ".call" do
29
- let(:calls) do
30
- [
31
- [first_output, ""],
32
- [second_output, ""]
33
- ]
34
- end
35
-
36
- before do
37
- stub(this).perform(this.command) {calls.shift}
38
- end
39
-
40
- it "should return the currently used bandwidth in MBit/s" do
41
- this.call.should eql(151.68)
42
- end
43
-
44
- it "should accept a seconds argument as interval" do
45
- mock(this).sleep(2)
46
- this.call(2)
47
- end
48
-
49
- it "should divide the result by given seconds" do
50
- stub(this).sleep(3)
51
- this.call(3).should eql(151.68/3)
52
- end
53
-
54
- it "should yield an error if /proc/net/dev is not available" do
55
- stub(this).perform(this.command) {["", "cat: /proc/net/dev: No such file or directory\n"]}
56
- expect {this.call}.to raise_error(Vidibus::Sysinfo::CallError)
57
- end
58
- end
59
- end
@@ -1,34 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo::Core" do
4
- let(:this) {Vidibus::Sysinfo::Core}
5
- let(:output) {"8"}
6
-
7
- describe ".command" do
8
- it "should return 'cat /proc/cpuinfo | grep processor | wc -l'" do
9
- this.command.should eql("cat /proc/cpuinfo | grep processor | wc -l")
10
- end
11
- end
12
-
13
- describe ".parse" do
14
- it "should return a number from valid output" do
15
- this.parse(output).should eql(8)
16
- end
17
-
18
- it "should return nil from invalid output" do
19
- this.parse("something").should be_nil
20
- end
21
- end
22
-
23
- describe ".call" do
24
- it "should return the number of CPU cores" do
25
- stub(this).perform(this.command) {[output, ""]}
26
- this.call.should eql(8)
27
- end
28
-
29
- it "should yield an error if /proc/cpuinfo is not available" do
30
- stub(this).perform(this.command) {[" 0\n", "cat: /proc/cpuinfo: No such file or directory\n"]}
31
- expect {this.call}.to raise_error(Vidibus::Sysinfo::CallError)
32
- end
33
- end
34
- end
@@ -1,34 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo::Cpu" do
4
- let(:this) {Vidibus::Sysinfo::Cpu}
5
- let(:output) {"Average: all 0.72 0.00 0.21 0.41 0.05 0.26 0.00 98.35 2950.20"}
6
-
7
- describe ".command" do
8
- it "should return 'mpstat 5 1 | grep Average:'" do
9
- this.command.should eql("mpstat 5 1 | grep Average:")
10
- end
11
- end
12
-
13
- describe ".parse" do
14
- it "should return a decimal from valid output" do
15
- this.parse(output).should eql(1.65)
16
- end
17
-
18
- it "should return nil from invalid output" do
19
- this.parse("something").should be_nil
20
- end
21
- end
22
-
23
- describe ".call" do
24
- it "should return the CPU load in percent" do
25
- stub(this).perform(this.command) {[output, ""]}
26
- this.call.should eql(1.65)
27
- end
28
-
29
- it "should yield an error if mpstat is not installed" do
30
- stub(this).perform(this.command) {["", "sh: mpstat: command not found\n"]}
31
- expect {this.call}.to raise_error(Vidibus::Sysinfo::CallError)
32
- end
33
- end
34
- end
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo::Load" do
4
- let(:this) {Vidibus::Sysinfo::Load}
5
- let(:output) {" 19:52:41 up 2 days, 9:39, 4 users, load average: 0.46, 0.53, 0.56"}
6
-
7
- before {stub(Vidibus::Sysinfo::Core).call {2}}
8
-
9
- describe ".command" do
10
- it "should return 'uptime'" do
11
- this.command.should eql("uptime")
12
- end
13
- end
14
-
15
- describe ".parse" do
16
- it "should return a decimal from valid output" do
17
- this.parse(output).should eql(0.23)
18
- end
19
-
20
- it "should return nil from invalid output" do
21
- this.parse("something").should be_nil
22
- end
23
- end
24
-
25
- describe ".call" do
26
- it "should return the system load as decimal" do
27
- stub(this).perform(this.command) {[output, ""]}
28
- this.call.should eql(0.23)
29
- end
30
-
31
- it "should yield a ParseError if output of uptime could not be parsed" do
32
- stub(this).perform(this.command) {["20:14 up 6 days, 22:03, 20 users, load averages: 0,41 0,26 0,29\n",""]}
33
- expect {this.call}.to raise_error(Vidibus::Sysinfo::ParseError)
34
- end
35
- end
36
- end
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo::Memory" do
4
- let(:this) {Vidibus::Sysinfo::Memory}
5
- let(:output) do
6
- "Mem: 12041 11873 167 0 75 10511"
7
- end
8
-
9
- describe ".command" do
10
- it "should return 'free -m | grep Mem:'" do
11
- this.command.should eql("free -m | grep Mem:")
12
- end
13
- end
14
-
15
- describe ".parse" do
16
- it "should return a number from valid output" do
17
- this.parse(output).should eql(1362)
18
- end
19
-
20
- it "should return nil from invalid output" do
21
- this.parse("something").should be_nil
22
- end
23
- end
24
-
25
- describe ".call" do
26
- it "should return the number of CPU cores" do
27
- stub(this).perform(this.command) {[output, ""]}
28
- this.call.should eql(1362)
29
- end
30
-
31
- it "should yield an error if /proc/cpuinfo is not available" do
32
- stub(this).perform(this.command) {["", "sh: free: command not found\n"]}
33
- expect {this.call}.to raise_error(Vidibus::Sysinfo::CallError)
34
- end
35
- end
36
- end
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo::Storage" do
4
- let(:this) {Vidibus::Sysinfo::Storage}
5
- let(:output) do
6
- "Filesystem Size Used Avail Use% Mounted on
7
- /dev/md2 1.4T 693G 622G 53% /
8
- tmpfs 5.9G 0 5.9G 0% /lib/init/rw
9
- udev 10M 764K 9.3M 8% /dev
10
- tmpfs 5.9G 0 5.9G 0% /dev/shm
11
- /dev/md1 251M 22M 217M 10% /boot"
12
- end
13
-
14
- describe ".command" do
15
- it "should return 'df -h'" do
16
- this.command.should eql("df -h")
17
- end
18
- end
19
-
20
- describe ".parse" do
21
- it "should return a number from valid output" do
22
- this.parse(output).should eql(693.0)
23
- end
24
-
25
- it "should return nil from invalid output" do
26
- this.parse("something").should be_nil
27
- end
28
- end
29
-
30
- describe ".call" do
31
- it "should return the used storage in gigabytes" do
32
- stub(this).perform(this.command) {[output, ""]}
33
- this.call.should eql(693.0)
34
- end
35
- end
36
- end
@@ -1,36 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo::Swap" do
4
- let(:this) {Vidibus::Sysinfo::Swap}
5
- let(:output) do
6
- "Swap: 2053 0 2052"
7
- end
8
-
9
- describe ".command" do
10
- it "should return 'free -m | grep Swap:'" do
11
- this.command.should eql("free -m | grep Swap:")
12
- end
13
- end
14
-
15
- describe ".parse" do
16
- it "should return a number from valid output" do
17
- this.parse(output).should eql(0)
18
- end
19
-
20
- it "should return nil from invalid output" do
21
- this.parse("something").should be_nil
22
- end
23
- end
24
-
25
- describe ".call" do
26
- it "should return the number of CPU cores" do
27
- stub(this).perform(this.command) {[output, ""]}
28
- this.call.should eql(0)
29
- end
30
-
31
- it "should yield an error if /proc/cpuinfo is not available" do
32
- stub(this).perform(this.command) {["", "sh: free: command not found\n"]}
33
- expect {this.call}.to raise_error(Vidibus::Sysinfo::CallError)
34
- end
35
- end
36
- end
@@ -1,46 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo::Traffic" do
4
- let(:this) {Vidibus::Sysinfo::Traffic}
5
- let(:output) do
6
- " eth0 / monthly
7
-
8
- month rx | tx | total
9
- -------------------------+--------------+--------------------------------------
10
- Feb '11 31.62 GB | 1.93 TB | 1.96 TB ::::::::::::::::::::::
11
- -------------------------+--------------+--------------------------------------
12
- estimated 88 GB | 5.50 TB | 5.58 TB"
13
- end
14
-
15
- describe ".command" do
16
- it "should return 'vnstat -m'" do
17
- this.command.should eql("vnstat -m")
18
- end
19
- end
20
-
21
- describe ".parse" do
22
- it "should return a number from valid output" do
23
- this.parse(output).should eql(2007.04)
24
- end
25
-
26
- it "should return 0.0 if not enough data is available yet" do
27
- this.parse(" eth0: Not enough data available yet.\n").should eql(0.0)
28
- end
29
-
30
- it "should return nil from invalid output" do
31
- this.parse("something").should be_nil
32
- end
33
- end
34
-
35
- describe ".call" do
36
- it "should return the total traffic in gigabytes" do
37
- stub(this).perform(this.command) {[output, ""]}
38
- this.call.should eql(2007.04)
39
- end
40
-
41
- it "should yield an error if the command is not available" do
42
- stub(this).perform(this.command) {["", "/Users/punkrats/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/open3.rb:73:in `exec': Permission denied - vnstat -m (Errno::EACCES)\n\tfrom /Users/punkrats/.rvm/rubies/ruby-1.8.7-p249/lib/ruby/1.8/open3.rb:73:in `popen3'\n\tfrom..."]}
43
- expect {this.call}.to raise_error(Vidibus::Sysinfo::CallError)
44
- end
45
- end
46
- end
@@ -1,66 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Vidibus::Sysinfo" do
4
- let(:this) {Vidibus::Sysinfo}
5
-
6
- describe ".core" do
7
- it "should call Vidibus::Sysinfo::Core" do
8
- mock(this::Core).call
9
- this.core
10
- end
11
- end
12
-
13
- describe ".cpu" do
14
- it "should call Vidibus::Sysinfo::Cpu" do
15
- mock(this::Cpu).call
16
- this.cpu
17
- end
18
- end
19
-
20
- describe ".load" do
21
- it "should call Vidibus::Sysinfo::Load" do
22
- mock(this::Load).call
23
- this.load
24
- end
25
- end
26
-
27
- describe ".traffic" do
28
- it "should call Vidibus::Sysinfo::Traffic" do
29
- mock(this::Traffic).call
30
- this.traffic
31
- end
32
- end
33
-
34
- describe ".bandwidth" do
35
- it "should call Vidibus::Sysinfo::Bandwidth" do
36
- mock(this::Bandwidth).call(1)
37
- this.bandwidth
38
- end
39
-
40
- it "should accept a seconds argument" do
41
- mock(this::Bandwidth).call(2)
42
- this.bandwidth(2)
43
- end
44
- end
45
-
46
- describe ".storage" do
47
- it "should call Vidibus::Sysinfo::Storage" do
48
- mock(this::Storage).call
49
- this.storage
50
- end
51
- end
52
-
53
- describe ".memory" do
54
- it "should call Vidibus::Sysinfo::Memory" do
55
- mock(this::Memory).call
56
- this.memory
57
- end
58
- end
59
-
60
- describe ".swap" do
61
- it "should call Vidibus::Sysinfo::Swap" do
62
- mock(this::Swap).call
63
- this.swap
64
- end
65
- end
66
- end
@@ -1,26 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path("../lib/vidibus/sysinfo/version", __FILE__)
3
-
4
- Gem::Specification.new do |s|
5
- s.name = "vidibus-sysinfo"
6
- s.version = Vidibus::Sysinfo::VERSION
7
- s.platform = Gem::Platform::RUBY
8
- s.authors = "Andre Pankratz"
9
- s.email = "andre@vidibus.com"
10
- s.homepage = "https://github.com/vidibus/vidibus-sysinfo"
11
- s.summary = "Provides tools for obtaining information about the system"
12
- s.description = "Gets CPU usage, current load, consumed memory and some other figures."
13
-
14
- s.required_rubygems_version = ">= 1.3.6"
15
- s.rubyforge_project = "vidibus-sysinfo"
16
-
17
- s.add_development_dependency "bundler", ">= 1.0.0"
18
- s.add_development_dependency "rake"
19
- s.add_development_dependency "rspec", "~> 2.0.0.beta.20"
20
- s.add_development_dependency "rr"
21
- s.add_development_dependency "relevance-rcov"
22
-
23
- s.files = `git ls-files`.split("\n")
24
- s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
25
- s.require_path = 'lib'
26
- end