site24x7_apminsight 1.7.3.0 → 1.8.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.8.2
@@ -19,22 +19,28 @@ module ManageEngine
19
19
  @@objects = nil
20
20
  #Don't Change the Order of Initialize
21
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
- @txn_util = ManageEngine::TransactionUtil.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 ] "
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
@@ -3,7 +3,7 @@ require 'json'
3
3
  require 'socket'
4
4
  require 'net/http'
5
5
  require 'agent/am_objectholder'
6
- require 'version'
6
+ require 'agent/version'
7
7
 
8
8
  module ManageEngine
9
9
  class APMConfig
@@ -24,7 +24,7 @@ module ManageEngine
24
24
  @alreadyconnected = checkAgentInfo
25
25
  @site24x7 = checkLicenseFile
26
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
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 : @license_key.start_with?('gd_') ? @obj.constants.site24x7GDurl : @obj.constants.site24x7USurl
28
28
  end
29
29
  @db_operations =["select","insert","update","delete"]
30
30
  urlMergePattern
@@ -58,6 +58,7 @@ module ManageEngine
58
58
  #conf file exists in APPlication Home
59
59
  @obj.log.debug "Config File Exists. It is read from #{@obj.constants.apm_conf}"
60
60
  @config = @obj.util.readProperties(@obj.constants.apm_conf)
61
+ secureConfFile "#{@obj.constants.apm_conf}"
61
62
  else
62
63
  gemSpecs = Gem.loaded_specs[@obj.constants.s247_apm_gem]
63
64
  if (gemSpecs == nil)
@@ -72,13 +73,14 @@ module ManageEngine
72
73
  #copied sucessfully
73
74
  @obj.log.info "Config File copied to application home directory. It is read from #{@obj.constants.apm_conf}"
74
75
  @config = @obj.util.readProperties(@obj.constants.apm_conf)
76
+ secureConfFile "#{@obj.constants.apm_conf}"
75
77
  else
76
78
  #Problem in copying, so reading props from Conf file in Gem Location
77
79
  @obj.log.warn "Config File not copied. It is read from #{gem_conf}"
78
80
  @config = @obj.util.readProperties(gem_conf)
81
+ secureConfFile gem_conf
79
82
  end
80
83
  end
81
-
82
84
  rescue Exception=>e
83
85
  @obj.log.info "[Exception] Problem in Reading Configuration File : \n File : #{@obj.constants.apm_conf}"
84
86
  @obj.log.logException "#{e.message}",e
@@ -87,6 +89,14 @@ module ManageEngine
87
89
  end
88
90
  end
89
91
 
92
+ def secureConfFile(file)
93
+ begin
94
+ File.chmod(0600, file)
95
+ rescue Exception => e
96
+ @obj.log.warn "Unable to secure the conf file #{file}"
97
+ end
98
+ end
99
+
90
100
  def checkAgentInfo
91
101
  if FileTest.exists?(@obj.constants.agent_conf)
92
102
  @obj.log.debug "Status : Agent Already Connected"
@@ -138,6 +148,8 @@ module ManageEngine
138
148
  @instance_id = props["agent.id"]
139
149
  @agent_enabled= @obj.util.getBooleanValue props["agent.enabled"]
140
150
  @obj.util.writeProperties(@obj.constants.agent_conf,props)
151
+
152
+ secureConfFile(@obj.constants.agent_conf)
141
153
  end
142
154
 
143
155
  def initValues
@@ -246,7 +258,9 @@ module ManageEngine
246
258
  def getHostType
247
259
  begin
248
260
  # Check for AWS environment
249
- response = Net::HTTP.get_response(URI('http://169.254.169.254/latest/meta-data/'))
261
+ url = URI.parse('http://169.254.169.254/latest/meta-data/') # AWS metadata url
262
+ request = Net::HTTP::Get.new(url.path)
263
+ response = Net::HTTP.start(url.host, url.port, :read_timeout => 2) {|http| http.request(request)}
250
264
  if (response.kind_of? Net::HTTPOK)
