heartbeat-client 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +6 -0
  3. data/Rakefile +2 -0
  4. data/VERSION +1 -1
  5. data/lib/heartbeat-client.rb +55 -7
  6. metadata +57 -15
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
  gem 'httparty'
3
3
  gem 'daemons'
4
+ gem 'foreman'
4
5
 
5
6
  # Add dependencies to develop your gem here.
6
7
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -2,6 +2,9 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  daemons (1.1.4)
5
+ foreman (0.30.1)
6
+ term-ansicolor (~> 1.0.5)
7
+ thor (>= 0.13.6)
5
8
  git (1.2.5)
6
9
  httparty (0.8.1)
7
10
  multi_json
@@ -15,6 +18,8 @@ GEM
15
18
  rake (0.9.2.2)
16
19
  rcov (0.9.11)
17
20
  shoulda (2.11.3)
21
+ term-ansicolor (1.0.7)
22
+ thor (0.14.6)
18
23
 
19
24
  PLATFORMS
20
25
  ruby
@@ -22,6 +27,7 @@ PLATFORMS
22
27
  DEPENDENCIES
23
28
  bundler (~> 1.0.0)
24
29
  daemons
30
+ foreman
25
31
  httparty
26
32
  jeweler (~> 1.5.2)
27
33
  rcov
data/Rakefile CHANGED
@@ -21,6 +21,8 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.authors = ["Oliver Kiessler"]
22
22
  gem.add_runtime_dependency 'daemons'
23
23
  gem.add_runtime_dependency 'httparty'
24
+ gem.add_runtime_dependency 'json'
25
+ gem.add_runtime_dependency 'foreman'
24
26
  end
25
27
  Jeweler::RubygemsDotOrgTasks.new
26
28
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -25,6 +25,9 @@ class Heartbeat
25
25
  load_avg = []
26
26
  cpu_usage = {'user' => 0, 'sys' => 0, 'idle' => 0}
27
27
  processes = []
28
+ memory = {'free' => 0, 'used' => 0}
29
+ disks = {}
30
+ swap = {'free' => 0, 'used' => 0}
28
31
 
29
32
  if is_linux?
30
33
  `top -b -n1 > /tmp/top.out`
@@ -32,6 +35,8 @@ class Heartbeat
32
35
  `top -l 1 > /tmp/top.out`
33
36
  end
34
37
 
38
+ `df -m > /tmp/dfm.out`
39
+
35
40
  if File.exists?('/tmp/top.out')
36
41
  counter = 0; proc_count = 0
37
42
  File.open("/tmp/top.out", "r") do |infile|
@@ -40,17 +45,30 @@ class Heartbeat
40
45
  processes(procs, line) if line.include?('Task')
41
46
  load_averages(load_avg, line) if line.include?('load average')
42
47
  cpu_usages(cpu_usage, line) if line.include?('Cpu')
48
+ memory_usage(memory, line) if line.include?('Mem')
49
+ swap_usage(swap, line) if line.include?('Swap')
43
50
  proc_count = counter + 1 if line.include?('PID') and line.include?('COMMAND')
44
51
  else
45
52
  processes(procs, line) if line.include?('Processes')
46
53
  load_averages(load_avg, line) if line.include?('Load Avg')
47
54
  cpu_usages(cpu_usage, line) if line.include?('CPU usage')
55
+ memory_usage(memory, line) if line.include?('PhysMem')
48
56
  proc_count = counter + 1 if line.include?('PID') and line.include?('COMMAND')
49
57
  end
50
58
  process(processes, line) if proc_count > 0 and counter >= proc_count
51
59
  counter += 1
52
60
  end
53
61
  end
62
+
63
+ if File.exists?('/tmp/dfm.out')
64
+ File.open("/tmp/dfm.out", "r") do |infile|
65
+ counter = 0
66
+ while (line = infile.gets)
67
+ disk_usage(disks, line) if counter > 0
68
+ counter += 1
69
+ end
70
+ end
71
+ end
54
72
 
55
73
  options = {
56
74
  :body => {
@@ -62,16 +80,21 @@ class Heartbeat
62
80
  :process_stats => procs,
63
81
  :load_avg => load_avg,
64
82
  :cpu_usage => cpu_usage,
65
- :processes => processes
83
+ :processes => processes,
84
+ :memory => memory,
85
+ :disks => disks,
86
+ :swap => swap
66
87
  }
67
88
  }
68
89
  }
69
90
  }
70
91
 
71
- #puts procs.inspect
72
- #puts load_avg.inspect
73
- #puts cpu_usage.inspect
74
- #puts processes.inspect
92
+ puts procs.inspect
93
+ puts load_avg.inspect
94
+ puts cpu_usage.inspect
95
+ puts processes.inspect
96
+ puts memory.inspect
97
+ puts disks.inspect
75
98
 
76
99
  Heartbeat.post('/heartbeat', options)
