heartbeat-client 0.4.2 → 0.4.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/VERSION +1 -1
- data/bin/hbc +4 -1
- data/lib/heartbeat-client.rb +105 -86
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
data/bin/hbc
CHANGED
@@ -35,9 +35,12 @@ if ARGV and ARGV.size == 1
|
|
35
35
|
Daemons.run_proc('heartbeat-client.rb', :dir => File.join('/tmp'), :monitor => true,
|
36
36
|
:backtrace => true, :monitor => true) do
|
37
37
|
Heartbeat.log = Logger.new('/tmp/heartbeat.log')
|
38
|
+
count = 0
|
38
39
|
loop do
|
39
40
|
begin
|
40
|
-
Heartbeat.create(@config, version)
|
41
|
+
Heartbeat.create(@config, version, (count == 2))
|
42
|
+
count += 1
|
43
|
+
count = 0 if count == 2
|
41
44
|
rescue => e
|
42
45
|
puts e.message
|
43
46
|
end
|
data/lib/heartbeat-client.rb
CHANGED
@@ -25,7 +25,7 @@ class Heartbeat
|
|
25
25
|
@@log
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.create(config, version = '0.0')
|
28
|
+
def self.create(config, version = '0.0', gather_metrics = false)
|
29
29
|
log.info("#create - Collecting data...")
|
30
30
|
|
31
31
|
apikey = config['apikey']
|
@@ -34,89 +34,121 @@ class Heartbeat
|
|
34
34
|
apache_status = config['apache_status']
|
35
35
|
mongostat_arguments = config['mongostat_arguments']
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
log.debug("Dumping top output...")
|
48
|
-
if is_linux?
|
49
|
-
`top -b -n1 > /tmp/top.out`
|
50
|
-
else
|
51
|
-
`top -l 1 > /tmp/top.out`
|
52
|
-
end
|
53
|
-
|
54
|
-
log.debug("Dumping df output...")
|
55
|
-
`df -m > /tmp/dfm.out`
|
37
|
+
if gather_metrics
|
38
|
+
procs = {'total' => 0, 'running' => 0, 'stuck' => 0, 'sleeping' => 0, 'threads' => 0, 'stopped' => 0, 'zombie' => 0}
|
39
|
+
load_avg = []
|
40
|
+
cpu_usage = {'user' => 0, 'sys' => 0, 'idle' => 0}
|
41
|
+
processes = []
|
42
|
+
memory = {'free' => 0, 'used' => 0}
|
43
|
+
disks = {}
|
44
|
+
swap = {'free' => 0, 'used' => 0}
|
45
|
+
apache = {}
|
46
|
+
mongodb = {}
|
56
47
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
48
|
+
log.debug("Dumping top output...")
|
49
|
+
if is_linux?
|
50
|
+
`top -b -n1 > /tmp/top.out`
|
51
|
+
else
|
52
|
+
`top -l 1 > /tmp/top.out`
|
53
|
+
end
|
61
54
|
|
62
|
-
|
63
|
-
|
64
|
-
`mongostat #{mongostat_arguments} > /tmp/mongodb.out`
|
65
|
-
end
|
55
|
+
log.debug("Dumping df output...")
|
56
|
+
`df -m > /tmp/dfm.out`
|
66
57
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
memory_usage(memory, line) if line.include?('Mem')
|
76
|
-
swap_usage(swap, line) if line.include?('Swap')
|
77
|
-
proc_count = counter + 1 if line.include?('PID') and line.include?('COMMAND')
|
78
|
-
else
|
79
|
-
processes(procs, line) if line.include?('Processes')
|
80
|
-
load_averages(load_avg, line) if line.include?('Load Avg')
|
81
|
-
cpu_usages(cpu_usage, line) if line.include?('CPU usage')
|
82
|
-
memory_usage(memory, line) if line.include?('PhysMem')
|
83
|
-
proc_count = counter + 1 if line.include?('PID') and line.include?('COMMAND')
|
84
|
-
end
|
85
|
-
process(processes, line) if proc_count > 0 and counter >= proc_count
|
86
|
-
counter += 1
|
87
|
-
end
|
58
|
+
if apache_status
|
59
|
+
log.debug("Dumping apache status output...")
|
60
|
+
`curl #{apache_status} > /tmp/apache.out`
|
61
|
+
end
|
62
|
+
|
63
|
+
if mongostat_arguments
|
64
|
+
log.debug("Dumping mongostat output...")
|
65
|
+
`mongostat #{mongostat_arguments} > /tmp/mongodb.out`
|
88
66
|
end
|
89
|
-
|
90
|
-
if File.exists?('/tmp/
|
91
|
-
|
92
|
-
|
67
|
+
|
68
|
+
if File.exists?('/tmp/top.out')
|
69
|
+
counter = 0; proc_count = 0
|
70
|
+
File.open("/tmp/top.out", "r") do |infile|
|
93
71
|
while (line = infile.gets)
|
94
|
-
|
72
|
+
if is_linux?
|
73
|
+
processes(procs, line) if line.include?('Task')
|
74
|
+
load_averages(load_avg, line) if line.include?('load average')
|
75
|
+
cpu_usages(cpu_usage, line) if line.include?('Cpu')
|
76
|
+
memory_usage(memory, line) if line.include?('Mem')
|
77
|
+
swap_usage(swap, line) if line.include?('Swap')
|
78
|
+
proc_count = counter + 1 if line.include?('PID') and line.include?('COMMAND')
|
79
|
+
else
|
80
|
+
processes(procs, line) if line.include?('Processes')
|
81
|
+
load_averages(load_avg, line) if line.include?('Load Avg')
|
82
|
+
cpu_usages(cpu_usage, line) if line.include?('CPU usage')
|
83
|
+
memory_usage(memory, line) if line.include?('PhysMem')
|
84
|
+
proc_count = counter + 1 if line.include?('PID') and line.include?('COMMAND')
|
85
|
+
end
|
86
|
+
process(processes, line) if proc_count > 0 and counter >= proc_count
|
95
87
|
counter += 1
|
96
88
|
end
|
97
89
|
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
90
|
+
|
91
|
+
if File.exists?('/tmp/dfm.out')
|
92
|
+
File.open("/tmp/dfm.out", "r") do |infile|
|
93
|
+
counter = 0
|
94
|
+
while (line = infile.gets)
|
95
|
+
disk_usage(disks, line) if counter > 0
|
96
|
+
counter += 1
|
97
|
+
end
|
106
98
|
end
|
107
99
|
end
|
108
|
-
end
|
109
100
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
101
|
+
if File.exists?('/tmp/apache.out')
|
102
|
+
File.open("/tmp/apache.out", "r") do |infile|
|
103
|
+
counter = 0; lines = []
|
104
|
+
while (line = infile.gets)
|
105
|
+
apache_status(apache, line)
|
106
|
+
counter += 1
|
107
|
+
end
|
115
108
|
end
|
116
|
-
mongodb_status(mongodb, lines)
|
117
109
|
end
|
118
|
-
end
|
119
110
|
|
111
|
+
if File.exists?('/tmp/mongodb.out')
|
112
|
+
File.open("/tmp/mongodb.out", "r") do |infile|
|
113
|
+
counter = 0; lines = []
|
114
|
+
while (line = infile.gets)
|
115
|
+
lines << line
|
116
|
+
end
|
117
|
+
mongodb_status(mongodb, lines)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
options = {
|
122
|
+
:body => {
|
123
|
+
:heartbeat => {
|
124
|
+
:client_version => version,
|
125
|
+
:apikey => apikey,
|
126
|
+
:host => `hostname`.chomp,
|
127
|
+
:macaddr => Mac.addr,
|
128
|
+
:name => name,
|
129
|
+
:timestamp => Time.now.to_i,
|
130
|
+
:values => {
|
131
|
+
:process_stats => procs,
|
132
|
+
:load_avg => load_avg,
|
133
|
+
:cpu_usage => cpu_usage,
|
134
|
+
:processes => processes,
|
135
|
+
:memory => memory,
|
136
|
+
:disks => disks,
|
137
|
+
:swap => swap,
|
138
|
+
:apache_status => apache,
|
139
|
+
:mongodb_status => mongodb
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
log.info("#create - Sending data to endpoint (with metrics)...")
|
146
|
+
res = Heartbeat.post(endpoint + '/heartbeat', options)
|
147
|
+
log.debug("Response: #{res.response.inspect}") if res
|
148
|
+
else
|
149
|
+
log.error "No top output found."
|
150
|
+
end
|
151
|
+
else
|
120
152
|
options = {
|
121
153
|
:body => {
|
122
154
|
:heartbeat => {
|
@@ -125,29 +157,16 @@ class Heartbeat
|
|
125
157
|
:host => `hostname`.chomp,
|
126
158
|
:macaddr => Mac.addr,
|
127
159
|
:name => name,
|
128
|
-
:timestamp => Time.now.to_i
|
129
|
-
:values => {
|
130
|
-
:process_stats => procs,
|
131
|
-
:load_avg => load_avg,
|
132
|
-
:cpu_usage => cpu_usage,
|
133
|
-
:processes => processes,
|
134
|
-
:memory => memory,
|
135
|
-
:disks => disks,
|
136
|
-
:swap => swap,
|
137
|
-
:apache_status => apache,
|
138
|
-
:mongodb_status => mongodb
|
139
|
-
}
|
160
|
+
:timestamp => Time.now.to_i
|
140
161
|
}
|
141
162
|
}
|
142
163
|
}
|
143
164
|
|
144
|
-
log.info("#create - Sending data to endpoint...")
|
165
|
+
log.info("#create - Sending data to endpoint (no metrics)...")
|
145
166
|
res = Heartbeat.post(endpoint + '/heartbeat', options)
|
146
167
|
log.debug("Response: #{res.response.inspect}") if res
|
147
|
-
log.info("Finished iteration.")
|
148
|
-
else
|
149
|
-
log.error "No top output found."
|
150
168
|
end
|
169
|
+
log.info("Finished iteration.")
|
151
170
|
end
|
152
171
|
|
153
172
|
def self.processes(procs, str)
|
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:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 3
|
10
|
+
version: 0.4.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-
|
18
|
+
date: 2012-03-31 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
version_requirements: &id001 !ruby/object:Gem::Requirement
|
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
255
|
requirements: []
|
256
256
|
|
257
257
|
rubyforge_project:
|
258
|
-
rubygems_version: 1.8.
|
258
|
+
rubygems_version: 1.8.15
|
259
259
|
signing_key:
|
260
260
|
specification_version: 3
|
261
261
|
summary: Heartbeat
|