251
265
  @hostType = "AWS"
252
266
  return @hostType
@@ -256,7 +270,9 @@ module ManageEngine
256
270
 
257
271
  begin
258
272
  #Check for Azure environment
259
- response = Net::HTTP.get_response(URI('http://169.254.169.254/metadata/v1/maintenance'))
273
+ url = URI.parse('http://169.254.169.254/metadata/v1/maintenance') # Azure metadata url
274
+ request = Net::HTTP::Get.new(url.path)
275
+ response = Net::HTTP.start(url.host, url.port, :read_timeout => 2) {|http| http.request(request)}
260
276
  if (response.kind_of? Net::HTTPOK)
261
277
  @hostType = "AZURE"
262
278
  return @hostType
@@ -264,6 +280,15 @@ module ManageEngine
264
280
  rescue Exception => e
265
281
  end
266
282
 
283
+ begin
284
+ # Check for Heroku env. In the backgroud it is using AWS EC2, hence sending as AWS
285
+ if (ENV.has_key?('DYNO') || ENV.has_key?('STACK'))
286
+ @hostType = "AWS"
287
+ return @hostType
288
+ end
289
+ rescue Exception => e
290
+ end
291
+
267
292
  @hostType = nil
268
293
  end
269
294
 
@@ -3,7 +3,7 @@ require 'agent/metrics/exception_record'
3
3
  module APMInsight
4
4
  module Agent
5
5
  class SequenceBook
6
- attr_reader :openTracker, :closedTracker, :rootTracker, :trackerCount, :exceptionBag, :listenFlag
6
+ attr_reader :openTracker, :closedTracker, :rootTracker, :trackerCount, :closedTrackerCount, :exceptionBag, :listenFlag
7
7
 
8
8
  def initialize
9
9
  @rootTracker = createDummyTracker()
@@ -11,6 +11,7 @@ module APMInsight
11
11
  @openTracker = nil
12
12
 
13
13
  @trackerCount = 0
14
+ @closedTrackerCount = 0
14
15
  @listenFlag = -1
15
16
  # @exceptionBag = Array.new
16
17
  end
@@ -54,6 +55,7 @@ module APMInsight
54
55
  end
55
56
 
56
57
  def closeTracker tracker
58
+ @closedTrackerCount += 1
57
59
  @closedTracker = tracker
58
60
  tracker.sibling = nil
59
61
  @openTracker = nil
@@ -61,12 +63,16 @@ module APMInsight
61
63
  # Marks end of transaction
62
64
  if @rootTracker == tracker
63
65
  if @listenFlag < 1 || (@listenFlag >= 1 && @trackerCount > 1)
64
-
65
- sequenceBag = Hash.new
66
- sequenceBag["roottracker"] = @rootTracker
67
- sequenceBag["exceptions"] = @exceptionBag
68
-
69
- ManageEngine::APMObjectHolder.instance.collector.updateTransaction(@rootTracker.url, sequenceBag)
66
+ # if some trackers are not closed, while processing the metrics, it may go into infinite loop
67
+ if (@closedTrackerCount - @trackerCount) == 0
68
+ sequenceBag = Hash.new
69
+ sequenceBag["roottracker"] = @rootTracker
70
+ sequenceBag["exceptions"] = @exceptionBag
71
+
72
+ ManageEngine::APMObjectHolder.instance.collector.updateTransaction(@rootTracker.url, sequenceBag)
73
+ else
74
+ ManageEngine::APMObjectHolder.instance.log.warn "Some trackers are not closed, dropping the metrics for #{@rootTracker.url}"
75
+ end
70
76
  end
71
77
  closeSequence()
72
78
  end
@@ -76,6 +82,7 @@ module APMInsight
76
82
  @rootTracker = nil
