class CloudMonitorAgent

Public Class Methods

new(url, token, intervel) click to toggle source
# File lib/cloud_monitor_agent.rb, line 7
def initialize(url, token, intervel)  
  @url = url
  @token = token
  @intervel = intervel  
end

Public Instance Methods

api_url() click to toggle source
# File lib/cloud_monitor_agent.rb, line 13
def api_url 
  @url
end
delay() click to toggle source
# File lib/cloud_monitor_agent.rb, line 21
def delay 
  @intervel
end
getPayload() click to toggle source
# File lib/cloud_monitor_agent.rb, line 25
def getPayload  
  usw =  Usagewatch
  payload = {:token => self.token, :cpu_used => usw.uw_cpuused, :disk_used => usw.uw_diskused_perc, :mem_used => usw.uw_memused, :bandwidth_up => usw.uw_bandtx,
              :bandwidth_down => usw.uw_bandrx, :top_process_cpu => usw.uw_cputop, :top_process_memory => usw.uw_memtop};
end
send_report() click to toggle source
# File lib/cloud_monitor_agent.rb, line 31
def send_report 
  while true
    payload = self.getPayload 
    uri = URI(self.api_url)
    req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
    req.body = payload.to_json
    res = Net::HTTP.start(uri.hostname, uri.port) do |http|
      http.request(req)
    end
    p res
    sleep @intervel
  end
end
token() click to toggle source
# File lib/cloud_monitor_agent.rb, line 17
def token 
  @token
end