heartbeat-client 0.3.2 → 0.4.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
data/bin/hbc CHANGED
@@ -28,7 +28,7 @@ if ARGV and ARGV.size == 1
28
28
  Heartbeat.log = Logger.new('/tmp/heartbeat.log')
29
29
  loop do
30
30
  begin
31
- Heartbeat.create(@config['apikey'], @config['endpoint'], @config['name'])
31
+ Heartbeat.create(@config)
32
32
  rescue => e
33
33
  puts e.message
34
34
  end
@@ -0,0 +1,4 @@
1
+ endpoint: "http://heartbeat-monitoring.com"
2
+ apikey: "<YOUR KEY>"
3
+ name: "<SERVER NAME ALIAS>"
4
+ apache_status: "http://127.0.0.1/server-status/?auto"
@@ -23,9 +23,14 @@ class Heartbeat
23
23
  @@log
24
24
  end
25
25
 
26
- def self.create(apikey, endpoint, name = nil)
26
+ def self.create(config)
27
27
  log.info("#create - Collecting data...")
28
28
 
29
+ apikey = config['apikey']
30
+ endpoint = config['endpoint']
31
+ name = config['name']
32
+ apache_status = config['apache_status']
33
+
29
34
  procs = {'total' => 0, 'running' => 0, 'stuck' => 0, 'sleeping' => 0, 'threads' => 0, 'stopped' => 0, 'zombie' => 0}
30
35
  load_avg = []
31
36
  cpu_usage = {'user' => 0, 'sys' => 0, 'idle' => 0}
@@ -33,6 +38,7 @@ class Heartbeat
33
38
  memory = {'free' => 0, 'used' => 0}
34
39
  disks = {}
35
40
  swap = {'free' => 0, 'used' => 0}
41
+ apache = {}
36
42
 
37
43
  log.debug("Dumping top output...")
38
44
  if is_linux?
@@ -44,6 +50,10 @@ class Heartbeat
44
50
  log.debug("Dumping df output...")
45
51
  `df -m > /tmp/dfm.out`
46
52
 
53
+ if apache_status
54
+ `curl #{apache_status} > /tmp/apache.out`
55
+ end
56
+
47
57
  if File.exists?('/tmp/top.out')
48
58
  counter = 0; proc_count = 0
49
59
  File.open("/tmp/top.out", "r") do |infile|
@@ -76,6 +86,16 @@ class Heartbeat
76
86
  end
77
87
  end
78
88
  end
89
+
90
+ if File.exists?('/tmp/apache.out')
91
+ File.open("/tmp/apache.out", "r") do |infile|
92
+ counter = 0; lines = []
93
+ while (line = infile.gets)
94
+ apache_status(apache, line)
95
+ counter += 1
96
+ end
97
+ end
98
+ end
79
99
 
80
100
  options = {
81
101
  :body => {
@@ -92,12 +112,13 @@ class Heartbeat
92
112
  :processes => processes,
93
113
  :memory => memory,
94
114
  :disks => disks,
95
- :swap => swap
115
+ :swap => swap,
116
+ :apache_status => apache
96
117
  }
97
118
  }
98
119
  }
99
120
  }
100
-
121
+
101
122
  log.info("#create - Sending data to endpoint...")
102
123
  res = Heartbeat.post(endpoint + '/heartbeat', options)
103
124
  log.debug("Response: #{res.response.inspect}") if res
@@ -168,7 +189,16 @@ class Heartbeat
168
189
  end
169
190
  end
170
191
  end
171
-
192
+
193
+ def self.apache_status(apache, str)
194
+ ap = str.split(':')
195
+ if ap and ap[0]
196
+ apache['requests'] = ap[1].strip.to_f if ap[0].include?('ReqPerSec')
197
+ apache['busy_workers'] = ap[1].strip.to_i if ap[0].include?('BusyWorkers')
198
+ apache['idle_workers'] = ap[1].strip.to_i if ap[0].include?('IdleWorkers')
199
+ end
200
+ end
201
+
172
202
  def self.disk_usage(disks, str)
173
203
  ds = str.split(' ')
174
204
  disks[ds[0].strip] = {'used' => ds[2].strip, 'available' => ds[3].strip}
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: 23
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 2
10
- version: 0.3.2
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
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-13 00:00:00 Z
18
+ date: 2012-01-15 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -222,6 +222,7 @@ files:
222
222
  - Rakefile
223
223
  - VERSION
224
224
  - bin/hbc
225
+ - heartbeat-client.yml.sample
225
226
  - lib/heartbeat-client.rb
226
227
  - test/helper.rb
227
228
  - test/test_heartbeat-client.rb