Class: CloudMonitorAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_monitor_agent.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, token, intervel) ⇒ CloudMonitorAgent

Returns a new instance of CloudMonitorAgent.



7
8
9
10
11
# File 'lib/cloud_monitor_agent.rb', line 7

def initialize(url, token, intervel)  
  @url = url
  @token = token
  @intervel = intervel  
end

Instance Method Details

#api_urlObject



13
14
15
# File 'lib/cloud_monitor_agent.rb', line 13

def api_url 
  @url
end

#delayObject



21
22
23
# File 'lib/cloud_monitor_agent.rb', line 21

def delay 
  @intervel
end

#getPayloadObject



25
26
27
28
29
# 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_reportObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cloud_monitor_agent.rb', line 31

def send_report 
  while true
    payload = self.getPayload 
    uri = URI('http://localhost:9292/api/v1/push_info')
    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
    sleep @intervel
  end
end

#tokenObject



17
18
19
# File 'lib/cloud_monitor_agent.rb', line 17

def token 
  @token
end