Class: CloudMonitorAgent
- Inherits:
-
Object
- Object
- CloudMonitorAgent
- Defined in:
- lib/cloud_monitor_agent.rb
Instance Method Summary collapse
- #api_url ⇒ Object
- #delay ⇒ Object
- #getPayload ⇒ Object
-
#initialize(url, token, intervel) ⇒ CloudMonitorAgent
constructor
A new instance of CloudMonitorAgent.
- #send_report ⇒ Object
- #token ⇒ Object
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_url ⇒ Object
13 14 15 |
# File 'lib/cloud_monitor_agent.rb', line 13 def api_url @url end |
#delay ⇒ Object
21 22 23 |
# File 'lib/cloud_monitor_agent.rb', line 21 def delay @intervel end |
#getPayload ⇒ Object
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_report ⇒ Object
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 |
#token ⇒ Object
17 18 19 |
# File 'lib/cloud_monitor_agent.rb', line 17 def token @token end |