@@ -15,6 +15,8 @@ var ReservoirSampler = require('./reservoir_sampler')
1515var Profiler = require ( './profiler' )
1616var Control = require ( './control' )
1717
18+ var Timer = require ( './timer' )
19+
1820var controlBus = new EventEmitter ( )
1921
2022var REQUEST_ID = 'request-id'
@@ -28,13 +30,6 @@ function Agent (options) {
2830 this . collectorApi = CollectorApi . create ( options . config )
2931 // config
3032 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 = { }
3833
3934 this . apmMetrics = Metrics . apm . create ( {
4035 collectorApi : this . collectorApi ,
@@ -79,29 +74,66 @@ function Agent (options) {
7974 controlBus : controlBus
8075 } )
8176
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
82113 this . collectorApi . getService ( function ( err , serviceKey ) {
83114 if ( err ) {
84115 return debug ( err . message )
85116 }
86117 debug ( 'Agent serviceKey is set to: ' , serviceKey )
87118 _this . serviceKey = serviceKey
88- _this . start ( )
119+ _this . _startAll ( )
89120 } )
90-
91- this . reservoirSampler = new ReservoirSampler ( MUST_COLLECT_LIMIT )
92121}
93122
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+ } )
100130}
101131
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+ } )
105137}
106138
107139Agent . prototype . getServiceKey = function ( ) {
0 commit comments