77
100
  else
@@ -114,10 +137,35 @@ class Heartbeat
114
137
  end
115
138
  end
116
139
 
117
- def self.process(processes, line)
118
- procs = line.split(' ')
140
+ def self.process(processes, str)
141
+ procs = str.split(' ')
119
142
  if procs and procs.size > 0
120
143
  processes << (is_linux? ? procs[11].strip : procs[1].strip)
121
144
  end
122
145
  end
146
+
147
+ def self.memory_usage(memory, str)
148
+ mem = str.split(':')
149
+ if mem and mem[0]
150
+ mem[1].split(',').each do |m|
151
+ memory['free'] = m.split(' ')[0].strip if m.include?('free')
152
+ memory['used'] = m.split(' ')[0].strip if m.include?('used')
153
+ end
154
+ end
155
+ end
156
+
157
+ def self.swap_usage(swap, str)
158
+ sw = str.split(':')
159
+ if sw and sw[0]
160
+ sw[1].split(',').each do |s|
161
+ swap['free'] = s.split(' ')[0].strip if s.include?('free')
162
+ swap['used'] = s.split(' ')[0].strip if s.include?('used')
163
+ end
164
+ end
165
+ end
166
+
167
+ def self.disk_usage(disks, str)
168
+ ds = str.split(' ')
169
+ disks[ds[0].strip] = {'used' => ds[2].strip, 'available' => ds[3].strip}
170
+ end
123
171
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heartbeat-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oliver Kiessler
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-05 00:00:00 Z
18
+ date: 2012-01-07 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -55,12 +55,26 @@ dependencies:
55
55
  segments:
56
56
  - 0
57
57
  version: "0"
58
- name: shoulda
58
+ name: foreman
59
59
  prerelease: false
60
- type: :development
60
+ type: :runtime
61
61
  requirement: *id003
62
62
  - !ruby/object:Gem::Dependency
63
63
  version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ name: shoulda
73
+ prerelease: false
74
+ type: :development
75
+ requirement: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ version_requirements: &id005 !ruby/object:Gem::Requirement
64
78
  none: false
65
79
  requirements:
66
80
  - - ~>
@@ -74,9 +88,9 @@ dependencies:
74
88
  name: bundler
75
89
  prerelease: false
76
90
  type: :development
77
- requirement: *id004
91
+ requirement: *id005
78
92
  - !ruby/object:Gem::Dependency
79
- version_requirements: &id005 !ruby/object:Gem::Requirement
93
+ version_requirements: &id006 !ruby/object:Gem::Requirement
80
94
  none: false
81
95
  requirements:
82
96
  - - ~>
@@ -90,9 +104,9 @@ dependencies:
90
104
  name: jeweler
91
105
  prerelease: false
92
106
  type: :development
93
- requirement: *id005
107
+ requirement: *id006
94
108
  - !ruby/object:Gem::Dependency
95
- version_requirements: &id006 !ruby/object:Gem::Requirement
109
+ version_requirements: &id007 !ruby/object:Gem::Requirement
96
110
  none: false
97
111
  requirements:
98
112
  - - ">="
@@ -104,9 +118,9 @@ dependencies:
104
118
  name: rcov
105
119
  prerelease: false
106
120
  type: :development
107
- requirement: *id006
121
+ requirement: *id007
108
122
  - !ruby/object:Gem::Dependency
109
- version_requirements: &id007 !ruby/object:Gem::Requirement
123
+ version_requirements: &id008 !ruby/object:Gem::Requirement
110
124
  none: false
111
125
  requirements:
112
126
  - - ">="
@@ -118,9 +132,9 @@ dependencies:
118
132
  name: daemons
119
133
  prerelease: false
120
134
  type: :runtime
121
- requirement: *id007
135
+ requirement: *id008
122
136
  - !ruby/object:Gem::Dependency
123
- version_requirements: &id008 !ruby/object:Gem::Requirement
137
+ version_requirements: &id009 !ruby/object:Gem::Requirement
124
138
  none: false
125
139
  requirements:
126
140
  - - ">="
@@ -132,7 +146,35 @@ dependencies:
132
146
  name: httparty
133
147
  prerelease: false
134
148
  type: :runtime
135
- requirement: *id008
149
+ requirement: *id009
150
+ - !ruby/object:Gem::Dependency
151
+ version_requirements: &id010 !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ hash: 3
157
+ segments:
158
+ - 0
159
+ version: "0"
160
+ name: json
161
+ prerelease: false
162
+ type: :runtime
163
+ requirement: *id010
164
+ - !ruby/object:Gem::Dependency
165
+ version_requirements: &id011 !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ name: foreman
175
+ prerelease: false
176
+ type: :runtime
177
+ requirement: *id011
136
178
  description: Heartbeat Client in Ruby
137
179
  email: kiessler@inceedo.com
138
180
  executables: