Class: ManageEngine::APMAgent
- Inherits:
-
Object
- Object
- ManageEngine::APMAgent
- Defined in:
- lib/agent/server/am_agent.rb
Instance Method Summary collapse
- #doCollect ⇒ Object
- #doConnect ⇒ Object
- #doDispatcherActions ⇒ Object
-
#initialize ⇒ APMAgent
constructor
A new instance of APMAgent.
- #startConnect(uri, data) ⇒ Object
Constructor Details
#initialize ⇒ APMAgent
Returns a new instance of APMAgent.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/agent/server/am_agent.rb', line 8 def initialize @obj = ManageEngine::APMObjectHolder.instance @obj.log.debug "Agent Initialization - START" doConnect if !@obj.shutdown && @obj.agent_initialized @obj.log.info "Agent Initialization - DONE" @obj.instrumenter.doSubscribe doDispatcherActions doCollect puts "ManageEngine APM Ruby Agent Started" else @obj.log.info "Agent Initialization Failed - Going to shutdown" @obj.instrumenter.doSubscribe @obj.shutdownagent end end |
Instance Method Details
#doCollect ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/agent/server/am_agent.rb', line 69 def doCollect @obj.log.info "[doCollect] Starts - Wait time : #{@obj.config.connect_interval} seconds " begin ManageEngine::APMWorker.getInstance.start rescue Exception=>e @obj.log.logException "[doCollect] Exception during worker startup #{e.message}",e @obj.shutdown=true end end |
#doConnect ⇒ Object
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 60 61 62 63 64 65 66 |
# File 'lib/agent/server/am_agent.rb', line 28 def doConnect begin if @obj.shutdown @obj.log.info "[ Problem in Agent Startup ]" else agentInfo = @obj.config.getAgentInfo resp = nil if @obj.config.alreadyconnected @obj.log.debug "[doConnect] Already Connected - Make Contact - Instance id = #{@obj.config.instance_id}" resp = startConnect "?instance_id="+@obj.config.instance_id,agentInfo else @obj.log.debug "[doConnect] Going to connect - New " resp = startConnect "",agentInfo if resp.has_key?("instance-info") aData = resp["instance-info"] aData["agent.id"]=aData.delete("instanceid") aData["agent.enabled"]=true @obj.config.updateAgentInfoFile(aData) @obj.log.debug "[doConnect] Connected - InstanceID : #{@obj.config.instance_id}" else @obj.log.info "[doConnect] [ Problem in connecting server] [ Going to shutdown ]" @obj.shutdown=true end end if resp==nil @obj.log.info "[doConnect] [ Error in Response while connecting Server . [ Going to shutdown ]" @obj.shutdown= true end if(!@obj.shutdown) @obj.agent_initialized=true end end rescue Exception=>e @obj.shutdown = true @obj.log.logException "[doConnect] Exception while connecting server. [ Going to shutdown ] ",e end end |
#doDispatcherActions ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/agent/server/am_agent.rb', line 84 def doDispatcherActions case @obj.config.app_dispatcher when 'passenger' #starting a new process PhusionPassenger.on_event(:starting_worker_process) do |forked| if forked @obj.log.info "starting_worker_process : Process ID :#{Process.pid} : Creating new apm worker" doCollect else doCollect @obj.log.info "starting_worker_process : Conservative Process ID :#{Process.pid} - No new worker" end end # shutting down a process. PhusionPassenger.on_event(:stopping_worker_process) do ManageEngine::APMWorker.getInstance.stop @obj.log.info "stopping_worker_process :Process ID :#{Process.pid} ----> #$$ " end else#case end#case end |
#startConnect(uri, data) ⇒ Object
80 81 82 |
# File 'lib/agent/server/am_agent.rb', line 80 def startConnect uri,data resp = @obj.connector.post @obj.constants.connect_uri+uri,data end |