77
83
  @openTracker = @closedTracker = nil
78
84
  @trackerCount = 0
85
+ @closedTrackerCount = 0
79
86
  Thread.current[:apminsight] = nil
80
87
  end
81
88
 
@@ -84,8 +91,10 @@ module APMInsight
84
91
  if @exceptionBag == nil
85
92
  @exceptionBag = Set.new
86
93
  end
87
- exceptionRecord = ::APMInsight::Errors::ExceptionRecord.new(exception)
88
- @exceptionBag.add(exceptionRecord)
94
+ if (@exceptionBag.size() < 10)
95
+ exceptionRecord = ::APMInsight::Errors::ExceptionRecord.new(exception)
96
+ @exceptionBag.add(exceptionRecord)
97
+ end
89
98
  rescue Exception=>e
90
99
  end
91
100
  end
@@ -99,7 +108,8 @@ module APMInsight
99
108
  end
100
109
 
101
110
  def checkAndArrestSequence
102
- if ++@trackerCount == 1000
111
+ @trackerCount += 1
112
+ if @trackerCount == 1000
103
113
  @listenFlag = 1
104
114
  end
105
115
 
@@ -4,6 +4,8 @@ require "logger"
4
4
  module ManageEngine
5
5
  class APMLogger
6
6
  @apmlog=nil;
7
+ @apmLogPath=nil;
8
+
7
9
  def initialize
8
10
  @obj=ManageEngine::APMObjectHolder.instance
9
11
  path = getLogsPath
@@ -11,13 +13,19 @@ module ManageEngine
11
13
  if Dir[path] == []
12
14
  Dir.mkdir(path)
13
15
  end
14
- path= path + '/apm.log'
16
+ @apmLogPath= path + '/apm.log'
15
17
  #puts "#{path}"
16
18
  # file = open(path, File::WRONLY | File::APPEND | File::CREAT)
17
- @apmlog = Logger.new(path, 10, 5 * 1024 * 1024)
18
- # @apmlog = Logger.new(file)
19
- @apmlog.level = Logger::INFO
20
- @apmlog.datetime_format = "%Y-%m-%d %H:%M:%S"
19
+ begin
20
+ @apmlog = Logger.new(@apmLogPath, 10, 5 * 1024 * 1024)
21
+ @apmlog.level = Logger::INFO
22
+ rescue Exception => e
23
+ puts "Unable to create/edit the log file #{@apmLogPath}. Writing agent logs to STDOUT.\nError: #{e.message}"
24
+ @apmlog = Logger.new(STDOUT)
25
+ @apmlog.level = Logger::WARN
26
+ end
27
+ # @apmlog = Logger.new(file)
28
+ @apmlog.datetime_format = "%Y-%m-%d %H:%M:%S"
21
29
  @apmlog.formatter = proc do |severity, datetime, progname, msg|
22
30
  "[#{datetime}|#{Process.pid}][#{severity}]:#{msg}\n"
23
31
  end
@@ -25,6 +33,9 @@ module ManageEngine
25
33
 
26
34
  end
27
35
 
36
+ def getLogFilePath
37
+ return @apmLogPath
38
+ end
28
39
 
29
40
  def getLogsPath
30
41
  props = {}
@@ -53,7 +64,7 @@ module ManageEngine
53
64
  if props["apminsight.log.dir"]!=nil
54
65
  return props["apminsight.log.dir"]
55
66
  else
56
- return "./log"
67
+ return @obj.constants.conf_location+"log"
57
68
  end
58
69
 
59
70
  end
@@ -17,7 +17,8 @@ module ManageEngine
17
17
 
18
18
  doDispatcherActions
19
19
  doCollect
20
- puts "APM Insight Ruby Agent Started"
20
+ puts "APM Insight Ruby Agent Started. Agent files are located at #{@obj.constants.conf_location}"
21
+ puts "Agent log file apm.log is generated at #{@obj.log.getLogFilePath}"
21
22
  else
