Class: Cloudscale::Monitor::Init
- Inherits:
-
Object
- Object
- Cloudscale::Monitor::Init
- Defined in:
- lib/cloudscale/monitor/agent/init.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#log ⇒ Object
Returns the value of attribute log.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
-
#initialize(token) ⇒ Init
constructor
A new instance of Init.
Constructor Details
#initialize(token) ⇒ Init
Returns a new instance of Init.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cloudscale/monitor/agent/init.rb', line 19 def initialize(token) @log = Logger.new(STDOUT) @server = Socket.gethostname @client = RestClientWrapper.instance @registry = Monitor::Registry.instance puts " " puts "Running preflight verification for cloudscale monitoring agent" if (@registry.stored_agent == nil) raise "You did not provide any valid Agent file under /store/agent/agent.store." end agent = client.searchOne('agents', 'findByAgentId', { :agentId => @registry.stored_agent["agentId"] }) if (agent == nil) raise "No agent registered yet. It is not allowed to connect this agent instance to cloudscale monitoring." end if (@registry.stored_agent_instance != nil) agent_instance = client.searchOne('agentInstances', 'findByAgentInstanceId', { :id => @registry.stored_agent_instance["agentInstanceId"] }) end if (agent_instance == nil) puts " No Instance of this agent was started previously, starting cloudscale monitoring agent for the first, registering..." agent_instance_settings = Monitor::Settings.new(15, 0, 1500, 5) agent_instance = Monitor::AgentInstance.new(RestClientWrapper.load_entity_ref(agent)["href"], @registry.agent_instance_id, token, server, agent_instance_settings, Time.now.to_i * 1000) client.post('agentInstances', agent_instance) Constants::AgentInstance.create(agent_instance.to_h) else puts " Instance has been started previously, loading settings and existing data... \n\n" agent_instance["lastInitialization"] = Time.now.to_i * 1000 client.patch('agentInstances', RestClientWrapper.load_entity_id(agent_instance), agent_instance) end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
17 18 19 |
# File 'lib/cloudscale/monitor/agent/init.rb', line 17 def client @client end |
#log ⇒ Object
Returns the value of attribute log.
17 18 19 |
# File 'lib/cloudscale/monitor/agent/init.rb', line 17 def log @log end |
#server ⇒ Object
Returns the value of attribute server.
17 18 19 |
# File 'lib/cloudscale/monitor/agent/init.rb', line 17 def server @server end |