Top Level Namespace

Defined Under Namespace

Modules: ManageEngine Classes: Class

Instance Method Summary collapse

Instance Method Details

#me_apm_injector(s, result) ⇒ Object



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/agent/server/instrument/am_apm.rb', line 23

def me_apm_injector(s,result)
  begin
    if(ManageEngine::APMObjectHolder.instance.config.include_packages.index(s.name)!=nil)
    ms =s.instance_methods(false)
    cms = s.methods(false)
    begin
      ms.each do |m|
      if( m.to_s.index("APMTEST"))
        return;
      end
      end
      cms.each do |m|
      if( m.to_s.index("APMTEST"))
        return;
      end
      end
    rescue Exception=>e
      return;
    end
    ManageEngine::APMObjectHolder.instance.log.debug "Injection Method : #{ms} "
    ManageEngine::APMObjectHolder.instance.log.debug "Injection Class Method : #{cms} "
    ms.each do |m|
    mn = m.to_s
    #ManageEngine::APMObjectHolder.instance.log.info "ManageEngine Monitor Method : #{s.name} # #{m.to_s}"
    omn = "APMTEST"+mn+"APMTEST"
    s.class_eval  %{
      alias_method :#{omn}, :#{mn}
    def #{mn} *args, &block
      begin
      ActiveSupport::Notifications.instrument("apm.methodstart", {:method=>"#{mn}",:args=>args})
      res = #{omn} *args, &block
      ActiveSupport::Notifications.instrument("apm.methodend", {:method=>"#{mn}",:args=>args})
      return res
      rescue Exception => exe
      puts "error in calling method"
      raise exe
      ensure
      end
      end
    }
    end#do
    default_methods = Array.new
    default_methods.push("_helpers");
    default_methods.push("middleware_stack");
    default_methods.push("helpers_path");
    default_methods.push("_wrapper_options");
    cms.each do |m|
    if(default_methods.index(m.to_s)==nil)
      mn = m.to_s
      #ManageEngine::APMObjectHolder.instance.log.debug "ManageEngine Monitor Singleton Method : #{s.name} ---> #{m.to_s}"
      omn = "APMTEST"+mn+"APMTEST"
      s.instance_eval  %{
        class << self
          alias_method :#{omn}, :#{mn}
        end
        def self.#{mn} *args, &block
        begin
          ActiveSupport::Notifications.instrument("apm.methodstart", {:method=>"#{mn}",:args=>args})
          res = #{omn} *args, &block
          ActiveSupport::Notifications.instrument("apm.methodend", {:method=>"#{mn}",:args=>args})
          return res
        rescue Exception=>exe
          puts "Instrument : error in calling class method"
        raise exe
        ensure
        end
        end
      }
    end
    end#do
  end#if
  rescue Exception=>e
    puts "Exception in instrument : #{e}"
  ensure
  end
end