Class: APMInsight::Agent::SequenceBook

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/handler/sequence_book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSequenceBook

Returns a new instance of SequenceBook.



8
9
10
11
12
13
14
15
16
17
# File 'lib/agent/handler/sequence_book.rb', line 8

def initialize
  @rootTracker = nil
  #@closedTracker = @rootTracker
  @openTracker = nil
  
  @trackerCount = 0
  @closedTrackerCount = 0
  @listenFlag = -1
#        @exceptionBag = Array.new
end

Instance Attribute Details

#exceptionBagObject (readonly)

Returns the value of attribute exceptionBag.



6
7
8
# File 'lib/agent/handler/sequence_book.rb', line 6

def exceptionBag
  @exceptionBag
end

#listenFlagObject (readonly)

Returns the value of attribute listenFlag.



6
7
8
# File 'lib/agent/handler/sequence_book.rb', line 6

def listenFlag
  @listenFlag
end

#openTrackerObject (readonly)

Returns the value of attribute openTracker.



6
7
8
# File 'lib/agent/handler/sequence_book.rb', line 6

def openTracker
  @openTracker
end

#rootTrackerObject (readonly)

Returns the value of attribute rootTracker.



6
7
8
# File 'lib/agent/handler/sequence_book.rb', line 6

def rootTracker
  @rootTracker
end

#trackerCountObject (readonly)

Returns the value of attribute trackerCount.



6
7
8
# File 'lib/agent/handler/sequence_book.rb', line 6

def trackerCount
  @trackerCount
end

Instance Method Details

#addExceptionInfo(exception) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/agent/handler/sequence_book.rb', line 93

def addExceptionInfo(exception)
  begin
    if @exceptionBag == nil
      @exceptionBag = Set.new
    end
    if (@exceptionBag.size() < 10)
      exceptionRecord = ::APMInsight::Errors::ExceptionRecord.new(exception)
      @exceptionBag.add(exceptionRecord)
    end
  rescue Exception=>e
  end
end

#attachTracker(tracker) ⇒ Object



19
20
21
22
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
# File 'lib/agent/handler/sequence_book.rb', line 19

def attachTracker tracker
  if tracker == nil
    return nil
  end
  
  # If RootTracker is not set, check type and set
  if @rootTracker == nil
    if !tracker.is_a?(ManageEngine::Tracker::RootTracker)
      closeSequence()
      return nil
    end
    @rootTracker = tracker
    updateListenFlag()
  end
  
  tracker.setParent(openTracker)
  @openTracker = tracker
  
  
  # Attach tracker as Sibling or Child and set nominee
#        if @closedTracker != nil
#          tracker.sibling = @closedTracker
#          @closedTracker.sibling = tracker # Nominee - if dropped/corrupted, defaults to this tracker
#          @openTracker = tracker
#          @closedTracker = nil
#        else
#          if tracker.equal?(@openTracker)
#            return nil
#          end
#          
#          @openTracker.child = tracker
#          tracker.sibling = @openTracker
#          @openTracker = tracker
#        end
  
  checkAndArrestSequence()
  
  return tracker
end

#checkAndArrestSequenceObject



114
115
116
117
118
119
120
121
# File 'lib/agent/handler/sequence_book.rb', line 114

def checkAndArrestSequence
  @trackerCount += 1
  if @trackerCount == 1000
    @listenFlag = 1
  end
  
  ## Can check for timeout
end

#closeSequenceObject



85
86
87
88
89
90
91
# File 'lib/agent/handler/sequence_book.rb', line 85

def closeSequence
  @rootTracker = nil
  @openTracker = @closedTracker = nil
  @trackerCount = 0
  @closedTrackerCount = 0
  Thread.current[:apminsight] = nil
end

#closeTracker(tracker) ⇒ Object



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
# File 'lib/agent/handler/sequence_book.rb', line 59

def closeTracker tracker
#        @closedTrackerCount += 1
#        @closedTracker = tracker
#        tracker.sibling = nil
#        @openTracker = nil
  @openTracker = tracker.parent;
  
  # Marks end of transaction
#        if @rootTracker == tracker
  if @openTracker == nil 
    if @listenFlag < 1 || (@listenFlag >= 1 && @trackerCount > 0)
      # if some trackers are not closed, while processing the metrics, it may go into infinite loop
#            if (@closedTrackerCount - @trackerCount) == 0
        sequenceBag = Hash.new
        sequenceBag["roottracker"] = @rootTracker
        sequenceBag["exceptions"] = @exceptionBag
        
        ManageEngine::APMObjectHolder.instance.collector.updateTransaction(@rootTracker.url, sequenceBag)
#            else
#              ManageEngine::APMObjectHolder.instance.log.warn "Some trackers are not closed, dropping the metrics for #{@rootTracker.url}"
#            end
    end
    closeSequence()
  end
end

#createDummyTrackerObject



123
124
125
# File 'lib/agent/handler/sequence_book.rb', line 123

def createDummyTracker
  return ManageEngine::Tracker::DefaultTracker.new("dummy")
end

#updateListenFlagObject



106
107
108
109
110
111
112
# File 'lib/agent/handler/sequence_book.rb', line 106

def updateListenFlag
  if !ManageEngine::APMObjectHolder.instance.txn_util.listen?(@rootTracker.url())
    @listenFlag = 1
  end
  
  ## Check for sampling factor & for bg txn chk if enabled
end