apminsight 1.0.1 → 1.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/apm-agent.gemspec +64 -0
- data/conf/apminsight.conf +15 -24
- data/lib/agent/am_objectholder.rb +25 -19
- data/lib/agent/api/custom_tracker.rb +79 -0
- data/lib/agent/configuration/am_configuration.rb +249 -37
- data/lib/agent/handler/custom_api_handler.rb +40 -0
- data/lib/agent/handler/sequence_book.rb +118 -0
- data/lib/agent/handler/tracker_handler.rb +58 -0
- data/lib/agent/logging/am_logger.rb +13 -9
- data/lib/agent/metrics/am_metricsformatter.rb +117 -59
- data/lib/agent/metrics/am_metricsparser.rb +195 -468
- data/lib/agent/metrics/am_metricstore.rb +7 -6
- data/lib/agent/metrics/exception_record.rb +24 -0
- data/lib/agent/server/am_agent.rb +42 -17
- data/lib/agent/server/am_connector.rb +65 -21
- data/lib/agent/server/instrument/action_view.rb +64 -0
- data/lib/agent/server/instrument/active_record.rb +52 -0
- data/lib/agent/server/instrument/am_apm.rb +107 -97
- data/lib/agent/server/instrument/am_instrumenter.rb +54 -42
- data/lib/agent/server/instrument/environment.rb +42 -0
- data/lib/agent/server/instrument/rails.rb +56 -0
- data/lib/agent/server/instrument/sinatra.rb +97 -0
- data/lib/agent/server/worker/am_worker.rb +93 -49
- data/lib/agent/trackers/database_tracker.rb +107 -0
- data/lib/agent/trackers/default_tracker.rb +57 -0
- data/lib/agent/trackers/root_tracker.rb +43 -0
- data/lib/agent/util/am_constants.rb +46 -3
- data/lib/agent/util/am_util.rb +64 -1
- data/lib/agent/util/transaction_util.rb +35 -0
- data/lib/agent/version.rb +13 -0
- data/lib/apminsight.rb +4 -1
- metadata +114 -76
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.8.2
|
data/apm-agent.gemspec
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
require './lib/agent/version'
|
7
|
+
require 'date'
|
8
|
+
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
s.name = "apminsight"
|
11
|
+
s.version = ManageEngine::APMInsight::VERSION
|
12
|
+
|
13
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
14
|
+
s.authors = ["Adithyan P"]
|
15
|
+
s.date = Date.today.to_s
|
16
|
+
s.description = "ManageEngine Applications Manager APM Insight gives you end-to-end web-transaction awareness of Rails applications enabling you to isolate performance issues and resolve them quickly. To monitor Rails application performance, download and deploy Applications Manager's Ruby agent(apminsight) in your Application Server. This agent allows you to send information about Ruby applications. You can install APM Insight Agent via Rubygems or download it from Applications Manager's website: http://www.manageengine.com/products/applications_manager/apm-insight-agent-installation.html"
|
17
|
+
|
18
|
+
s.email = "apm-insight@zohocorp.com"
|
19
|
+
s.extra_rdoc_files = [
|
20
|
+
"LICENSE.txt",
|
21
|
+
"README.rdoc"
|
22
|
+
]
|
23
|
+
|
24
|
+
s.files = Dir[
|
25
|
+
'LICENSE.txt',
|
26
|
+
'README.rdoc',
|
27
|
+
'Rakefile',
|
28
|
+
'VERSION',
|
29
|
+
'apm-agent.gemspec',
|
30
|
+
'conf/apminsight.conf',
|
31
|
+
'lib/apminsight.rb',
|
32
|
+
'lib/agent/**/*'
|
33
|
+
]
|
34
|
+
|
35
|
+
s.homepage = "http://www.manageengine.com/products/applications_manager/ruby-webtransaction-monitoring.html"
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = "1.8.15"
|
38
|
+
s.summary = "ManageEngine Applications Manager APM Insight gives you end-to-end web-transaction awareness of Rails applications enabling you to isolate performance issues and resolve them quickly. To monitor Rails application performance, download and deploy Applications Manager's Ruby agent(apminsight) in your Application Server. This agent allows you to send information about Ruby applications. You can install APM Insight Agent via Rubygems or download it from Applications Manager's website : http://www.manageengine.com/products/applications_manager/apm-insight-agent-installation.html"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
46
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
47
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rails>, [">= 3.0.0"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
51
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
53
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
54
|
+
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
60
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
data/conf/apminsight.conf
CHANGED
@@ -9,6 +9,9 @@
|
|
9
9
|
#
|
10
10
|
#All the configuration options defaults to factory configuration if commented or not supported values
|
11
11
|
|
12
|
+
#License key of your Applications Manager.
|
13
|
+
license.key=
|
14
|
+
|
12
15
|
#Logical name of your application.Say for example you have "Order Processing" applications running in
|
13
16
|
#10 instances of Tomcat server. Specify the name as "Order Processing" for the name in all the 10
|
14
17
|
#instances while deploying the agent. Applications Manager will group the data from 10 instances of
|
@@ -16,16 +19,9 @@
|
|
16
19
|
application.name=My Application
|
17
20
|
|
18
21
|
#Name of the host or IPV4 address where the Applications Manager is installed and running.
|
22
|
+
#For Enterprise Edition of Applications Manager provide Managed Server's host or IPV4 address
|
19
23
|
#[Mandatory]
|
20
|
-
apm.host=localhost
|
21
|
-
|
22
|
-
#Whether the data to the Applications Manager should be sent through HTTPS protocol.
|
23
|
-
#default value: false
|
24
|
-
apm.protocol.https=false
|
25
|
-
|
26
|
-
#HTTP/HTTPS Port of the Applications Manager.(Specify HTTPS port if apm.protocol.https is true)
|
27
|
-
#[Mandatory]
|
28
|
-
apm.port=9090
|
24
|
+
apm.host=http://localhost:9090/
|
29
25
|
|
30
26
|
#APM Insight agent communicates to the Applications Manager through the HTTP/HTTPS protocol.
|
31
27
|
#Specify Proxy server configuration when there is a proxy server between APM Insight agent and
|
@@ -64,17 +60,19 @@ apdex.threshold=0.5
|
|
64
60
|
sql.capture.enabled=true
|
65
61
|
|
66
62
|
#Whether the transaction trace is enabled or not. Setting this value to true will send the trace of the
|
67
|
-
#slow transaction.
|
63
|
+
#slow web transaction.
|
68
64
|
#default value: true
|
69
65
|
transaction.trace.enabled=true
|
70
66
|
|
71
|
-
#Threshold to construct the trace for slow transactions. Transaction Traces violating this threshold will be
|
67
|
+
#Threshold to construct the trace for slow web transactions. Transaction Traces violating this threshold will be
|
72
68
|
#collected and sent to the server. Used to analyze and troubleshoot the Transaction by the user.
|
73
69
|
#default value: 2 (second)
|
74
70
|
transaction.trace.threshold=2
|
75
71
|
|
76
|
-
#
|
77
|
-
#
|
72
|
+
#Enabling this option will parametrize all SQL Queries in Slow Transaction Traces (if sql.capture.enabled
|
73
|
+
#set to true & transaction.trace.enabled set to true). Disabling this option will give you the real query
|
74
|
+
#with actual parameters. It is recommended to enable this option if there are queries getting executed
|
75
|
+
#using confidential parameters like credit card number, passwords, etc.
|
78
76
|
#default value: true
|
79
77
|
transaction.trace.sql.parametrize=true
|
80
78
|
|
@@ -83,23 +81,16 @@ transaction.trace.sql.parametrize=true
|
|
83
81
|
#default value: 3 (second)
|
84
82
|
transaction.trace.sql.stacktrace.threshold=3
|
85
83
|
|
86
|
-
#
|
87
|
-
|
88
|
-
#starts with com.test.customimpl. It is best if this is enabled only in the testing/staging environment.
|
89
|
-
#Use comma(,) to separate multiple entries.
|
90
|
-
#include.packages=
|
91
|
-
|
92
|
-
#Sampling counter.Say for example when you specify the value as 20, agent will track one in 20 transactions.
|
93
|
-
#default value: 1 (request)
|
94
|
-
transaction.tracking.request.interval=1
|
84
|
+
#Stop listening transactions with specified URL pattern.
|
85
|
+
transaction.skip.listening=*.css, *.js, *.gif, *.jpg, *.jpeg, *.bmp, *.png, *.ico
|
95
86
|
|
96
87
|
#Directory where agent logs information separately.
|
97
88
|
#Defaults to the directory where apminsight-javaagent.jar is installed.
|
98
|
-
#Use
|
89
|
+
#Use forward slash(/) as path separator.
|
99
90
|
#apminsight.log.dir=./apminsight/logs
|
100
91
|
|
101
92
|
#The log level at which the APM Insight agent should record logging
|
102
93
|
#information. The levels are SEVERE, WARNING, INFO, FINE in the order
|
103
94
|
#respectively. Defaults to the level INFO if commented or mentioned
|
104
95
|
#incorrectly.
|
105
|
-
apminsight.log.level=INFO
|
96
|
+
apminsight.log.level=INFO
|
@@ -9,32 +9,38 @@ require "agent/metrics/am_metricscollector"
|
|
9
9
|
require "agent/metrics/am_metricstore"
|
10
10
|
require "agent/metrics/am_metricsformatter"
|
11
11
|
require "agent/metrics/am_metricsparser"
|
12
|
-
require "agent/
|
12
|
+
require "agent/util/transaction_util"
|
13
13
|
|
14
14
|
module ManageEngine
|
15
15
|
|
16
16
|
class APMObjectHolder
|
17
|
-
attr_reader :config,:log,:util,:constants,:shutdown,:connector,:agent,:collector
|
18
|
-
attr_accessor :shutdown,:agent_initialized,:last_dispatch_time,:
|
17
|
+
attr_reader :config,:log,:util,:constants,:shutdown,:connector,:agent,:collector, :txn_util
|
18
|
+
attr_accessor :shutdown,:agent_initialized,:last_dispatch_time,:store,:formatter,:parser
|
19
19
|
@@objects = nil
|
20
20
|
#Don't Change the Order of Initialize
|
21
21
|
def initializeObjects
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
22
|
+
begin
|
23
|
+
@agent_initialized = false
|
24
|
+
@shutdown = false
|
25
|
+
@constants = ManageEngine::APMConstants.new
|
26
|
+
@log = ManageEngine::APMLogger.new
|
27
|
+
@util = ManageEngine::APMUtil.new
|
28
|
+
@util.setLogger @log
|
29
|
+
@config = ManageEngine::APMConfig.new
|
30
|
+
@connector = ManageEngine::APMConnector.new
|
31
|
+
@store = ManageEngine::APMMetricsStore.new
|
32
|
+
@collector = ManageEngine::APMMetricsCollector.new
|
33
|
+
@txn_util = ManageEngine::TransactionUtil.new
|
34
|
+
@formatter = ManageEngine::APMMetricsFormatter.new
|
35
|
+
@parser = ManageEngine::APMMetricsParser.new
|
36
|
+
@agent = ManageEngine::APMAgent.new
|
37
|
+
@last_dispatch_time = @@objects.util.currenttimemillis
|
38
|
+
@@objects.log.debug "[APMObjectHolder] [ All Objects Initialized ] "
|
39
|
+
rescue Exception => e
|
40
|
+
puts "Error initializing APM Insight Ruby agent. #{e.message}"
|
41
|
+
@shutdown = true
|
42
|
+
@agent_initialized = false
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
46
|
def self.instance
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'agent/handler/custom_api_handler'
|
2
|
+
|
3
|
+
module APMInsight
|
4
|
+
module API
|
5
|
+
module CustomTracker
|
6
|
+
|
7
|
+
def self.included clazz
|
8
|
+
clazz.extend CustomMethodTracker
|
9
|
+
end
|
10
|
+
|
11
|
+
module CustomMethodTracker
|
12
|
+
# @api public
|
13
|
+
def track_method(method_name)
|
14
|
+
|
15
|
+
# Check whether the method exists
|
16
|
+
return unless method_defined?(method_name) || private_method_defined?(method_name)
|
17
|
+
|
18
|
+
# Check whether the method is already instrumented
|
19
|
+
return if is_instrumented?(method_name)
|
20
|
+
|
21
|
+
# Injecting code into the class
|
22
|
+
class_eval(get_instrumentation_code(method_name), __FILE__, __LINE__)
|
23
|
+
|
24
|
+
# Setting alias to invoke agent methods
|
25
|
+
alias_method "original_#{method_name}", "#{method_name}"
|
26
|
+
alias_method "#{method_name}", "apminsight_#{method_name}"
|
27
|
+
|
28
|
+
# TODO: set visibility
|
29
|
+
# visibility = instance_method_visibility(self, method_name)
|
30
|
+
# send visibility, method_name
|
31
|
+
# send visibility, "apminsight_#{method_name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def is_instrumented?(method_name)
|
36
|
+
method_name = "apminsight_#{method_name}"
|
37
|
+
return method_defined?(method_name)
|
38
|
+
end
|
39
|
+
|
40
|
+
# TODO: Capture exception, attach tracker
|
41
|
+
# TODO: Create agent handler and call respective methods like in java agent
|
42
|
+
def get_instrumentation_code(method_name)
|
43
|
+
"def apminsight_#{method_name}(*args, &block)
|
44
|
+
tracker = ::APMInsight::API::CustomAPIHandler.invokeTracker \"\#{self.class.name}.#{method_name}\"
|
45
|
+
begin
|
46
|
+
original_#{method_name}(*args, &block)
|
47
|
+
rescue Exception=>e
|
48
|
+
if tracker != nil
|
49
|
+
tracker.setError e
|
50
|
+
end
|
51
|
+
raise e
|
52
|
+
ensure
|
53
|
+
::APMInsight::API::CustomAPIHandler.exitTracker tracker
|
54
|
+
end
|
55
|
+
end"
|
56
|
+
end
|
57
|
+
|
58
|
+
# def instance_method_visibility(klass, method_name)
|
59
|
+
# if klass.private_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym
|
60
|
+
# :private
|
61
|
+
# elsif klass.protected_instance_methods.map{|s|s.to_sym}.include? method_name.to_sym
|
62
|
+
# :protected
|
63
|
+
# else
|
64
|
+
# :public
|
65
|
+
# end
|
66
|
+
# end
|
67
|
+
end #CustomMethodTracker
|
68
|
+
|
69
|
+
def self.trackException(exception)
|
70
|
+
return unless exception != nil
|
71
|
+
|
72
|
+
# Check for active transaction
|
73
|
+
# Associate exception to current transaction
|
74
|
+
::APMInsight::API::CustomAPIHandler.track_exception(exception)
|
75
|
+
end
|
76
|
+
|
77
|
+
end #CustomTracker
|
78
|
+
end #API
|
79
|
+
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'json'
|
3
3
|
require 'socket'
|
4
|
-
require '
|
4
|
+
require 'net/http'
|
5
5
|
require 'agent/am_objectholder'
|
6
|
+
require 'agent/version'
|
6
7
|
|
7
8
|
module ManageEngine
|
8
9
|
class APMConfig
|
9
|
-
attr_reader :agenthost,:agentport,:instance_id,:alreadyconnected,:apmhost,:apmport
|
10
|
-
attr_reader :appname,:proxyneeded, :apdex_t, :trans_trace, :trans_trace_t, :sql_capture, :sql_capture_params, :sql_trace_t,:proxy_user,:proxy_pass
|
11
|
-
attr_reader :proxy_host,:proxy_port ,:is_secured, :logs_dir ,:connection_retry,:agent_enabled,:connect_interval,:db_operations,:
|
10
|
+
attr_reader :agenthost,:agentport,:instance_id,:alreadyconnected,:apmhost,:apmport,:license_key,:site24x7, :site24x7url, :hostType
|
11
|
+
attr_reader :appname,:proxyneeded, :apdex_t, :trans_trace, :trans_trace_t, :sql_capture, :sql_capture_params, :sql_trace_t,:proxy_user,:proxy_pass, :metric_overflow_t, :trace_overflow_t, :dbmetric_overflow_t
|
12
|
+
attr_reader :proxy_host,:proxy_port ,:is_secured, :logs_dir ,:connection_retry,:agent_enabled,:connect_interval,:db_operations,:txn_skip_listen, :url_merge_pattern
|
12
13
|
attr_accessor :app_db,:app_dispatcher,:lastupdatedtime
|
13
14
|
def initialize
|
14
15
|
@obj = ManageEngine::APMObjectHolder.instance
|
@@ -21,19 +22,31 @@ module ManageEngine
|
|
21
22
|
@instance_id = 0
|
22
23
|
@agent_enabled = false
|
23
24
|
@alreadyconnected = checkAgentInfo
|
25
|
+
@site24x7 = checkLicenseFile
|
26
|
+
if (@site24x7)
|
27
|
+
@site24x7url = @license_key.start_with?('eu_') ? @obj.constants.site24x7EUurl : @license_key.start_with?('cn_') ? @obj.constants.site24x7CNurl : @license_key.start_with?('au_') ? @obj.constants.site24x7AUurl : @license_key.start_with?('in_') ? @obj.constants.site24x7INurl : @obj.constants.site24x7USurl
|
28
|
+
end
|
24
29
|
@db_operations =["select","insert","update","delete"]
|
25
|
-
|
26
|
-
@
|
27
|
-
@obj.log.
|
28
|
-
@obj.log.
|
29
|
-
@obj.log.
|
30
|
-
@obj.log.
|
31
|
-
|
32
|
-
|
33
|
-
@
|
34
|
-
@obj.log.info "
|
35
|
-
|
36
|
-
@obj.log.
|
30
|
+
urlMergePattern
|
31
|
+
@hostType = getHostType
|
32
|
+
@obj.log.info "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
33
|
+
@obj.log.info "APP HOME #{File.absolute_path(".")} "
|
34
|
+
@obj.log.info "APP HOME #{Dir.pwd} "
|
35
|
+
@obj.log.info "Agent Version : #{ManageEngine::APMInsight::VERSION}"
|
36
|
+
#@obj.log.info "Configuration : "
|
37
|
+
#@obj.log.info "Hostname : #{@agenthost}"
|
38
|
+
@obj.log.info "Host Type: #{@hostType}"
|
39
|
+
@obj.log.info "Agent Already Connected : #{@alreadyconnected}"
|
40
|
+
@obj.log.info "Agent Enabled : #{@agent_enabled}"
|
41
|
+
@obj.log.info "Allowed DB Operations : #{@db_operations}"
|
42
|
+
# @config.each do|key,val|
|
43
|
+
# @obj.log.info "#{key} => #{val}"
|
44
|
+
# end
|
45
|
+
@obj.log.info "URL Merge Patterns"
|
46
|
+
@url_merge_pattern.each do |key, val|
|
47
|
+
@obj.log.info "#{key} => #{val}"
|
48
|
+
end
|
49
|
+
@obj.log.info "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
|
37
50
|
@app_db="dummydb"
|
38
51
|
@app_dispatcher = getDispatcher
|
39
52
|
@lastupdatedtime=File.mtime(@obj.constants.apm_conf).to_i
|
@@ -41,23 +54,27 @@ module ManageEngine
|
|
41
54
|
|
42
55
|
def configureFile
|
43
56
|
begin
|
44
|
-
gem_conf = Gem.loaded_specs[@obj.constants.apm_gem].full_gem_path
|
45
|
-
#gem_conf = File.join(gem_conf, 'lib')
|
46
|
-
gem_conf = File.join(gem_conf, 'conf')
|
47
|
-
gem_conf = File.join(gem_conf, 'apminsight.conf')
|
48
57
|
if(FileTest.exists?(@obj.constants.apm_conf))
|
49
58
|
#conf file exists in APPlication Home
|
50
|
-
@obj.log.debug "Config File
|
59
|
+
@obj.log.debug "Config File Exists. It is read from #{@obj.constants.apm_conf}"
|
51
60
|
@config = @obj.util.readProperties(@obj.constants.apm_conf)
|
52
61
|
else
|
62
|
+
gemSpecs = Gem.loaded_specs[@obj.constants.s247_apm_gem]
|
63
|
+
if (gemSpecs == nil)
|
64
|
+
gemSpecs = Gem.loaded_specs[@obj.constants.apm_gem]
|
65
|
+
end
|
66
|
+
gem_conf = gemSpecs.full_gem_path
|
67
|
+
#gem_conf = File.join(gem_conf, 'lib')
|
68
|
+
gem_conf = File.join(gem_conf, 'conf')
|
69
|
+
gem_conf = File.join(gem_conf, 'apminsight.conf')
|
53
70
|
#conf file not exists in APPlications Home. So 1. copy it for gem locations
|
54
71
|
if @obj.util.copyFiles gem_conf,@obj.constants.apm_conf
|
55
72
|
#copied sucessfully
|
56
|
-
@obj.log.
|
73
|
+
@obj.log.info "Config File copied to application home directory. It is read from #{@obj.constants.apm_conf}"
|
57
74
|
@config = @obj.util.readProperties(@obj.constants.apm_conf)
|
58
75
|
else
|
59
76
|
#Problem in copying, so reading props from Conf file in Gem Location
|
60
|
-
@obj.log.
|
77
|
+
@obj.log.warn "Config File not copied. It is read from #{gem_conf}"
|
61
78
|
@config = @obj.util.readProperties(gem_conf)
|
62
79
|
end
|
63
80
|
end
|
@@ -74,7 +91,17 @@ module ManageEngine
|
|
74
91
|
if FileTest.exists?(@obj.constants.agent_conf)
|
75
92
|
@obj.log.debug "Status : Agent Already Connected"
|
76
93
|
props = @obj.util.readProperties(@obj.constants.agent_conf)
|
77
|
-
|
94
|
+
instance_id = props["agent.id"]
|
95
|
+
|
96
|
+
if (instance_id == nil || instance_id == "")
|
97
|
+
# If instance id is not found or empty, it means the apminsight.info is being modified by user
|
98
|
+
# Ignore all its entry
|
99
|
+
@obj.log.warn "File: #{@obj.constants.agent_conf} is corrupted. Agent will continue ignoring these values."
|
100
|
+
return false
|
101
|
+
else
|
102
|
+
@instance_id = instance_id
|
103
|
+
end
|
104
|
+
|
78
105
|
@agent_enabled= @obj.util.getBooleanValue props["agent.enabled"]
|
79
106
|
true
|
80
107
|
else
|
@@ -83,6 +110,30 @@ module ManageEngine
|
|
83
110
|
end
|
84
111
|
end
|
85
112
|
|
113
|
+
def checkLicenseFile
|
114
|
+
if(@license_key != nil)
|
115
|
+
@obj.log.info "License key is not null. Connecting to site24x7"
|
116
|
+
@obj.constants.setLicenseKey @license_key
|
117
|
+
true
|
118
|
+
else
|
119
|
+
@obj.log.info "License key is null. Connecting to APPManager"
|
120
|
+
false
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
def urlMergePattern
|
126
|
+
@url_merge_pattern = Hash.new
|
127
|
+
begin
|
128
|
+
if (FileTest.exists?(@obj.constants.mergepattern_conf))
|
129
|
+
@url_merge_pattern=@obj.util.readProperties(@obj.constants.mergepattern_conf)
|
130
|
+
end
|
131
|
+
rescue Exception => e
|
132
|
+
@obj.log.info "[Exception] Problem in Reading Configuration File : \n File : #{@obj.constants.mergepattern_conf}"
|
133
|
+
@obj.log.logException "#{e.message}",e
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
86
137
|
def updateAgentInfoFile(props)
|
87
138
|
@instance_id = props["agent.id"]
|
88
139
|
@agent_enabled= @obj.util.getBooleanValue props["agent.enabled"]
|
@@ -102,18 +153,30 @@ module ManageEngine
|
|
102
153
|
@connection_retry = 0
|
103
154
|
@connect_interval = 60
|
104
155
|
@apdex_t=0.5
|
105
|
-
@
|
156
|
+
@txn_skip_listen=Array.new
|
106
157
|
@trans_trace_t=2
|
107
158
|
@sql_trace_t=3
|
159
|
+
@metric_overflow_t=250
|
160
|
+
@dbmetric_overflow_t=500
|
161
|
+
@trace_overflow_t=30
|
162
|
+
@site24x7url = @obj.constants.site24x7USurl #default agent communication URL
|
108
163
|
end
|
109
164
|
|
110
165
|
def assignConfig
|
111
166
|
initValues
|
112
167
|
@config.each do |key,value|
|
168
|
+
value = checkAndGetEnvValue(value)
|
113
169
|
case key
|
114
170
|
when "application.name" then @appname=value
|
171
|
+
if (ENV.has_key?('APM_APPLICATION_NAME'))
|
172
|
+
@appname = ENV['APM_APPLICATION_NAME']
|
173
|
+
end
|
115
174
|
when "apm.host" then @apmhost=value
|
116
175
|
when "apm.port" then @apmport=isInteger(@apmport,value)
|
176
|
+
when "license.key" then @license_key=value
|
177
|
+
if (@license_key.empty? && ENV.has_key?('S247_LICENSE_KEY'))
|
178
|
+
@license_key = ENV['S247_LICENSE_KEY']
|
179
|
+
end
|
117
180
|
when "behind.proxy" then @proxyneeded=@obj.util.getBooleanValue value
|
118
181
|
when "agent.server.port" then @agentport=isInteger(@agentport,value)
|
119
182
|
when "apdex.threshold" then @apdex_t=isFloat(@apdex_t,value)
|
@@ -123,24 +186,103 @@ module ManageEngine
|
|
123
186
|
when "transaction.trace.sql.parametrize" then @sql_capture_params=@obj.util.getBooleanValue value
|
124
187
|
when "transaction.trace.sql.stacktrace.threshold" then @sql_trace_t=isFloat(@sql_trace_t,value)
|
125
188
|
when "proxy.server.host" then @proxy_host=value
|
126
|
-
when "proxy.server.port" then @proxy_port=value
|
189
|
+
when "proxy.server.port" then @proxy_port=isInteger(@proxy_port,value)
|
127
190
|
when "proxy.auth.username" then @proxy_user=value
|
128
|
-
when "proxy.auth.password" then @proxy_pass
|
129
|
-
|
191
|
+
when "proxy.auth.password" then @proxy_pass=@obj.util.decrypt value, @license_key
|
192
|
+
if (@proxy_pass == nil)
|
193
|
+
@proxy_pass = value
|
194
|
+
end
|
195
|
+
when "apm.protocol.https" then @is_secured=@obj.util.getBooleanValue value
|
130
196
|
when "apminsight.log.dir" then @logs_dir=value
|
197
|
+
when "apminsight.log.level" then @obj.log.setLevel value
|
131
198
|
when "agent.connection.retry" then @connection_retry=value #Not in Conf - yet to come
|
132
|
-
|
133
|
-
|
199
|
+
when "agent.polling.interval" then @connect_interval=isInteger(@connect_interval, value)#Not in Conf - yet to come
|
200
|
+
when "transaction.skip.listening" then @txn_skip_listen=@obj.util.getArray value.gsub("\s", ""),","
|
201
|
+
when "metricstore.metric.bucket.size" then @metric_overflow_t = isInteger(@metric_overflow_t, value)
|
202
|
+
when "metricstore.dbmetric.bucket.size" then @dbmetric_overflow_t = isInteger(@dbmetric_overflow_t, value)
|
203
|
+
when "transaction.tracestore.size" then @trace_overflow_t = isInteger(@trace_overflow_t, value)
|
134
204
|
end
|
135
205
|
end
|
206
|
+
store_encrypted_data(@config)
|
207
|
+
end
|
208
|
+
|
209
|
+
#Checks whether the given value is Environment Variable
|
210
|
+
def checkAndGetEnvValue(data)
|
211
|
+
begin
|
212
|
+
value = "#{data}"[/\{(.*)\}/,1]
|
213
|
+
if (value != nil && ENV.has_key?(value))
|
214
|
+
return data.gsub(/\{.*\}/, ENV[value])
|
215
|
+
end
|
216
|
+
rescue Exception=>e
|
217
|
+
end
|
218
|
+
return data
|
136
219
|
end
|
137
220
|
|
221
|
+
def store_encrypted_data config
|
222
|
+
data = config["proxy.auth.password"]
|
223
|
+
if (data != nil && @obj.util.decrypt(data, @license_key) == nil) # checking whether data is already encrypted
|
224
|
+
begin
|
225
|
+
file_contents = ""
|
226
|
+
conf_file = File.open(@obj.constants.apm_conf, 'r')
|
227
|
+
conf_file.read.each_line do |line|
|
228
|
+
if line.start_with?("proxy.auth.password")
|
229
|
+
file_contents += "proxy.auth.password=" + @obj.util.encrypt(config["proxy.auth.password"], @license_key)
|
230
|
+
else
|
231
|
+
file_contents += line
|
232
|
+
end
|
233
|
+
#file_contents += "\n"
|
234
|
+
end #end of do read loop
|
235
|
+
conf_file.close
|
236
|
+
conf_file = File.open(@obj.constants.apm_conf, "w+")
|
237
|
+
conf_file.puts file_contents
|
238
|
+
conf_file.close
|
239
|
+
file_contents = nil # clearing memory
|
240
|
+
rescue Exception=>e
|
241
|
+
@obj.log.logException "Error while encrypting file", e
|
242
|
+
end
|
243
|
+
end # if already encrypted
|
244
|
+
end
|
245
|
+
|
246
|
+
def getHostType
|
247
|
+
begin
|
248
|
+
# Check for AWS environment
|
249
|
+
response = Net::HTTP.get_response(URI('http://169.254.169.254/latest/meta-data/'))
|
250
|
+
# url = URI.parse('http://169.254.169.254/latest/meta-data/')
|
251
|
+
# request = Net::HTTP::Get.new(url.path)
|
252
|
+
# response = Net::HTTP.start(url.host, url.port, :read_timeout => 2) {|http| http.request(request)}
|
253
|
+
if (response.kind_of? Net::HTTPOK)
|
254
|
+
@hostType = "AWS"
|
255
|
+
return @hostType
|
256
|
+
end
|
257
|
+
rescue Exception => e
|
258
|
+
end
|
259
|
+
|
260
|
+
begin
|
261
|
+
#Check for Azure environment
|
262
|
+
response = Net::HTTP.get_response(URI('http://169.254.169.254/metadata/v1/maintenance'))
|
263
|
+
# url = URI.parse('http://169.254.169.254/metadata/v1/maintenance')
|
264
|
+
# request = Net::HTTP::Get.new(url.path)
|
265
|
+
# response = Net::HTTP.start(url.host, url.port, :read_timeout => 2) {|http| http.request(request)}
|
266
|
+
if (response.kind_of? Net::HTTPOK)
|
267
|
+
@hostType = "AZURE"
|
268
|
+
return @hostType
|
269
|
+
end
|
270
|
+
rescue Exception => e
|
271
|
+
end
|
272
|
+
|
273
|
+
@hostType = nil
|
274
|
+
end
|
275
|
+
|
138
276
|
def getAgentInfo
|
139
277
|
data = Hash.new
|
140
278
|
agentdata = Hash.new
|
141
|
-
agentdata = {"application.type"=>"RUBY","application.name"=>@appname,"hostname"=>@agenthost,"port"=>@agentport,"agent.version"=>
|
279
|
+
agentdata = {"application.type"=>"RUBY","application.name"=>@appname,"hostname"=>@agenthost,"port"=>@agentport,"agent.version"=>ManageEngine::APMInsight::MAJOR_VERSION}
|
280
|
+
if (@hostType != nil)
|
281
|
+
agentdata["host.type"]=@hostType
|
282
|
+
end
|
142
283
|
data["agent_info"]=agentdata
|
143
284
|
data["environment"]=getEnvData
|
285
|
+
data["custom_config_info"]=getAgentConfigData
|
144
286
|
data
|
145
287
|
end
|
146
288
|
|
@@ -150,19 +292,49 @@ module ManageEngine
|
|
150
292
|
ENV.to_hash.each do |key, value|
|
151
293
|
env[key] = value
|
152
294
|
end
|
153
|
-
env["Application Path"]="#{Rails.root}"
|
295
|
+
#env["Application Path"]="#{Rails.root}"
|
154
296
|
rescue Exception=>e
|
155
297
|
end
|
156
298
|
env
|
157
299
|
end
|
158
300
|
|
301
|
+
def getAgentConfigData
|
302
|
+
agentconfig = Hash.new
|
303
|
+
agentconfig["last.modified.time"]=@lastupdatedtime*1000
|
304
|
+
agentconfig["apdex.threshold"]=@apdex_t
|
305
|
+
agentconfig["sql.capture.enabled"]=0
|
306
|
+
if @sql_capture
|
307
|
+
agentconfig["sql.capture.enabled"]=1
|
308
|
+
end
|
309
|
+
agentconfig["transaction.trace.enabled"]=0
|
310
|
+
if @trans_trace
|
311
|
+
agentconfig["transaction.trace.enabled"]=1
|
312
|
+
end
|
313
|
+
agentconfig["transaction.trace.threshold"]=@trans_trace_t
|
314
|
+
agentconfig["transaction.trace.sql.parametrize"]=0
|
315
|
+
if @sql_capture_params
|
316
|
+
agentconfig["transaction.trace.sql.parametrize"]=1
|
317
|
+
end
|
318
|
+
agentconfig["transaction.trace.sql.stacktrace.threshold"]=@sql_trace_t
|
319
|
+
agentconfig["transaction.tracking.request.interval"]=1
|
320
|
+
agentconfig
|
321
|
+
end
|
159
322
|
|
160
323
|
def getDispatcher
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
324
|
+
|
325
|
+
@obj.log.info "Server: #{ENV['SERVER_SOFTWARE']}"
|
326
|
+
|
327
|
+
dispatcher = "unknown"
|
328
|
+
if defined?(PhusionPassenger) then
|
329
|
+
dispatcher = "passenger"
|
330
|
+
end
|
331
|
+
if defined?(Unicorn) then
|
332
|
+
dispatcher = "unicorn"
|
333
|
+
end
|
334
|
+
if defined?(Rainbows) then
|
335
|
+
dispatcher = "rainbows"
|
336
|
+
end
|
337
|
+
dispatcher
|
166
338
|
end
|
167
339
|
|
168
340
|
def isInteger default,value
|
@@ -184,6 +356,46 @@ module ManageEngine
|
|
184
356
|
end
|
185
357
|
end
|
186
358
|
|
359
|
+
def update_config configInfo
|
360
|
+
filepath = @obj.constants.apm_conf
|
361
|
+
f = "apminsight.conf.new"
|
362
|
+
begin
|
363
|
+
propsFile=File.open(filepath, 'r')
|
364
|
+
file = File.new(f,"w+")
|
365
|
+
propsFile.read.each_line do |line|
|
366
|
+
line.strip!
|
367
|
+
if (line[0] != ?# and line[0] != ?=)
|
368
|
+
i = line.index('=')
|
369
|
+
if (i)
|
370
|
+
key1 = line[0..i - 1].strip
|
371
|
+
if configInfo.has_key?(key1)
|
372
|
+
file.puts "#{key1}=#{configInfo[key1]}\n"
|
373
|
+
else
|
374
|
+
file.puts "#{line}\n"
|
375
|
+
end
|
376
|
+
else
|
377
|
+
file.puts "#{line}\n"
|
378
|
+
end
|
379
|
+
else
|
380
|
+
file.puts "#{line}\n"
|
381
|
+
end
|
382
|
+
end
|
383
|
+
rescue Exception=>e
|
384
|
+
@obj.log.info "Problem in Reading / Writing Property File : #{e.message} "
|
385
|
+
@obj.log.error "#{e.backtrace}"
|
386
|
+
ensure
|
387
|
+
propsFile.close
|
388
|
+
file.close
|
389
|
+
end
|
390
|
+
res = @obj.util.copyFiles f, filepath
|
391
|
+
if res
|
392
|
+
@obj.log.info "copyFiles result = #{res}"
|
393
|
+
#delete apminsight.conf.new has to be done
|
394
|
+
end
|
395
|
+
configureFile
|
396
|
+
assignConfig
|
397
|
+
end
|
398
|
+
|
187
399
|
|
188
400
|
end#c
|
189
401
|
end#m
|