machine 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT LICENSE
2
+
3
+ Copyright (c) chatgris <jboyer@af83.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # machine
2
+
3
+ Machine collects some informations about cpu, memory, processes.
4
+
5
+ # Usage
6
+
7
+ ``` ruby
8
+ Machine::Info::Cpu.cores_size
9
+ Machine::Info::Memory.mem_total
10
+ Machine::Info::Memory.mem_free
11
+ Machine::ProcessStatus.new(pid).pctcpu
12
+ Machine::ProcessStatus.new(pid).pctmem
13
+ ```
14
+
15
+ Check out the [sys-proctable](https://github.com/djberg96/sys-proctable) from
16
+ documentation about ProcessStatus.
17
+
18
+ ## Copyright
19
+
20
+ MIT. See LICENSE for further details.
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+ module Machine
3
+ class Info
4
+ class Cpu < CpuDefault
5
+ class << self
6
+ def cores_size
7
+ `sysctl -n hw.ncpu`.to_i
8
+ end
9
+ end
10
+ end
11
+
12
+ class Memory
13
+ class << self
14
+ def mem_total
15
+ `sysctl -n hw.memsize`.to_i
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+ module Machine
3
+ class Info
4
+ class CpuDefault
5
+ class << self
6
+ def cores_size
7
+ 1
8
+ end
9
+ end
10
+ end
11
+
12
+ class Memory
13
+ class << self
14
+ def mem_total
15
+ 1024 * 1024
16
+ end
17
+
18
+ def mem_free
19
+ 512 * 1024
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+ module Machine
3
+ class Info
4
+ class Cpu < CpuDefault
5
+ class << self
6
+ def cores_size
7
+ `grep -c processor /proc/cpuinfo`.to_i
8
+ end
9
+ end
10
+ end
11
+
12
+ class Memory
13
+ class << self
14
+ def mem_total
15
+ `grep MemTotal /proc/meminfo`.split(' ')[1].to_i
16
+ end
17
+
18
+ def mem_free
19
+ `grep MemFree /proc/meminfo`.split(' ')[1].to_i
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ require 'sys/proctable'
3
+ require 'delegate'
4
+
5
+ module Machine
6
+ class ProcessStatus < SimpleDelegator
7
+ include Sys
8
+
9
+ def initialize(pid)
10
+ super ProcTable.ps(pid)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Machine
2
+ VERSION = "0.0.1"
3
+ end
data/lib/machine.rb ADDED
@@ -0,0 +1,11 @@
1
+ # encoding: utf-8
2
+ module Machine
3
+ end
4
+ require_relative 'machine/default/info'
5
+ case RbConfig::CONFIG['host_os']
6
+ when /linux/
7
+ require_relative 'machine/linux/info'
8
+ when /darwin/
9
+ require_relative 'machine/darwin/info'
10
+ end
11
+ require_relative 'machine/process_status'
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: machine
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - chatgris
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sys-proctable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Machine collects some informations about cpu, memory, processes.
31
+ email:
32
+ - jboyer@af83.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - LICENSE
38
+ - README.md
39
+ - lib/machine.rb
40
+ - lib/machine/darwin/info.rb
41
+ - lib/machine/default/info.rb
42
+ - lib/machine/linux/info.rb
43
+ - lib/machine/process_status.rb
44
+ - lib/machine/version.rb
45
+ homepage: https://github.com/chatgris/machine
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Machine collects some informations about cpu, memory, processes.
69
+ test_files: []