lib/heartbeat-client.rb in heartbeat-client-0.2.1 vs lib/heartbeat-client.rb in heartbeat-client-0.2.2

- old
+ new

@@ -71,11 +71,11 @@ #puts procs.inspect #puts load_avg.inspect #puts cpu_usage.inspect #puts processes.inspect - pp Heartbeat.post('/heartbeat', options) + Heartbeat.post('/heartbeat', options) else put "No top output found." end end @@ -93,15 +93,11 @@ end end end def self.load_averages(load_avg, str) - if is_linux? - avg = str.split('load average:') - else - avg = str.split(':') - end + avg = str.split(is_linux? ? 'load average:' : ':') if avg and avg[0] avg[1].split(',').each do |a| load_avg << a.strip.to_f end end @@ -109,29 +105,19 @@ def self.cpu_usages(cpu_usage, str) cpu = str.split(':') if cpu and cpu[0] cpu[1].split(',').each do |cp| - if is_linux? - cpu_usage['us'] = cp.split(' ')[0].strip.to_f if cp.include?('us') - cpu_usage['sy'] = cp.split(' ')[0].strip.to_f if cp.include?('sy') - cpu_usage['id'] = cp.split(' ')[0].strip.to_f if cp.include?('id') - else - cpu_usage['user'] = cp.split(' ')[0].strip.to_f if cp.include?('user') - cpu_usage['sys'] = cp.split(' ')[0].strip.to_f if cp.include?('sys') - cpu_usage['idle'] = cp.split(' ')[0].strip.to_f if cp.include?('idle') - end + cpu_usage['user'] = cp.split(' ')[0].strip.to_f if cp.include?(is_linux? ? 'us' : 'user') + cpu_usage['sys'] = cp.split(' ')[0].strip.to_f if cp.include?(is_linux? ? 'sy' : 'sys') + cpu_usage['idle'] = cp.split(' ')[0].strip.to_f if cp.include?(is_linux? ? 'id' : 'idle') end end end def self.process(processes, line) procs = line.split(' ') if procs and procs.size > 0 - if is_linux? - processes << {'pid' => procs[0].strip.to_i, 'command' => procs[11].strip, 'cpu' => procs[8].strip.to_f} # debian - else - processes << {'pid' => procs[0].strip.to_i, 'command' => procs[1].strip, 'cpu' => procs[2].strip.to_f} - end + processes << (is_linux? ? procs[11].strip : procs[1].strip) end end end