Sha256: 8e8daf7ede7612687443b4584ae312078f5517997e42bd535574d5aedc7d314b
Contents?: true
Size: 1.07 KB
Versions: 1
Compression:
Stored size: 1.07 KB
Contents
require 'rubygems' gem 'httparty' require 'httparty' require 'logger' require "sys/cpu" rescue nil require 'pp' class Heartbeat include Sys include HTTParty base_uri 'http://heartbeat-server.herokuapp.com' def self.is_mac? RUBY_PLATFORM.downcase.include?("darwin") end def self.is_linux? RUBY_PLATFORM.downcase.include?("linux") end def self.log Logger.new('/tmp/heartbeat.log') end def self.create(apikey) cpu = 0; load_average = 0; memory_used = 0; memory_free = 0 if self.is_mac? load_average = CPU.load_avg.first elsif self.is_linux? cpus = `iostat -c`.split cpu = 100 - cpus.last.to_i end options = { :body => { :heartbeat => { :apikey => apikey, :host => `hostname`.chomp, :timestamp => Time.now.to_i, :values => { :cpu => cpu, :load_average => load_average, :memory_used => memory_used, :memory_free => memory_free } } } } pp Heartbeat.post('/heartbeat', options) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
heartbeat-client-0.1.4 | lib/heartbeat-client.rb |