22
23
  @obj.log.info "Agent Initialization Failed - Going to shutdown"
23
24
  #While parsing the response from /arh/connect we set instrumenter to nil on delete request
@@ -109,14 +109,14 @@ module ManageEngine
109
109
  #con.verify_mode=OpenSSL::SSL::VERIFY_NONE
110
110
  #@obj.log.info "connection = #{con}"
111
111
  end
112
- con=getScheme(con)
112
+ con=getScheme(con, url)
113
113
  con.open_timeout = @obj.constants.connection_open_timeout
114
114
  con.read_timeout = @obj.constants.connection_read_timeout
115
115
  con
116
116
  end
117
117
 
118
- def getScheme(con)
119
- if(@obj.config.license_key != nil || @obj.config.is_secured)
118
+ def getScheme(con, url)
119
+ if(url.to_s.start_with?("https"))
120
120
  #@obj.log.info "[connect] Secured"
121
121
  #con = Net::HTTP::Proxy(@obj.config.proxy_host, @obj.config.proxy_port,@obj.config.proxy_user,@obj.config.proxy_pass).new(url.host, url.port)
122
122
  con.use_ssl=true
@@ -28,7 +28,12 @@ module ManageEngine
28
28
  end
29
29
 
30
30
  def duration
31
- (@endtime - @starttime).to_i
31
+ begin
32
+ (@endtime - @starttime).to_i
33
+ rescue Exception=>e
34
+ @logger.warn "Name: #{name} Starttime: #{starttime} Endtime: #{endtime}"
35
+ raise e
36
+ end
32
37
  end
33
38
 
34
39
  def ==(obj)
@@ -2,33 +2,33 @@
2
2
  module ManageEngine
3
3
  class APMConstants
4
4
 
5
- attr_reader :apm_gem,:s247_apm_gem,:apm_conf,:agent_conf,:connection_open_timeout,:connection_read_timeout,:connect_uri,:connect_data_uri,:connect_trace_uri,:connect_config_update_uri,:mergepattern_conf
6
- attr_reader :site24x7USurl, :site24x7EUurl, :site24x7CNurl, :site24x7INurl, :site24x7AUurl
5
+ attr_reader :conf_location, :apm_gem,:s247_apm_gem,:apm_conf,:agent_conf,:connection_open_timeout,:connection_read_timeout,:connect_uri,:connect_data_uri,:connect_trace_uri,:connect_config_update_uri,:mergepattern_conf
6
+ attr_reader :site24x7USurl, :site24x7EUurl, :site24x7CNurl, :site24x7INurl, :site24x7AUurl, :site24x7GDurl
7
7
  attr_reader :licence_exceeds,:licence_expired,:unmanage_agent,:manage_agent,:agent_config_updated,:error_notfound,:error_server,:delete_agent,:response_code,:custom_config_info, :agent_specific_info
8
8
  attr_reader :mf_transaction,:mf_separator,:mf_db,:mf_apdex,:mf_namespace,:mf_name,:mf_all,:agent_store,:agent_lock,:mf_overflow
9
9
  attr_reader :mf_logmetric, :mf_logmetric_warning, :mf_exception_st, :mf_err_st, :mf_loginfo, :mf_loginfo_time, :mf_loginfo_level, :mf_loginfo_str, :mf_loginfo_err_clz, :mf_loginfo_st, :mf_loginfo_level_warn
10
10
  attr_reader :en_alphabets, :en_numerals
11
11
 
12
12
  def initialize
13
-
13
+ @conf_location=ENV.has_key?('APMINSIGHT_HOME') ? ENV['APMINSIGHT_HOME']+"/" : "./"
14
14
  #File path for APM Conf file
15
- @apm_gem="apminsight"
16
- @s247_apm_gem="site24x7_apminsight"
15
+ @apm_gem=@conf_location + "apminsight"
16
+ @s247_apm_gem=@conf_location + "site24x7_apminsight"
17
17
 
18
18
  #File path for APM Conf file
19
- @apm_conf="apminsight.conf"
19
+ @apm_conf=@conf_location + "apminsight.conf"
20
20
 
21
21
  #file path for agent id, enable details
22
- @agent_conf="apminsight.info"
22
+ @agent_conf=@conf_location + "apminsight.info"
23
23
 
24
24
  #file path for agent data store lock
25
- @agent_lock="apminsight.lock"
25
+ @agent_lock=@conf_location + "apminsight.lock"
26
26
 
27
27
  #file path for agent data store lock
28
- @agent_store="apminsight.store"
28
+ @agent_store=@conf_location + "apminsight.store"
29
29
 
30
30
  #file name for url merge patterns
31
- @mergepattern_conf="transaction_merge_patterns.conf"
31
+ @mergepattern_conf=@conf_location + "transaction_merge_patterns.conf"
32
32
 
33
33
 
34
34
  #Timeout for opening Connections
@@ -53,8 +53,9 @@ module ManageEngine
53
53
  @site24x7USurl = "https://plusinsight.site24x7.com/"
54
54
  @site24x7EUurl = "https://plusinsight.site24x7.eu/"
55
55
  @site24x7CNurl = "https://plusinsight.site24x7.cn/"
56
- @site24x7AUurl = "https://plusinsight.site24x7.au/"
56
+ @site24x7AUurl = "https://plusinsight.site24x7.net.au/"
57
57
  @site24x7INurl = "https://plusinsight.site24x7.in/"
58
+ @site24x7GDurl = "https://gdplusinsight.site24x7.com/"
58
59
 
59
60
  #Response Codes
60
61
  @licence_expired = 701
@@ -6,8 +6,8 @@
6
6
 
7
7
  module ManageEngine
8
8
  class APMInsight
9
- VERSION = '1.7.3.0'
10
- MAJOR_VERSION = '1.7'
11
- MINOR_VERSION = '3.0'
9
+ VERSION = '1.8.5'
10
+ MAJOR_VERSION = '1.8'
11
+ MINOR_VERSION = '5'
12
12
  end
13
13
  end
@@ -3,7 +3,7 @@
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
- require './lib/version'
6
+ require './lib/agent/version'
7
7
  require 'date'
8
8
 
9
9
  Gem::Specification.new do |s|
@@ -28,7 +28,6 @@ Gem::Specification.new do |s|
28
28
  'VERSION',
29
29
  'site24x7-agent.gemspec',
30
30
  'conf/apminsight.conf',
31
- 'lib/version.rb',
32
31
  'lib/site24x7_apminsight.rb',
33
32
  'lib/agent/**/*'
34
33
  ]
metadata CHANGED
@@ -4,10 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 7
8
- - 3
9
- - 0
10
- version: 1.7.3.0
7
+ - 8
8
+ - 5
9
+ version: 1.8.5
11
10
  platform: ruby
12
11
  authors:
13
12
  - Adithyan P
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2018-12-28 00:00:00 +05:30
17
+ date: 2021-06-29 00:00:00 +05:30
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -105,7 +104,6 @@ files:
105
104
  - VERSION
106
105
  - site24x7-agent.gemspec
107
106
  - conf/apminsight.conf
108
- - lib/version.rb
109
107
  - lib/site24x7_apminsight.rb
110
108
  - lib/agent/am_objectholder.rb
111
109
  - lib/agent/api/custom_tracker.rb
@@ -135,6 +133,7 @@ files:
135
133
  - lib/agent/util/am_constants.rb
136
134
  - lib/agent/util/am_util.rb
137
135
  - lib/agent/util/transaction_util.rb
136
+ - lib/agent/version.rb
138
137
  has_rdoc: true
139
138
  homepage: https://www.site24x7.com/help/apm/ruby-agent.html
140
139
  licenses: []