heartbeat-client 0.2.0 → 0.2.1
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/lib/heartbeat-client.rb +42 -19
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.1
|
data/lib/heartbeat-client.rb
CHANGED
|
@@ -21,12 +21,12 @@ class Heartbeat
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def self.create(apikey)
|
|
24
|
-
procs = {'total' => 0, 'running' => 0, 'stuck' => 0, 'sleeping' => 0, 'threads' => 0}
|
|
24
|
+
procs = {'total' => 0, 'running' => 0, 'stuck' => 0, 'sleeping' => 0, 'threads' => 0, 'stopped' => 0, 'zombie' => 0}
|
|
25
25
|
load_avg = []
|
|
26
26
|
cpu_usage = {'user' => 0, 'sys' => 0, 'idle' => 0}
|
|
27
27
|
processes = []
|
|
28
28
|
|
|
29
|
-
if
|
|
29
|
+
if is_linux?
|
|
30
30
|
`top -b -n1 > /tmp/top.out`
|
|
31
31
|
else
|
|
32
32
|
`top -l 1 > /tmp/top.out`
|
|
@@ -36,15 +36,22 @@ class Heartbeat
|
|
|
36
36
|
counter = 0; proc_count = 0
|
|
37
37
|
File.open("/tmp/top.out", "r") do |infile|
|
|
38
38
|
while (line = infile.gets)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
if is_linux?
|
|
40
|
+
processes(procs, line) if line.include?('Task')
|
|
41
|
+
load_averages(load_avg, line) if line.include?('load average')
|
|
42
|
+
cpu_usages(cpu_usage, line) if line.include?('Cpu')
|
|
43
|
+
proc_count = counter + 1 if line.include?('PID') and line.include?('COMMAND')
|
|
44
|
+
else
|
|
45
|
+
processes(procs, line) if line.include?('Processes')
|
|
46
|
+
load_averages(load_avg, line) if line.include?('Load Avg')
|
|
47
|
+
cpu_usages(cpu_usage, line) if line.include?('CPU usage')
|
|
48
|
+
proc_count = counter + 1 if line.include?('PID') and line.include?('COMMAND')
|
|
49
|
+
end
|
|
43
50
|
process(processes, line) if proc_count > 0 and counter >= proc_count
|
|
44
51
|
counter += 1
|
|
45
52
|
end
|
|
46
53
|
end
|
|
47
|
-
|
|
54
|
+
|
|
48
55
|
options = {
|
|
49
56
|
:body => {
|
|
50
57
|
:heartbeat => {
|
|
@@ -61,10 +68,10 @@ class Heartbeat
|
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
71
|
+
#puts procs.inspect
|
|
72
|
+
#puts load_avg.inspect
|
|
73
|
+
#puts cpu_usage.inspect
|
|
74
|
+
#puts processes.inspect
|
|
68
75
|
|
|
69
76
|
pp Heartbeat.post('/heartbeat', options)
|
|
70
77
|
else
|
|
@@ -74,20 +81,26 @@ class Heartbeat
|
|
|
74
81
|
|
|
75
82
|
def self.processes(procs, str)
|
|
76
83
|
proc = str.split(':')
|
|
77
|
-
if proc and proc[0]
|
|
84
|
+
if proc and proc[0]
|
|
78
85
|
proc[1].split(',').each do |pr|
|
|
79
86
|
procs['total'] = pr.split(' ')[0].strip.to_i if pr.include?('total')
|
|
80
87
|
procs['running'] = pr.split(' ')[0].strip.to_i if pr.include?('running')
|
|
81
88
|
procs['stuck'] = pr.split(' ')[0].strip.to_i if pr.include?('stuck')
|
|
82
89
|
procs['sleeping'] = pr.split(' ')[0].strip.to_i if pr.include?('sleeping')
|
|
83
90
|
procs['threads'] = pr.split(' ')[0].strip.to_i if pr.include?('threads')
|
|
91
|
+
procs['stopped'] = pr.split(' ')[0].strip.to_i if pr.include?('stopped')
|
|
92
|
+
procs['zombie'] = pr.split(' ')[0].strip.to_i if pr.include?('zombie')
|
|
84
93
|
end
|
|
85
94
|
end
|
|
86
95
|
end
|
|
87
96
|
|
|
88
97
|
def self.load_averages(load_avg, str)
|
|
89
|
-
|
|
90
|
-
|
|
98
|
+
if is_linux?
|
|
99
|
+
avg = str.split('load average:')
|
|
100
|
+
else
|
|
101
|
+
avg = str.split(':')
|
|
102
|
+
end
|
|
103
|
+
if avg and avg[0]
|
|
91
104
|
avg[1].split(',').each do |a|
|
|
92
105
|
load_avg << a.strip.to_f
|
|
93
106
|
end
|
|
@@ -96,11 +109,17 @@ class Heartbeat
|
|
|
96
109
|
|
|
97
110
|
def self.cpu_usages(cpu_usage, str)
|
|
98
111
|
cpu = str.split(':')
|
|
99
|
-
if cpu and cpu[0]
|
|
112
|
+
if cpu and cpu[0]
|
|
100
113
|
cpu[1].split(',').each do |cp|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
114
|
+
if is_linux?
|
|
115
|
+
cpu_usage['us'] = cp.split(' ')[0].strip.to_f if cp.include?('us')
|
|
116
|
+
cpu_usage['sy'] = cp.split(' ')[0].strip.to_f if cp.include?('sy')
|
|
117
|
+
cpu_usage['id'] = cp.split(' ')[0].strip.to_f if cp.include?('id')
|
|
118
|
+
else
|
|
119
|
+
cpu_usage['user'] = cp.split(' ')[0].strip.to_f if cp.include?('user')
|
|
120
|
+
cpu_usage['sys'] = cp.split(' ')[0].strip.to_f if cp.include?('sys')
|
|
121
|
+
cpu_usage['idle'] = cp.split(' ')[0].strip.to_f if cp.include?('idle')
|
|
122
|
+
end
|
|
104
123
|
end
|
|
105
124
|
end
|
|
106
125
|
end
|
|
@@ -108,7 +127,11 @@ class Heartbeat
|
|
|
108
127
|
def self.process(processes, line)
|
|
109
128
|
procs = line.split(' ')
|
|
110
129
|
if procs and procs.size > 0
|
|
111
|
-
|
|
130
|
+
if is_linux?
|
|
131
|
+
processes << {'pid' => procs[0].strip.to_i, 'command' => procs[11].strip, 'cpu' => procs[8].strip.to_f} # debian
|
|
132
|
+
else
|
|
133
|
+
processes << {'pid' => procs[0].strip.to_i, 'command' => procs[1].strip, 'cpu' => procs[2].strip.to_f}
|
|
134
|
+
end
|
|
112
135
|
end
|
|
113
136
|
end
|
|
114
137
|
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:
|
|
4
|
+
hash: 21
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 2
|
|
9
|
-
-
|
|
10
|
-
version: 0.2.
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.2.1
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Oliver Kiessler
|