lib/heartbeat-client.rb in heartbeat-client-0.3.0 vs lib/heartbeat-client.rb in heartbeat-client-0.3.1

- old
+ new

@@ -12,29 +12,37 @@ def self.is_linux? RUBY_PLATFORM.downcase.include?("linux") end + def self.log=(logger) + @@log = logger + end + def self.log - Logger.new('/tmp/heartbeat.log') + @@log end - + def self.create(apikey, endpoint, name = nil) + log.info("#create - Collecting data...") + procs = {'total' => 0, 'running' => 0, 'stuck' => 0, 'sleeping' => 0, 'threads' => 0, 'stopped' => 0, 'zombie' => 0} load_avg = [] cpu_usage = {'user' => 0, 'sys' => 0, 'idle' => 0} processes = [] memory = {'free' => 0, 'used' => 0} disks = {} swap = {'free' => 0, 'used' => 0} - + + log.debug("Dumping top output...") if is_linux? `top -b -n1 > /tmp/top.out` else `top -l 1 > /tmp/top.out` end - + + log.debug("Dumping df output...") `df -m > /tmp/dfm.out` if File.exists?('/tmp/top.out') counter = 0; proc_count = 0 File.open("/tmp/top.out", "r") do |infile| @@ -85,13 +93,16 @@ :swap => swap } } } } - - Heartbeat.post(endpoint + '/heartbeat', options) + + log.info("#create - Sending data to endpoint...") + res = Heartbeat.post(endpoint + '/heartbeat', options) + log.debug("Response: #{res.response.inspect}") if res + log.info("Finished iteration.") else - put "No top output found." + log.error "No top output found." end end def self.processes(procs, str) proc = str.split(':')