site24x7_apminsight 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,60 @@
1
+ This License Agreement details the policy for license of Site24x7 APM Insight Ruby Agent ("Licensed Software")
2
+ Please read the following license carefully, before either (i) downloading the Licensed Software from an authorized website, or (ii) installing the Licensed Software. You acknowledge that you have read this License Agreement, have understood it, and agree to be bound by its terms. If you do not agree to the terms and conditions of this Agreement, do not download or install the Licensed Software.
3
+
4
+ 1. LICENSE GRANT
5
+
6
+ Zoho Corp. grants to you a non-exclusive, non-transferable, world-wide license to use the Licensed Software, including user documentation and updates during and as part of your subscription to APM Insight ("the Service").Licensed Software forms part and parcel of your subscription to the Service. You agree not to use the Licensed Software in any manner not explicitly permitted herein. Since the Licensed Software is provided as part of the Service, you also agree to comply with the terms under which the Service is provided to you.
7
+
8
+ 2. THIRD PARTY PRODUCTS:
9
+
10
+ The Licensed Software may contain software which originated with third party vendors and without limiting the general applicability of the other provisions of this Agreement, you agree that (a) the title to any third party software incorporated in the Licensed Software shall remain with the third party which supplied the same; and (b) you will not distribute any such third party software available with the Licensed Software, unless the license terms of such third party software provide otherwise.
11
+
12
+ 3. RESTRICTIONS ON USE:
13
+
14
+ In addition to all other terms and conditions of this Agreement, you shall not:
15
+ i. remove any copyright, trademark or other proprietary notices from the Licensed Software or its copies;
16
+ ii. make any copies except for one back-up or archival copy, for temporary emergency purpose;
17
+ iii. rent, lease, license, sublicense or distribute the Licensed Software or any portions of it on a standalone basis or as part of your application;
18
+ iv. modify or enhance the Licensed Software;
19
+ v. reverse engineer, decompile or disassemble the Licensed Software;
20
+
21
+ 4. TECHNICAL SUPPORT:
22
+
23
+ Technical support for the Licensed Software is provided as part of your subscription to the Service. Technical support for the Licensed Software is co-terminus with your subscription to the Service.
24
+
25
+ 5. OWNERSHIP AND INTELLECTUAL PROPERTY:
26
+
27
+ Zoho Corp. owns all right, title and interest in and to the Licensed Software. Zoho Corp. expressly reserves all rights not granted to you herein, including the right to discontinue or not to release any Software and to alter prices, features, specifications, capabilities, functions, licensing terms, release dates, general availability or characteristics of the Licensed Software. The Software is only licensed and not sold to you by Zoho Corp.
28
+
29
+ 6. AUDIT:
30
+
31
+ Zoho Corp. has the right to audit your Use of the Licensed Software by providing at least seven (7) days prior written notice of its intention to conduct such an audit at your facilities during normal business hours.
32
+
33
+ 7. CONFIDENTIALITY:
34
+
35
+ The Licensed Software contains proprietary information of Zoho Corp. that are protected by the laws of the United States and you hereby agree to take all reasonable efforts to maintain the confidentiality of the Licensed Software. You agree to reasonably communicate the terms and conditions of this Agreement to those persons employed by you who come into contact with or access the Licensed Software, and to use reasonable efforts to ensure their compliance with such terms and conditions, including but not limited to, not knowingly permitting such persons to use any portion of the Licensed Software for a purpose that is not allowed under this Agreement.
36
+
37
+ 8. WARRANTY DISCLAIMER:
38
+
39
+ ZOHO CORP. DOES NOT WARRANT THAT THE LICENSED SOFTWARE WILL BE ERROR-FREE. EXCEPT AS PROVIDED HEREIN, THE LICENSED SOFTWARE IS FURNISHED "AS IS" WITHOUT WARRANTY OF ANY KIND, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND WITHOUT WARRANTY AS TO THE PERFORMANCE OR RESULTS YOU MAY OBTAIN BY USING THE LICENSED SOFTWARE. YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING THE LICENSED SOFTWARE AND ASSUME ALL RISKS ASSOCIATED WITH THE USE OF IT, INCLUDING BUT NOT LIMITED TO THE RISKS OF PROGRAM ERRORS, DAMAGE TO OR LOSS OF DATA, PROGRAMS OR EQUIPMENT, AND UNAVAILABILITY OR INTERRUPTION OF OPERATIONS.
40
+ BECAUSE SOME JURISDICTIONS DO NOT ALLOW FOR THE EXCLUSION OR LIMITATION OF IMPLIED WARRANTIES, THE ABOVE EXCLUSIONS OR LIMITATIONS MAY NOT APPLY TO YOU.
41
+
42
+ 9. LIMITATION OF LIABILITY:
43
+
44
+ IN NO EVENT WILL ZOHO CORP. BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY SPECIAL, INCIDENTAL, INDIRECT, PUNITIVE OR EXEMPLARY OR CONSEQUENTIAL DAMAGES, OR DAMAGES FOR LOSS OF BUSINESS, LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF BUSINESS INFORMATION ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM OR FOR ANY CLAIM BY ANY OTHER PARTY EVEN IF ZOHO CORP. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. ZOHO CORP.'S ENTIRE LIABILITY WITH RESPECT TO ITS OBLIGATIONS UNDER THIS AGREEMENT OR OTHERWISE WITH RESPECT TO THE LICENSED SOFTWARE SHALL NOT EXCEED THE SUBSCRIPTION FEE PAID BY YOU FOR THE SERVICE.
45
+ BECAUSE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES, THE ABOVE EXCLUSIONS OR LIMITATIONS MAY NOT APPLY TO YOU.
46
+
47
+ 10. INDEMNIFICATION:
48
+
49
+ Zoho Corp. agrees to indemnify and defend you from and against any and all claims, actions or proceedings, arising out of any claim that the Licensed Software infringes or violates any valid U.S. patent, copyright or trade secret right of any third party; so long as you provide; (i) prompt written notice to Zoho Corp. of such claim; (ii) cooperate with Zoho Corp. in the defense and/or settlement thereof, at Zoho Corp.'s expense; and, (iii) allow Zoho Corp. to control the defense and all related settlement negotiations. The above is Zoho Corp.'s sole obligation to you and shall be your sole and exclusive remedy pursuant to this Agreement for intellectual property infringement.
50
+ Zoho Corp. shall have no indemnity obligation for claims of infringement to the extent resulting or alleged to result from (i) any combination, operation, or use of the Licensed Software with any programs or equipment not supplied by Zoho Corp.; (ii) any modification of the Licensed Software by a party other than Zoho Corp.; and (iii) your failure, within a reasonable time frame, to implement any replacement or modification of Licensed Software provided by Zoho Corp.
51
+
52
+ 11. TERMINATION:
53
+
54
+ This Agreement is co-terminus with your subscription to the Service. You may terminate this Agreement at any time by destroying or returning to Zoho Corp. all copies of the Licensed Software in your possession. Zoho Corp. may terminate this Agreement for any reason, including but not limited to your breach of any of the terms of this Agreement. Upon termination, you shall destroy or return to Zoho Corp. all copies of the Licensed Software and certify in writing that all known copies have been destroyed. All provisions relating to confidentiality, proprietary rights, non-disclosure, and limitation of liability shall survive the termination of this Agreement.
55
+
56
+ 12. GENERAL:
57
+
58
+ If you are a resident of the United States or Canada, this Agreement shall be governed by and interpreted in all respects by the laws of the State of California, without reference to conflict of laws' principles, as such laws are applied to agreements entered into and to be performed entirely within California between California residents. If you are a resident of any other country, this Agreement shall be governed by and interpreted in all respects by the laws of the Republic of India without reference to conflict of laws' principles, as such laws are applied to agreements entered into and to be performed entirely within the Republic of India between residents of the Republic of India. If you are a resident of the United States or Canada, you agree to submit to the personal jurisdiction of the courts in the Northern District of California. If you are a resident of any other country, you agree to submit to the personal jurisdiction of the courts in Chennai, India. This Agreement constitutes the entire agreement between the parties, and supersedes all prior communications, understandings or agreements between the parties. Any waiver or modification of this Agreement shall only be effective if it is in writing and signed by both parties hereto. If any part of this Agreement is found to be invalid or unenforceable, the remainder shall be interpreted so as to reasonably effect the intention of the parties.
59
+
60
+
data/README.rdoc ADDED
@@ -0,0 +1,67 @@
1
+ APM Insight Ruby Agent
2
+ Site24x7 APM Insight Ruby agent gives you end-to-end web-transaction awareness enabling you to isolate performance issues and resolve them quickly. Site24x7 APM Insight requires a monitoring agent (ruby gem) to be deployed in your application server to monitor Ruby application performance. Download the latest Ruby Agent(site24x7_apminsight.gem) and deploy it in your application server. The agent collects application performance metrics and sends it to the central Site24x7 server at fixed intervals i.e. every 60 seconds. You can view them at https://site24x7.com in your accounts page.
3
+
4
+ Installing APM Insight Agent
5
+
6
+ Ruby Agent installation can be done in two ways:
7
+
8
+ * Install from RubyGems by using the following command in the system where Ruby is installed :
9
+
10
+ gem install site24x7_apminsight
11
+
12
+ OR
13
+
14
+ * Download the site24x7_apminsight.gem file from your accounts page in https://site24x7.com (after sign in) or the RubyGems website and run the command
15
+
16
+ gem install site24x7_apminsight.gem
17
+
18
+ Configuration
19
+
20
+ After installation of the gem:
21
+
22
+ For each of your applications, add the following line to the application gemfile:
23
+
24
+ gem 'site24x7_apminsight'
25
+
26
+ OR
27
+
28
+ For each of your applications, add the following line to the application initializer block:
29
+
30
+ require 'site24x7_apminsight'
31
+
32
+ A copy of the configuration file apminsight.conf will be available in the <Gem Installed folder> /site24x7_apminsight/conf/. Configure the class name in the configuration file(include.packages), so that all the methods in that class can be instrumented and details will be reported in tracedata.
33
+
34
+
35
+ The following configuration options are mandatory and should be provided for the agent to be initialized:
36
+
37
+ application.name - The application's name to be displayed in Site24x7 server.
38
+
39
+ license.key - The license api key from your account page after sign in (https://site24x7.com)
40
+
41
+ behind.proxy - The proxy network under which the agent is installed
42
+
43
+ agent.server.port - The HTTP listening port of the Application Server.
44
+
45
+ More configuration options of APM Insight Ruby Agent can be found here. https://help.site24x7.com/APM-Insight-Agent-Configuration.html
46
+
47
+ Supported Environments :
48
+
49
+ Ruby - 1.8.7 and higher
50
+
51
+ Rails - 3.0 and higher
52
+
53
+ References
54
+
55
+ * Create an apminsight account in Site24x7 server (https://www.site24x7.com)
56
+
57
+ * Download link for site24x7_apminsight gem
58
+
59
+ From your account page after valid sign in
60
+ or
61
+ http://rubygems.org/gems/site24x7_apminsight
62
+
63
+ * Help Documentation for apminsight
64
+
65
+ https://help.site24x7.com/Installing-Ruby-Agent.html
66
+ https://help.site24x7.com/Troubleshooting-Tips-Ruby-Agent.html
67
+
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "site24x7_apminsight"
18
+ gem.homepage = "https://help.site24x7.com/Installing-Ruby-Agent.html" #to be changed after the web page is ready
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Application Performace Monitor}
21
+ gem.description = %Q{Application Performace Monitor : Monitor the web tranasactions}
22
+ gem.email = "apm-insight@zohocorp.com"
23
+ gem.authors = ["Rajalakshmi Ezhilan"]
24
+ gem.files=Dir.glob('lib/**/*.*')
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ test.rcov_opts << '--exclude "gems/*"'
42
+ end
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "site24x7_apminsight #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.*')
54
+ rdoc.rdoc_files.include('lib/agent/**/*.*')
55
+ rdoc.rdoc_files.include('lib/agent/*.*')
56
+ rdoc.rdoc_files.include('lib/agent/logging/*.*')
57
+ rdoc.rdoc_files.include('lib/agent/server/*.*')
58
+ rdoc.rdoc_files.include('lib/agent/server/worker/*.*')
59
+ rdoc.rdoc_files.include('lib/agent/configuration/*.*')
60
+ rdoc.rdoc_files.include('lib/agent/metrics/*.*')
61
+ rdoc.rdoc_files.include('lib/agent/util/*.*')
62
+ rdoc.rdoc_files.include('lib/config/*.*')
63
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0
@@ -0,0 +1,96 @@
1
+ # $Id$
2
+ #
3
+ ################### APM Insight Agent Configuration File ###################
4
+ #
5
+ #This file contains configuration options for APM Insight agent installation in your Application Server.
6
+ #
7
+ #NOTE: Though the properties can be defined in any different order, it is advisable to maintain
8
+ #the below order for related properties and ease of reference.
9
+ #
10
+ #All the configuration options defaults to factory configuration if commented or not supported values
11
+
12
+ #License key of your account.
13
+ license.key=
14
+
15
+ #Logical name of your application. Say for example you have "Order Processing" applications running in
16
+ #10 instances of Tomcat server. Specify the name as "Order Processing" for the name in all the 10
17
+ #instances while deploying the agent. Site24x7 will group the data from 10 instances of
18
+ #Tomcat and provide response time, throughput etc.
19
+ application.name=My Application
20
+
21
+ #APM Insight agent communicates to the Site24x7 through the HTTP/HTTPS protocol.
22
+ #Specify Proxy server configuration when there is a proxy server between APM Insight agent and
23
+ #Site24x7 server.
24
+ #
25
+ behind.proxy=false
26
+ #proxy.server.host=proxyserver
27
+ #proxy.server.port=proxyport
28
+ #proxy.auth.username=proxyuser
29
+ #proxy.auth.password=proxypassword
30
+
31
+ #Application Server HTTP/HTTPS listening port.Say for example when you are deploying the agent in Tomcat
32
+ #Server running in 8080 port, specify the value as 8080.
33
+ #[Mandatory]
34
+ agent.server.port=8080
35
+
36
+ #The Apdex (Application Performance Index) threshold is used to calculate application performance score.
37
+ #More at http://www.apdex.org.
38
+ #A Transaction is said to be satisfied, if the response time is equal to or below the apdex.threshold.
39
+ #A Transaction is said to be tolerating, if the response time is greater than apdex.threshold and less
40
+ #than 4 times of apdex.threshold. A Transaction is said to be frustrated, if the response time is greater
41
+ #than 4 times of apdex.threshold. Say for example when you specify the value as 2, transactions with response
42
+ #time less than 2 seconds is considered as satisfied, transactions with response time greater than 2 and
43
+ #less than 8 is considered as tolerating and transactions with response time greater than 8 seconds is
44
+ #considered as frustrating.
45
+ #default value: 0.5 (second)
46
+ apdex.threshold=0.5
47
+
48
+ #Whether SQL queries getting executed in your application need to be tracked or not.
49
+ #default value: true
50
+ sql.capture.enabled=true
51
+
52
+ #Whether the transaction trace is enabled or not. Setting this value to true will send the trace of the
53
+ #slow transaction.
54
+ #default value: true
55
+ transaction.trace.enabled=true
56
+
57
+ #Threshold to construct the trace for slow transactions. Transaction Traces violating this threshold will be
58
+ #collected and sent to the server. Used to analyze and troubleshoot the Transaction by the user.
59
+ #default value: 2 (second)
60
+ transaction.trace.threshold=2
61
+
62
+ #Enabling this option will parametrize all SQL Queries in Slow Transaction Traces (if sql.capture.enabled
63
+ #set to true & transaction.trace.enabled set to true). Disabling this option will give you the real query
64
+ #with actual parameters. It is recommended to enable this option if there are queries getting executed
65
+ #using confidential parameters like credit card number, passwords, etc.
66
+ #default value: true
67
+ transaction.trace.sql.parametrize=true
68
+
69
+ #Threshold value to generate a stack trace to identify the caller who executed a slow query. This stack
70
+ #trace is sent to the server for the user to analyze and troubleshoot
71
+ #default value: 3 (second)
72
+ transaction.trace.sql.stacktrace.threshold=3
73
+
74
+ #Stop listening transactions with specified URL pattern.
75
+ transaction.skip.listening=*.css, *.js, *.gif, *.jpg, *.jpeg, *.bmp, *.png
76
+
77
+ #Sampling counter.Say for example when you specify the value as 20, agent will track one in 20 transactions.
78
+ #default value: 1 (transaction)
79
+ transaction.tracking.request.interval=1
80
+
81
+ #The packages which also needs to be instrumented. By Default, APM Insight does not instrument all the class
82
+ #loaded in the JVM. eg: configuring com/test/customimpl/.* will include all the packages & classes that
83
+ #starts with com.test.customimpl. It is best if this is enabled only in the testing/staging environment.
84
+ #Use comma(,) to separate multiple entries.
85
+ #include.packages=
86
+
87
+ #Directory where agent logs information separately.
88
+ #Defaults to the directory where apminsight-javaagent.jar is installed.
89
+ #Use forward slash(/) as path separator.
90
+ #apminsight.log.dir=./apminsight/logs
91
+
92
+ #The log level at which the APM Insight agent should record logging
93
+ #information. The levels are SEVERE, WARNING, INFO, FINE in the order
94
+ #respectively. Defaults to the level INFO if commented or mentioned
95
+ #incorrectly.
96
+ apminsight.log.level=INFO
@@ -0,0 +1,66 @@
1
+
2
+ require "agent/configuration/am_configuration"
3
+ require "agent/logging/am_logger"
4
+ require "agent/util/am_util"
5
+ require "agent/util/am_constants"
6
+ require "agent/server/am_connector"
7
+ require "agent/server/am_agent"
8
+ require "agent/metrics/am_metricscollector"
9
+ require "agent/metrics/am_metricstore"
10
+ require "agent/metrics/am_metricsformatter"
11
+ require "agent/metrics/am_metricsparser"
12
+ require "agent/server/instrument/am_instrumenter"
13
+
14
+ module ManageEngine
15
+
16
+ class APMObjectHolder
17
+ attr_reader :config,:log,:util,:constants,:shutdown,:connector,:agent,:collector
18
+ attr_accessor :shutdown,:agent_initialized,:last_dispatch_time,:instrumenter,:store,:formatter,:parser
19
+ @@objects = nil
20
+ #Don't Change the Order of Initialize
21
+ def initializeObjects
22
+ @agent_initialized = false
23
+ @shutdown = false
24
+ @constants = ManageEngine::APMConstants.new
25
+ @log = ManageEngine::APMLogger.new
26
+ @util = ManageEngine::APMUtil.new
27
+ @util.setLogger @log
28
+ @config = ManageEngine::APMConfig.new
29
+ @connector = ManageEngine::APMConnector.new
30
+ @store = ManageEngine::APMMetricsStore.new
31
+ @collector = ManageEngine::APMMetricsCollector.new
32
+ @instrumenter = ManageEngine::APMInstrumenter.new
33
+ @formatter = ManageEngine::APMMetricsFormatter.new
34
+ @parser = ManageEngine::APMMetricsParser.new
35
+ @agent = ManageEngine::APMAgent.new
36
+ @last_dispatch_time = @@objects.util.currenttimemillis
37
+ @@objects.log.debug "[APMObjectHolder] [ All Objects Initialized ] "
38
+ end
39
+
40
+ def self.instance
41
+ if(@@objects==nil)
42
+ @@objects = ManageEngine::APMObjectHolder.new
43
+ @@objects.initializeObjects
44
+ end
45
+ return @@objects
46
+ end
47
+
48
+ def shutdownagent
49
+ ###@agent_initialized=false
50
+ #@shutdown = true
51
+ #@constants = nil
52
+ #@util = nil
53
+ #@config = nil
54
+ #@connector = nil
55
+ #@store = nil
56
+ #@collector=nil
57
+ #@instrumenter = nil
58
+ #@formatter = nil
59
+ #@parser = nil
60
+ #@agent = nil
61
+ #@log.info "[ APMObjectHolder ][ All Objects deleted ] "
62
+ #@log = nil
63
+ end
64
+
65
+ end #c
66
+ end#m
@@ -0,0 +1,268 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'socket'
4
+ require 'rails'
5
+ require 'agent/am_objectholder'
6
+
7
+ module ManageEngine
8
+ class APMConfig
9
+ attr_reader :agenthost,:agentport,:instance_id,:alreadyconnected,:apmhost,:apmport,:license_key,:site24x7
10
+ 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
11
+ attr_reader :proxy_host,:proxy_port ,:is_secured, :logs_dir ,:connection_retry,:agent_enabled,:connect_interval,:db_operations,:include_packages
12
+ attr_accessor :app_db,:app_dispatcher,:lastupdatedtime
13
+ def initialize
14
+ @obj = ManageEngine::APMObjectHolder.instance
15
+
16
+ #@config = @obj.util.readProperties(@obj.constants.apm_conf)
17
+ configureFile
18
+ @agenthost = Socket.gethostname
19
+ assignConfig
20
+ @obj.log.setLevel @config["apminsight.log.level"]
21
+ @instance_id = 0
22
+ @agent_enabled = false
23
+ @alreadyconnected = checkAgentInfo
24
+ @site24x7 = checkLicenseFile
25
+ @db_operations =["select","insert","update","delete"]
26
+ @obj.log.debug "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
27
+ @obj.log.debug "APP HOME #{File.absolute_path(".")} "
28
+ @obj.log.debug "APP HOME #{Dir.pwd} "
29
+ @obj.log.debug "Configuration : "
30
+ @obj.log.debug "Agent Name : #{@agenthost}"
31
+ @obj.log.debug "Agent Already Connected : #{@alreadyconnected}"
32
+ @obj.log.debug "Agent Enabled : #{@agent_enabled}"
33
+ @obj.log.debug "Allowed DB Operations : #{@db_operations}"
34
+ @config.each do|key,val|
35
+ @obj.log.info "#{key} => #{val}"
36
+ end
37
+ @obj.log.debug "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
38
+ @app_db="dummydb"
39
+ @app_dispatcher = getDispatcher
40
+ @lastupdatedtime=File.mtime(@obj.constants.apm_conf).to_i
41
+ end
42
+
43
+ def configureFile
44
+ begin
45
+ if(FileTest.exists?(@obj.constants.apm_conf))
46
+ #conf file exists in APPlication Home
47
+ @obj.log.debug "Config File Exists. It is read from #{@obj.constants.apm_conf}"
48
+ @config = @obj.util.readProperties(@obj.constants.apm_conf)
49
+ else
50
+ gem_conf = Gem.loaded_specs[@obj.constants.apm_gem].full_gem_path
51
+ #gem_conf = File.join(gem_conf, 'lib')
52
+ gem_conf = File.join(gem_conf, 'conf')
53
+ gem_conf = File.join(gem_conf, 'apminsight.conf')
54
+ #conf file not exists in APPlications Home. So 1. copy it for gem locations
55
+ if @obj.util.copyFiles gem_conf,@obj.constants.apm_conf
56
+ #copied sucessfully
57
+ @obj.log.debug "Config File copied. It is read from #{@obj.constants.apm_conf}"
58
+ @config = @obj.util.readProperties(@obj.constants.apm_conf)
59
+ else
60
+ #Problem in copying, so reading props from Conf file in Gem Location
61
+ @obj.log.debug "Config File not copied. It is read from #{gem_conf}"
62
+ @config = @obj.util.readProperties(gem_conf)
63
+ end
64
+ end
65
+
66
+ rescue Exception=>e
67
+ @obj.log.info "[Exception] Problem in Reading Configuration File : \n File : #{@obj.constants.apm_conf}"
68
+ @obj.log.logException "#{e.message}",e
69
+ @config = @obj.util.readProperties(gem_conf)
70
+ ensure
71
+ end
72
+ end
73
+
74
+ def checkAgentInfo
75
+ if FileTest.exists?(@obj.constants.agent_conf)
76
+ @obj.log.debug "Status : Agent Already Connected"
77
+ props = @obj.util.readProperties(@obj.constants.agent_conf)
78
+ @instance_id = props["agent.id"]
79
+ @agent_enabled= @obj.util.getBooleanValue props["agent.enabled"]
80
+ true
81
+ else
82
+ @obj.log.info "Status : Agent not connected"
83
+ false
84
+ end
85
+ end
86
+
87
+ def checkLicenseFile
88
+ if(@license_key != nil)
89
+ @obj.log.info "License key is not null. Connecting to site24x7"
90
+ @obj.constants.setLicenseKey @license_key
91
+ true
92
+ else
93
+ @obj.log.info "License key is null. Connecting to APPManager"
94
+ false
95
+ end
96
+
97
+ end
98
+
99
+ def updateAgentInfoFile(props)
100
+ @instance_id = props["agent.id"]
101
+ @agent_enabled= @obj.util.getBooleanValue props["agent.enabled"]
102
+ @obj.util.writeProperties(@obj.constants.agent_conf,props)
103
+ end
104
+
105
+ def initValues
106
+ @apmport=8080
107
+ @appname="My Application"
108
+ @proxyneeded = false
109
+ @proxy_host="localhost"
110
+ @proxy_port=80
111
+ @proxy_user=""
112
+ @proxy_pass=""
113
+ @is_secured=false
114
+ @logs_dir="./log"
115
+ @connection_retry = 0
116
+ @connect_interval = 60
117
+ @apdex_t=0.5
118
+ @include_packages=Array.new
119
+ @trans_trace_t=2
120
+ @sql_trace_t=3
121
+ @metric_overflow_t=250
122
+ @trace_overflow_t=60
123
+ end
124
+
125
+ def assignConfig
126
+ initValues
127
+ @config.each do |key,value|
128
+ case key
129
+ when "application.name" then @appname=value
130
+ when "apm.host" then @apmhost=value
131
+ when "apm.port" then @apmport=isInteger(@apmport,value)
132
+ when "license.key" then @license_key=value
133
+ when "behind.proxy" then @proxyneeded=@obj.util.getBooleanValue value
134
+ when "agent.server.port" then @agentport=isInteger(@agentport,value)
135
+ when "apdex.threshold" then @apdex_t=isFloat(@apdex_t,value)
136
+ when "transaction.trace.enabled" then @trans_trace=@obj.util.getBooleanValue value
137
+ when "transaction.trace.threshold" then @trans_trace_t=isFloat(@trans_trace_t,value)
138
+ when "sql.capture.enabled" then @sql_capture=@obj.util.getBooleanValue value
139
+ when "transaction.trace.sql.parametrize" then @sql_capture_params=@obj.util.getBooleanValue value
140
+ when "transaction.trace.sql.stacktrace.threshold" then @sql_trace_t=isFloat(@sql_trace_t,value)
141
+ when "proxy.server.host" then @proxy_host=value
142
+ when "proxy.server.port" then @proxy_port=value
143
+ when "proxy.auth.username" then @proxy_user=value
144
+ when "proxy.auth.password" then @proxy_pass=value
145
+ when "apminsight.secure" then @is_secured=@obj.util.getBooleanValue value
146
+ when "apminsight.log.dir" then @logs_dir=value
147
+ when "agent.connection.retry" then @connection_retry=value #Not in Conf - yet to come
148
+ when "agent.connection.interval" then @connect_interval=value#Not in Conf - yet to come
149
+ when "include.packages" then @include_packages=@obj.util.getArray value,","
150
+ end
151
+ end
152
+ end
153
+
154
+ def getAgentInfo
155
+ data = Hash.new
156
+ agentdata = Hash.new
157
+ agentdata = {"application.type"=>"RUBY","application.name"=>@appname,"hostname"=>@agenthost,"port"=>@agentport,"agent.version"=>"1.0"}
158
+ data["agent_info"]=agentdata
159
+ data["environment"]=getEnvData
160
+ data["custom_config_info"]=getAgentConfigData
161
+ data
162
+ end
163
+
164
+ def getEnvData
165
+ env = Hash.new
166
+ begin
167
+ ENV.to_hash.each do |key, value|
168
+ env[key] = value
169
+ end
170
+ env["Application Path"]="#{Rails.root}"
171
+ rescue Exception=>e
172
+ end
173
+ env
174
+ end
175
+
176
+ def getAgentConfigData
177
+ agentconfig = Hash.new
178
+ agentconfig["last.modified.time"]=@lastupdatedtime*1000
179
+ agentconfig["apdex.threshold"]=@apdex_t
180
+ agentconfig["sql.capture.enabled"]=0
181
+ if @sql_capture
182
+ agentconfig["sql.capture.enabled"]=1
183
+ end
184
+ agentconfig["transaction.trace.enabled"]=0
185
+ if @trans_trace
186
+ agentconfig["transaction.trace.enabled"]=1
187
+ end
188
+ agentconfig["transaction.trace.threshold"]=@trans_trace_t
189
+ agentconfig["transaction.trace.sql.parametrize"]=0
190
+ if @sql_capture_params
191
+ agentconfig["transaction.trace.sql.parametrize"]=1
192
+ end
193
+ agentconfig["transaction.trace.sql.stacktrace.threshold"]=@sql_trace_t
194
+ agentconfig["transaction.tracking.request.interval"]=1
195
+ agentconfig
196
+ end
197
+
198
+ def getDispatcher
199
+ dispatcher = "unknown"
200
+ if defined?(PhusionPassenger) then
201
+ dispatcher = "passenger"
202
+ end
203
+ dispatcher
204
+ end
205
+
206
+ def isInteger default,value
207
+ if @obj.util.is_integer value
208
+ value.to_i
209
+ else
210
+ @obj.log.info "Problem in getting Integer Value #{value} .. So setting default value #{default} "
211
+ default.to_i
212
+ end
213
+
214
+ end
215
+
216
+ def isFloat default,value
217
+ if @obj.util.is_float value
218
+ value.to_f
219
+ else
220
+ default.to_f
221
+ @obj.log.info "Problem in getting Integer Value #{value} .. So setting default value #{default} "
222
+ end
223
+ end
224
+
225
+ def update_config configInfo
226
+ filepath = @obj.constants.apm_conf
227
+ f = "apminsight.conf.new"
228
+ begin
229
+ propsFile=File.open(filepath, 'r')
230
+ file = File.new(f,"w+")
231
+ propsFile.read.each_line do |line|
232
+ line.strip!
233
+ if (line[0] != ?# and line[0] != ?=)
234
+ i = line.index('=')
235
+ if (i)
236
+ key1 = line[0..i - 1].strip
237
+ if configInfo.has_key?(key1)
238
+ file.puts "#{key1}=#{configInfo[key1]}\n"
239
+ else
240
+ file.puts "#{line}\n"
241
+ end
242
+ else
243
+ file.puts "#{line}\n"
244
+ end
245
+ else
246
+ file.puts "#{line}\n"
247
+ end
248
+ end
249
+ rescue Exception=>e
250
+ @obj.log.info "Problem in Reading / Writing Property File : #{e.message} "
251
+ @obj.log.error "#{e.backtrace}"
252
+ ensure
253
+ propsFile.close
254
+ file.close
255
+ end
256
+ res = @obj.util.copyFiles f, filepath
257
+ if res
258
+ @obj.log.info "copyFiles result = #{res}"
259
+ #delete apminsight.conf.new has to be done
260
+ end
261
+ configureFile
262
+ assignConfig
263
+ end
264
+
265
+
266
+ end#c
267
+ end#m
268
+