Class: ManageEngine::Tracker::DatabaseTracker
Instance Attribute Summary
#children, #component, #endtime, #error, #name, #parent, #starttime
Instance Method Summary
collapse
#==, #duration, #error?, #finish, #hash, #setError, #setName, #setParent
Constructor Details
#initialize(name = "unknown", time = ManageEngine::APMObjectHolder.instance.util.currenttimemillis) ⇒ DatabaseTracker
Returns a new instance of DatabaseTracker.
5
6
7
8
|
# File 'lib/agent/trackers/database_tracker.rb', line 5
def initialize(name = "unknown", time = ManageEngine::APMObjectHolder.instance.util.currenttimemillis)
super(name, time)
@component = "DATABASE"
end
|
Instance Method Details
95
96
97
98
99
|
# File 'lib/agent/trackers/database_tracker.rb', line 95
def format s
s.gsub!("\"", '')
s.gsub!("\n", '')
s
end
|
#getAdditionalInfo ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/agent/trackers/database_tracker.rb', line 101
def getAdditionalInfo
info = super
begin
if (@query != nil)
if (info == nil)
info = Hash.new
end
obj = ManageEngine::APMObjectHolder.instance
info["query"] = !obj.config.sql_capture_params ? getCompleteQuery : getObfuscatedQuery
if (@backtrace != nil && @error == nil)
info["stacktrace"] = obj.util.formatStacktrace(@backtrace)
end
end
rescue Exception => e
@logger.logException("Error updating additionalInfo in dbTracker.", e)
end
info
end
|
#getCompleteQuery ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/agent/trackers/database_tracker.rb', line 30
def getCompleteQuery
begin
query = @query if query != nil && @binds != nil && @binds.length > 0
@binds.each do |ar|
if query.index("?") != nil
query["?"]=ar.value.to_s
end
end
return query
end
rescue Exception=>exe
@logger.logException "Not severe -#{exe.message}",exe
end
@query
end
|
#getObfuscatedQuery ⇒ Object
#getQueryInfo ⇒ Object
Returns array [db_operation, tablename]
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
|
# File 'lib/agent/trackers/database_tracker.rb', line 48
def getQueryInfo
sql = @query
sql.strip!
sql.downcase!
sqlArr = sql.split(" ")
begin
tableName = case sqlArr[0]
when "select" then
fromIndex = sqlArr.index("from");
if(fromIndex != nil)
sqlArr[fromIndex+1]
else
"-"
end
when "insert" then
intoIndex = sqlArr.index("into");
if(intoIndex != nil)
sqlArr[intoIndex+1]
else
"-"
end
when "update" then sqlArr[1]
when "delete" then
fromIndex = sqlArr.index("from");
if(fromIndex != nil)
sqlArr[fromIndex+1]
else
"-"
end
when "create" then sqlArr[1] + sqlArr[2]
when "alter" then sqlArr[1] + sqlArr[2]
when "drop" then sqlArr[1] + sqlArr[2]
when "show" then sqlArr[1]
when "describe" then sqlArr[1]
else "-"
end
@signature = sqlArr[0] + " - " + tableName
return [sqlArr[0], tableName]
rescue Exception=>e
@logger.logException "Error processing query #{sql} Exception: #{e.message}",e
@signature = sqlArr[0] + " - "
return [sqlArr[0], '-']
end
end
|
#getRawQuery ⇒ Object
22
23
24
|
# File 'lib/agent/trackers/database_tracker.rb', line 22
def getRawQuery
@query
end
|
#getTrace ⇒ Object
129
130
131
132
133
134
135
|
# File 'lib/agent/trackers/database_tracker.rb', line 129
def getTrace
trace = super
if (@signature != nil)
trace[1] = @signature
end
trace
end
|
#params(binds = []) ⇒ Object
14
15
16
|
# File 'lib/agent/trackers/database_tracker.rb', line 14
def params(binds = [])
@binds = binds
end
|
#sql(query) ⇒ Object
10
11
12
|
# File 'lib/agent/trackers/database_tracker.rb', line 10
def sql(query)
@query = format(query.dup)
end
|
#sqlBacktrace(backtrace) ⇒ Object
18
19
20
|
# File 'lib/agent/trackers/database_tracker.rb', line 18
def sqlBacktrace(backtrace)
@backtrace = backtrace
end
|
#to_s ⇒ Object
125
126
127
|
# File 'lib/agent/trackers/database_tracker.rb', line 125
def to_s
"#{@name} - #{@query}"
end
|