heartbeat-client 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/bin/hbc CHANGED
@@ -22,13 +22,22 @@ unless @config['endpoint']
22
22
  exit
23
23
  end
24
24
 
25
+ version = "0.0"
26
+ begin
27
+ file = File.open(File.dirname(__FILE__) + "/../VERSION", "rb")
28
+ version = file.read
29
+ puts "heartbeat-client #{version}"
30
+ rescue => e
31
+ puts e.message
32
+ end
33
+
25
34
  if ARGV and ARGV.size == 1
26
35
  Daemons.run_proc('heartbeat-client.rb', :dir => File.join('/tmp'), :monitor => true,
27
36
  :backtrace => true, :monitor => true) do
28
37
  Heartbeat.log = Logger.new('/tmp/heartbeat.log')
29
38
  loop do
30
39
  begin
31
- Heartbeat.create(@config)
40
+ Heartbeat.create(@config, version)
32
41
  rescue => e
33
42
  puts e.message
34
43
  end
@@ -2,3 +2,5 @@ endpoint: "http://heartbeat-monitoring.com"
2
2
  apikey: "<YOUR KEY>"
3
3
  name: "<SERVER NAME ALIAS>"
4
4
  apache_status: "http://127.0.0.1/server-status/?auto"
5
+ mongostat_arguments: "-h 127.0.0.1 -n 1"
6
+ #mongostat_arguments: "-h 127.0.0.1 -n 1 -u YOUR_USER -p PASS"
@@ -3,6 +3,8 @@ gem 'httparty'
3
3
  require 'httparty'
4
4
  require 'logger'
5
5
  require 'macaddr'
6
+ require 'net/http'
7
+ require 'json'
6
8
 
7
9
  class Heartbeat
8
10
  include HTTParty
@@ -23,13 +25,14 @@ class Heartbeat
23
25
  @@log
24
26
  end
25
27
 
26
- def self.create(config)
28
+ def self.create(config, version = '0.0')
27
29
  log.info("#create - Collecting data...")
28
30
 
29
31
  apikey = config['apikey']
30
32
  endpoint = config['endpoint']
31
33
  name = config['name']
32
34
  apache_status = config['apache_status']
35
+ mongostat_arguments = config['mongostat_arguments']
33
36
 
34
37
  procs = {'total' => 0, 'running' => 0, 'stuck' => 0, 'sleeping' => 0, 'threads' => 0, 'stopped' => 0, 'zombie' => 0}
35
38
  load_avg = []
@@ -39,6 +42,7 @@ class Heartbeat
39
42
  disks = {}
40
43
  swap = {'free' => 0, 'used' => 0}
41
44
  apache = {}
45
+ mongodb = {}
42
46
 
43
47
  log.debug("Dumping top output...")
44
48
  if is_linux?
@@ -51,9 +55,15 @@ class Heartbeat
51
55
  `df -m > /tmp/dfm.out`
52
56
 
53
57
  if apache_status
58
+ log.debug("Dumping apache status output...")
54
59
  `curl #{apache_status} > /tmp/apache.out`
55
60
  end
56
61
 
62
+ if mongostat_arguments
63
+ log.debug("Dumping mongostat output...")
64
+ `mongostat #{mongostat_arguments} > /tmp/mongodb.out`
65
+ end
66
+
57
67
  if File.exists?('/tmp/top.out')
58
68
  counter = 0; proc_count = 0
59
69
  File.open("/tmp/top.out", "r") do |infile|
@@ -97,9 +107,20 @@ class Heartbeat
97
107
  end
98
108
  end
99
109
 
110
+ if File.exists?('/tmp/mongodb.out')
111
+ File.open("/tmp/mongodb.out", "r") do |infile|
112
+ counter = 0
113
+ while (line = infile.gets)
114
+ mongodb_status(mongodb, line) if counter == 2
115
+ counter += 1
116
+ end
117
+ end
118
+ end
119
+
100
120
  options = {
101
121
  :body => {
102
122
  :heartbeat => {
123
+ :client_version => version,
103
124
  :apikey => apikey,
104
125
  :host => `hostname`.chomp,
105
126
  :macaddr => Mac.addr,
@@ -113,7 +134,8 @@ class Heartbeat
113
134
  :memory => memory,
114
135
  :disks => disks,
115
136
  :swap => swap,
116
- :apache_status => apache
137
+ :apache_status => apache,
138
+ :mongodb_status => mongodb
117
139
  }
118
140
  }
119
141
  }
@@ -199,6 +221,26 @@ class Heartbeat
199
221
  end
200
222
  end
201
223
 
224
+ def self.mongodb_status(mongodb, str)
225
+ if (mo = str.split(' '))
226
+ mo.each_with_index do |moa, index|
227
+ mongodb['insert'] = moa.strip.to_i if index == 0
228
+ mongodb['query'] = moa.strip.to_i if index == 1
229
+ mongodb['update'] = moa.strip.to_i if index == 2
230
+ mongodb['delete'] = moa.strip.to_i if index == 3
231
+ mongodb['getmore'] = moa.strip.to_i if index == 4
232
+ mongodb['command'] = moa.strip.to_i if index == 5
233
+ mongodb['flushes'] = moa.strip.to_i if index == 6
234
+ mongodb['mapped'] = moa.strip if index == 7
235
+ mongodb['vsize'] = moa.strip if index == 8
236
+ mongodb['res'] = moa.strip if index == 9
237
+ mongodb['netIn'] = moa.strip if index == 14
238
+ mongodb['netOut'] = moa.strip if index == 15
239
+ mongodb['conn'] = moa.strip if index == 16
240
+ end
241
+ end
242
+ end
243
+
202
244
  def self.disk_usage(disks, str)
203
245
  ds = str.split(' ')
204
246
  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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
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-15 00:00:00 Z
18
+ date: 2012-01-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement