@@ -15,6 +15,8 @@ var ReservoirSampler = require('./reservoir_sampler')
15
15
var Profiler = require ( './profiler' )
16
16
var Control = require ( './control' )
17
17
18
+ var Timer = require ( './timer' )
19
+
18
20
var controlBus = new EventEmitter ( )
19
21
20
22
var REQUEST_ID = 'request-id'
@@ -28,13 +30,6 @@ function Agent (options) {
28
30
this . collectorApi = CollectorApi . create ( options . config )
29
31
// config
30
32
this . config = options . config
31
- this . collectInterval = this . config . collectInterval
32
-
33
- this . totalRequestCount = 0
34
- this . mustCollectCount = 0
35
-
36
- // init required variables
37
- this . partials = { }
38
33
39
34
this . apmMetrics = Metrics . apm . create ( {
40
35
collectorApi : this . collectorApi ,
@@ -79,29 +74,66 @@ function Agent (options) {
79
74
controlBus : controlBus
80
75
} )
81
76
77
+ // TODO: The Tracer agent, to be extracted
78
+ this . name = 'Tracer'
79
+
80
+ this . collectInterval = this . config . collectInterval
81
+
82
+ this . totalRequestCount = 0
83
+ this . mustCollectCount = 0
84
+
85
+ // init required variables
86
+ this . partials = { }
87
+
88
+ this . reservoirSampler = new ReservoirSampler ( MUST_COLLECT_LIMIT )
89
+
90
+ this . timer = new Timer ( function ( ) {
91
+ _this . _send ( )
92
+ } , this . collectInterval )
93
+
94
+ this . tracer = this
95
+
96
+ //
97
+
98
+ this . agents = [
99
+ this . tracer ,
100
+ this . apmMetrics ,
101
+ this . healthcheck ,
102
+ this . rpmMetrics ,
103
+ this . externalEdgeMetrics ,
104
+ this . incomingEdgeMetrics ,
105
+ this . memoryProfiler ,
106
+ this . cpuProfiler ,
107
+ this . control
108
+ ]
109
+ }
110
+
111
+ Agent . prototype . start = function ( ) {
112
+ var _this = this
82
113
this . collectorApi . getService ( function ( err , serviceKey ) {
83
114
if ( err ) {
84
115
return debug ( err . message )
85
116
}
86
117
debug ( 'Agent serviceKey is set to: ' , serviceKey )
87
118
_this . serviceKey = serviceKey
88
- _this . start ( )
119
+ _this . _startAll ( )
89
120
} )
90
-
91
- this . reservoirSampler = new ReservoirSampler ( MUST_COLLECT_LIMIT )
92
121
}
93
122
94
- Agent . prototype . start = function ( ) {
95
- var _this = this
96
- debug ( 'Agent started collecting' )
97
- this . transactionIntervalId = setInterval ( function ( ) {
98
- _this . _send ( )
99
- } , this . collectInterval )
123
+ Agent . prototype . _startAll = function ( ) {
124
+ this . agents . forEach ( function ( agent ) {
125
+ debug ( agent . name + ' started' )
126
+ if ( agent . timer != null ) {
127
+ agent . timer . start ( )
128
+ }
129
+ } )
100
130
}
101
131
102
- Agent . prototype . stop = function ( ) {
103
- debug ( 'Agent stopped collecting' )
104
- clearInterval ( this . transactionIntervalId )
132
+ Agent . prototype . _stopAll = function ( ) {
133
+ this . agents . forEach ( function ( agent ) {
134
+ debug ( agent . name + ' stopped' )
135
+ agent . timer . end ( )
136
+ } )
105
137
}
106
138
107
139
Agent . prototype . getServiceKey = function ( ) {
0 commit comments