whatap 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/README.md +32 -78
  2. package/lib/conf/conf-sys-mon.js +101 -0
  3. package/lib/conf/config-default.js +10 -3
  4. package/lib/conf/configure.js +369 -349
  5. package/lib/conf/license.js +1 -1
  6. package/lib/control/cmd-config.js +24 -0
  7. package/lib/control/control-handler.js +367 -0
  8. package/lib/control/packagectr-helper.js +34 -3
  9. package/lib/core/agent.js +176 -882
  10. package/lib/core/interceptor.js +6 -6
  11. package/lib/core/request-agent.js +27 -0
  12. package/lib/core/shimmer.js +82 -36
  13. package/lib/counter/counter-manager.js +79 -8
  14. package/lib/counter/meter/meter-activex.js +67 -0
  15. package/lib/counter/meter/meter-httpc.js +57 -0
  16. package/lib/counter/meter/meter-resource.js +9 -0
  17. package/lib/counter/meter/meter-service.js +168 -0
  18. package/lib/counter/meter/meter-socket.io.js +51 -0
  19. package/lib/counter/meter/meter-sql.js +71 -0
  20. package/lib/counter/meter/meter-users.js +58 -0
  21. package/lib/counter/meter.js +183 -0
  22. package/lib/counter/task/activetransaction.js +68 -17
  23. package/lib/counter/task/agentinfo.js +107 -0
  24. package/lib/{system → counter/task}/gc-action.js +27 -74
  25. package/lib/counter/task/gcstat.js +34 -0
  26. package/lib/counter/task/heapmem.js +25 -0
  27. package/lib/counter/task/httpc.js +76 -0
  28. package/lib/counter/task/metering-info.js +125 -0
  29. package/lib/counter/task/proc-cpu.js +29 -0
  30. package/lib/counter/task/realtimeuser.js +31 -0
  31. package/lib/counter/task/res/systemECSTask.js +39 -0
  32. package/lib/counter/task/res/systemKubeTask.js +53 -0
  33. package/lib/counter/task/res/util/awsEcsClientThread.js +218 -0
  34. package/lib/counter/task/res/util/linuxProcStatUtil.js +14 -0
  35. package/lib/counter/task/res-sys-cpu.js +62 -0
  36. package/lib/counter/task/service.js +202 -0
  37. package/lib/counter/task/socketio.js +30 -0
  38. package/lib/counter/task/sql.js +105 -0
  39. package/lib/counter/task/systemperf.js +43 -0
  40. package/lib/data/datapack-sender.js +289 -0
  41. package/lib/data/dataprofile-agent.js +162 -0
  42. package/lib/data/datatext-agent.js +135 -0
  43. package/lib/data/event-level.js +15 -0
  44. package/lib/data/test.js +49 -0
  45. package/lib/data/zipprofile.js +197 -0
  46. package/lib/env/constants.js +21 -0
  47. package/lib/error/error-handler.js +437 -0
  48. package/lib/io/data-inputx.js +13 -3
  49. package/lib/io/data-outputx.js +268 -206
  50. package/lib/kube/kube-client.js +144 -0
  51. package/lib/lang/text-types.js +58 -0
  52. package/lib/logger.js +6 -6
  53. package/lib/logsink/line-log-util.js +87 -0
  54. package/lib/logsink/line-log.js +12 -0
  55. package/lib/logsink/log-sender.js +78 -0
  56. package/lib/logsink/log-tracer.js +40 -0
  57. package/lib/logsink/sender-util.js +56 -0
  58. package/lib/logsink/zip/zip-send.js +177 -0
  59. package/lib/net/netflag.js +55 -0
  60. package/lib/net/receiver.js +66 -0
  61. package/lib/net/security-master.js +139 -20
  62. package/lib/net/sender.js +141 -0
  63. package/lib/net/tcp-return.js +18 -0
  64. package/lib/net/tcp-session.js +286 -0
  65. package/lib/net/tcpreq-client-proxy.js +70 -0
  66. package/lib/net/tcprequest-mgr.js +58 -0
  67. package/lib/observers/apollo-server-observer.js +33 -27
  68. package/lib/observers/cluster-observer.js +22 -0
  69. package/lib/observers/express-observer.js +215 -0
  70. package/lib/observers/file-observer.js +184 -0
  71. package/lib/observers/global-observer.js +155 -80
  72. package/lib/observers/grpc-observer.js +336 -0
  73. package/lib/observers/http-observer.js +666 -236
  74. package/lib/observers/maria-observer.js +204 -362
  75. package/lib/observers/memcached-observer.js +56 -0
  76. package/lib/observers/mongo-observer.js +317 -0
  77. package/lib/observers/mongodb-observer.js +169 -226
  78. package/lib/observers/mongoose-observer.js +518 -323
  79. package/lib/observers/mssql-observer.js +177 -418
  80. package/lib/observers/mysql-observer.js +342 -449
  81. package/lib/observers/mysql2-observer.js +396 -358
  82. package/lib/observers/net-observer.js +77 -0
  83. package/lib/observers/oracle-observer.js +559 -384
  84. package/lib/observers/pgsql-observer.js +231 -489
  85. package/lib/observers/prisma-observer.js +303 -92
  86. package/lib/observers/process-observer.js +79 -35
  87. package/lib/observers/promise-observer.js +31 -0
  88. package/lib/observers/redis-observer.js +166 -331
  89. package/lib/observers/schedule-observer.js +67 -0
  90. package/lib/observers/socket.io-observer.js +226 -187
  91. package/lib/observers/stream-observer.js +19 -0
  92. package/lib/observers/thrift-observer.js +197 -0
  93. package/lib/observers/websocket-observer.js +175 -301
  94. package/lib/pack/activestack-pack.js +55 -0
  95. package/lib/pack/apenum.js +8 -0
  96. package/lib/pack/counter-pack.js +3 -0
  97. package/lib/pack/errorsnap-pack.js +69 -0
  98. package/lib/pack/event-pack.js +54 -0
  99. package/lib/pack/hitmap-pack.js +63 -0
  100. package/lib/pack/hitmap-pack1.js +152 -0
  101. package/lib/pack/log-sink-pack.js +14 -52
  102. package/lib/pack/netstat.js +15 -0
  103. package/lib/pack/otype.js +7 -0
  104. package/lib/pack/profile-pack.js +49 -0
  105. package/lib/pack/realtimeuser-pack.js +41 -0
  106. package/lib/pack/stat-general-pack.js +96 -0
  107. package/lib/pack/staterror-pack.js +120 -0
  108. package/lib/pack/stathttpc-pack.js +66 -0
  109. package/lib/pack/stathttpc-rec.js +78 -0
  110. package/lib/pack/statremote-pack.js +46 -0
  111. package/lib/pack/statservice-pack.js +63 -0
  112. package/lib/pack/statservice-pack1.js +88 -0
  113. package/lib/pack/statservice-rec.js +292 -0
  114. package/lib/pack/statservice-rec_dep.js +151 -0
  115. package/lib/pack/statsql-pack.js +69 -0
  116. package/lib/pack/statsql-rec.js +100 -0
  117. package/lib/pack/statuseragent-pack.js +44 -0
  118. package/lib/pack/tagcount-pack.js +4 -4
  119. package/lib/pack/tagctr.js +15 -0
  120. package/lib/pack/text-pack.js +50 -0
  121. package/lib/pack/time-count.js +25 -0
  122. package/lib/pack/websocket.js +15 -0
  123. package/lib/pack/zip-pack.js +70 -0
  124. package/lib/pii/pii-item.js +31 -0
  125. package/lib/pii/pii-mask.js +174 -0
  126. package/lib/plugin/plugin-loadermanager.js +57 -0
  127. package/lib/plugin/plugin.js +75 -0
  128. package/lib/service/tx-record.js +332 -0
  129. package/lib/stat/stat-error.js +116 -0
  130. package/lib/stat/stat-httpc.js +98 -0
  131. package/lib/stat/stat-remote-ip.js +46 -0
  132. package/lib/stat/stat-remote-ipurl.js +88 -0
  133. package/lib/stat/stat-sql.js +113 -0
  134. package/lib/stat/stat-tranx.js +58 -0
  135. package/lib/stat/stat-tx-caller.js +160 -0
  136. package/lib/stat/stat-tx-domain.js +111 -0
  137. package/lib/stat/stat-tx-referer.js +112 -0
  138. package/lib/stat/stat-useragent.js +48 -0
  139. package/lib/stat/timingsender.js +76 -0
  140. package/lib/step/activestack-step.js +38 -0
  141. package/lib/step/dbc-step.js +36 -0
  142. package/lib/step/http-stepx.js +67 -0
  143. package/lib/step/message-step.js +40 -0
  144. package/lib/step/method-stepx.js +45 -0
  145. package/lib/step/resultset-step.js +40 -0
  146. package/lib/step/securemsg-step.js +44 -0
  147. package/lib/step/socket-step.js +46 -0
  148. package/lib/step/sql-stepx.js +68 -0
  149. package/lib/step/sqlxtype.js +16 -0
  150. package/lib/step/step.js +66 -0
  151. package/lib/step/stepenum.js +54 -0
  152. package/lib/topology/link.js +63 -0
  153. package/lib/topology/nodeinfo.js +123 -0
  154. package/lib/topology/status-detector.js +111 -0
  155. package/lib/trace/trace-context-manager.js +113 -25
  156. package/lib/trace/trace-context.js +21 -7
  157. package/lib/trace/trace-httpc.js +17 -11
  158. package/lib/trace/trace-sql.js +29 -21
  159. package/lib/util/anylist.js +103 -0
  160. package/lib/util/cardinality/hyperloglog.js +106 -0
  161. package/lib/util/cardinality/murmurhash.js +31 -0
  162. package/lib/util/cardinality/registerset.js +75 -0
  163. package/lib/util/errordata.js +21 -0
  164. package/lib/util/escape-literal-sql.js +5 -5
  165. package/lib/util/hashutil.js +18 -18
  166. package/lib/util/iputil_x.js +527 -0
  167. package/lib/util/keygen.js +0 -3
  168. package/lib/util/kube-util.js +73 -0
  169. package/lib/util/linkedset.js +1 -2
  170. package/lib/util/nodeutil.js +2 -1
  171. package/lib/util/paramsecurity.js +80 -0
  172. package/lib/util/pre-process.js +13 -0
  173. package/lib/util/process-seq.js +166 -0
  174. package/lib/util/property-util.js +36 -0
  175. package/lib/util/request-queue.js +70 -0
  176. package/lib/util/requestdouble-queue.js +72 -0
  177. package/lib/util/resourceprofile.js +157 -0
  178. package/lib/util/stop-watch.js +30 -0
  179. package/lib/util/system-util.js +10 -0
  180. package/lib/util/userid-util.js +57 -0
  181. package/lib/value/map-value.js +3 -2
  182. package/package.json +9 -4
  183. package/whatap.conf +1 -4
  184. package/agent/darwin/arm64/whatap_nodejs +0 -0
  185. package/agent/linux/amd64/whatap_nodejs +0 -0
  186. package/agent/linux/arm64/whatap_nodejs +0 -0
  187. package/build.txt +0 -4
  188. package/lib/observers/ioredis-observer.js +0 -294
  189. package/lib/udp/async_sender.js +0 -119
  190. package/lib/udp/index.js +0 -17
  191. package/lib/udp/packet_enum.js +0 -52
  192. package/lib/udp/packet_queue.js +0 -69
  193. package/lib/udp/packet_type_enum.js +0 -33
  194. package/lib/udp/param_def.js +0 -72
  195. package/lib/udp/udp_session.js +0 -336
  196. package/lib/util/sql-util.js +0 -178
  197. package/lib/util/trace-helper.js +0 -91
  198. package/lib/util/transfer.js +0 -58
@@ -35,7 +35,7 @@ Interceptor.prototype.before = function(obj, funcs, advice, isCallback) {
35
35
  try {
36
36
  advice(this, arguments);
37
37
  } catch (e) {
38
- Logger.printError("WHATAP-114", "Interceptor error", e);
38
+ Logger.printError("WHATAP-500", "Interceptor error", e);
39
39
  }
40
40
  return orig.apply(this, arguments);
41
41
  }
@@ -60,7 +60,7 @@ Interceptor.prototype.after = function(obj, funcs, advice) {
60
60
  try {
61
61
  funcRet = advice(this, arguments, ret);
62
62
  } catch(e) {
63
- Logger.printError('WHATAP-115', 'Interceptor after error', e);
63
+ Logger.printError('WHATAP-177', 'Interceptor after error', e);
64
64
  }
65
65
 
66
66
  return funcRet || ret;
@@ -90,7 +90,7 @@ Interceptor.prototype.both = function(obj, funcs, beforeFunc, afterFunc) {
90
90
  try {
91
91
  beforeFunc(this, arguments, local_ctx);
92
92
  } catch(e) {
93
- Logger.printError('WHATAP-116', 'Interceptor both before error', e);
93
+ Logger.printError('WHATAP-178', 'Interceptor both before error', e);
94
94
  }
95
95
 
96
96
  var ret = orig.apply(this, arguments);
@@ -100,7 +100,7 @@ Interceptor.prototype.both = function(obj, funcs, beforeFunc, afterFunc) {
100
100
  funcRet = afterFunc(this, arguments, ret, local_ctx);
101
101
  }
102
102
  } catch(e) {
103
- Logger.printError("WHATAP-117", "Interceptor both after error", e);
103
+ Logger.printError("WHATAP-501", "Interceptor both after error", e);
104
104
  }
105
105
 
106
106
  return funcRet || ret;
@@ -122,7 +122,7 @@ Interceptor.prototype.functionHook = function(args, pos, beforeFunc, afterFunc)
122
122
  try {
123
123
  beforeFunc(this, arguments);
124
124
  } catch(e) {
125
- Logger.printError("WHATAP-118", 'Interceptor functionhook before error', e);
125
+ Logger.printError("WHATAP-179", 'Interceptor functionhook before error', e);
126
126
  }
127
127
  }
128
128
 
@@ -132,7 +132,7 @@ Interceptor.prototype.functionHook = function(args, pos, beforeFunc, afterFunc)
132
132
  try {
133
133
  afterFunc(this, arguments, result);
134
134
  } catch(e) {
135
- Logger.printError("WHATAP-119", 'Interceptor functionhook after error', e);
135
+ Logger.printError("WHATAP-180", 'Interceptor functionhook after error', e);
136
136
  }
137
137
  }
138
138
  return result;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright 2016 the WHATAP project authors. All rights reserved.
3
+ * Use of this source code is governed by a license that
4
+ * can be found in the LICENSE file.
5
+ */
6
+
7
+
8
+ const http = require('http');
9
+ var keepAliveAgent = new http.Agent({ keepAlive: true });
10
+
11
+
12
+ var baseConfig = {
13
+ keepAlive: true,
14
+ keepAliveTimeoutMsecs: 500,
15
+ maxSockets: 1 // requests are serialized
16
+ }
17
+
18
+ baseConfig.agent = keepAliveAgent;
19
+
20
+
21
+ http.request(baseConfig, onResponseCallback);
22
+
23
+
24
+
25
+ var RequestAgent = function(){
26
+
27
+ }
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
 
3
- function isFunction (funktion) {
3
+ function isFunction(funktion) {
4
4
  return typeof funktion === 'function'
5
5
  }
6
6
 
7
- function defineProperty (obj, name, value) {
7
+ function defineProperty(obj, name, value) {
8
8
  var enumerable = !!obj[name] && obj.propertyIsEnumerable(name)
9
9
  Object.defineProperty(obj, name, {
10
10
  configurable: true,
@@ -14,10 +14,28 @@ function defineProperty (obj, name, value) {
14
14
  })
15
15
  }
16
16
 
17
- var shimmer = function () {
18
- }
17
+ var shimmer = function() {}
18
+
19
+ /**
20
+ * Wrap a single method or multiple methods with the provided wrapper function
21
+ *
22
+ * @param {Object} nodule - The object containing methods to wrap
23
+ * @param {string|Array<string>} name - Method name or array of method names to wrap
24
+ * @param {Function} wrapper - The wrapper function
25
+ * @returns {Function|Array<Function>} - The wrapped function(s)
26
+ */
27
+ var wrap = function(nodule, name, wrapper) {
28
+ // If name is an array, recursively call wrap for each name in the array
29
+ if (Array.isArray(name)) {
30
+ var wrapped = [];
31
+ name.forEach(function(methodName) {
32
+ var result = wrap(nodule, methodName, wrapper);
33
+ if (result) wrapped.push(result);
34
+ });
35
+ return wrapped.length > 0 ? wrapped : undefined;
36
+ }
19
37
 
20
- var wrap = function (nodule, name, wrapper) {
38
+ // Standard single method wrap logic
21
39
  if (!nodule || !nodule[name]) {
22
40
  return;
23
41
  }
@@ -27,67 +45,95 @@ var wrap = function (nodule, name, wrapper) {
27
45
  }
28
46
 
29
47
  if (!isFunction(nodule[name]) || !isFunction(wrapper)) {
30
- return
48
+ return;
31
49
  }
32
50
 
33
- var original = nodule[name]
34
- var wrapped = wrapper(original, name)
51
+ var original = nodule[name];
52
+ var wrapped = wrapper(original, name);
35
53
 
36
- defineProperty(wrapped, '__original', original)
37
- defineProperty(wrapped, '__unwrap', function () {
38
- if (nodule[name] === wrapped) defineProperty(nodule, name, original)
39
- })
40
- defineProperty(wrapped, '__wrapped', true)
54
+ defineProperty(wrapped, '__original', original);
55
+ defineProperty(wrapped, '__unwrap', function() {
56
+ if (nodule[name] === wrapped) defineProperty(nodule, name, original);
57
+ });
58
+ defineProperty(wrapped, '__wrapped', true);
41
59
 
42
- defineProperty(nodule, name, wrapped)
43
- return wrapped
60
+ defineProperty(nodule, name, wrapped);
61
+ return wrapped;
44
62
  }
45
63
 
46
- function unwrap (nodule, name) {
64
+ /**
65
+ * Unwrap a single method or multiple methods
66
+ *
67
+ * @param {Object} nodule - The object containing wrapped methods
68
+ * @param {string|Array<string>} name - Method name or array of method names to unwrap
69
+ */
70
+ function unwrap(nodule, name) {
71
+ // If name is an array, recursively call unwrap for each name in the array
72
+ if (Array.isArray(name)) {
73
+ name.forEach(function(methodName) {
74
+ unwrap(nodule, methodName);
75
+ });
76
+ return;
77
+ }
78
+
47
79
  if (!nodule || !nodule[name]) {
48
- return
80
+ return;
49
81
  }
50
82
 
51
83
  if (!nodule[name].__unwrap) {
84
+ // Method is not wrapped
52
85
  } else {
53
- return nodule[name].__unwrap()
86
+ return nodule[name].__unwrap();
54
87
  }
55
88
  }
56
89
 
57
- function massWrap (nodules, names, wrapper) {
90
+ /**
91
+ * Wrap multiple methods of multiple modules with the same wrapper
92
+ *
93
+ * @param {Object|Array<Object>} nodules - Module or array of modules with methods to wrap
94
+ * @param {Array<string>} names - Array of method names to wrap
95
+ * @param {Function} wrapper - The wrapper function to apply
96
+ */
97
+ function massWrap(nodules, names, wrapper) {
58
98
  if (!nodules) {
59
- return
99
+ return;
60
100
  } else if (!Array.isArray(nodules)) {
61
- nodules = [nodules]
101
+ nodules = [nodules];
62
102
  }
63
103
 
64
104
  if (!(names && Array.isArray(names))) {
65
- return
105
+ return;
66
106
  }
67
107
 
68
- nodules.forEach(function (nodule) {
69
- names.forEach(function (name) {
70
- wrap(nodule, name, wrapper)
71
- })
72
- })
108
+ nodules.forEach(function(nodule) {
109
+ names.forEach(function(name) {
110
+ wrap(nodule, name, wrapper);
111
+ });
112
+ });
73
113
  }
74
114
 
75
- function massUnwrap (nodules, names) {
115
+ /**
116
+ * Unwrap multiple methods of multiple modules
117
+ *
118
+ * @param {Object|Array<Object>} nodules - Module or array of modules with wrapped methods
119
+ * @param {Array<string>} names - Array of method names to unwrap
120
+ */
121
+ function massUnwrap(nodules, names) {
76
122
  if (!nodules) {
77
- return
123
+ return;
78
124
  } else if (!Array.isArray(nodules)) {
79
- nodules = [nodules]
125
+ nodules = [nodules];
80
126
  }
81
127
 
82
128
  if (!(names && Array.isArray(names))) {
83
- return
129
+ return;
84
130
  }
85
131
 
86
- nodules.forEach(function (nodule) {
87
- names.forEach(function (name) {
88
- unwrap(nodule, name)
89
- })
90
- })
132
+ nodules.forEach(function(nodule) {
133
+ names.forEach(function(name) {
134
+ unwrap(nodule, name);
135
+ });
136
+ });
91
137
  }
92
138
 
93
139
  shimmer.wrap = wrap;
@@ -4,32 +4,70 @@
4
4
  * can be found in the LICENSE file.
5
5
  */
6
6
 
7
- var TraceContextManager = require('../trace/trace-context-manager'),
7
+ var CounterPack = require('../pack/counter-pack'),
8
+ Service = require('./task/service'),
9
+ AgentInfo = require('./task/agentinfo'),
10
+ ActiveTransaction = require('./task/activetransaction'),
11
+ ProcCpu = require('./task/proc-cpu'),
12
+ ResSysCpu = require('./task/res-sys-cpu'),
13
+ HeapMem = require('./task/heapmem'),
14
+ SystemPerf = require('./task/systemperf'),
15
+ RealtimeUser = require('./task/realtimeuser'),
16
+ Socketio = require('./task/socketio'),
17
+ GCStat = require('./task/gcstat'),
18
+ Sql = require('./task/sql'),
19
+ HttpC = require('./task/httpc'),
20
+ MeteringInfo = require('./task/metering-info'),
21
+ GCAction = require('./task/gc-action'),
22
+ StatError = require('../stat/stat-error'),
23
+ TagCounterPack = require('../pack/tagcount-pack'),
24
+ TraceContextManager = require('../trace/trace-context-manager'),
8
25
  secuMaster = require('../net/security-master'),
26
+ DataPackSender = require('../data/datapack-sender'),
9
27
  conf = require('../conf/configure'),
10
28
  DateUtil = require('./../util/dateutil'),
11
- Logger = require('../logger'),
12
- GCAction = require('../system/gc-action');
29
+ KubeClient = require('../kube/kube-client'),
30
+ KubeUtil = require('../util/kube-util'),
31
+ Logger = require('../logger');
13
32
 
14
33
  function CounterManager(agent) {
15
34
  this.agent = agent;
16
35
  this.time = Date.now();
17
-
36
+
18
37
  this.intervalIndex = undefined;
19
38
  };
20
39
  CounterManager.plugin={}
21
40
  CounterManager.prototype.run = function () {
22
- let self = this;
41
+ var self = this;
42
+
23
43
  process.nextTick(function () {
24
44
  var tasks = [];
45
+ tasks.push(new Service());
46
+ tasks.push(new AgentInfo());
47
+ tasks.push(new ActiveTransaction());
48
+ tasks.push(new RealtimeUser());
49
+ tasks.push(new HeapMem());
50
+ tasks.push(new ProcCpu());
51
+ tasks.push(new ResSysCpu());
52
+ tasks.push(new SystemPerf());
53
+ tasks.push(new Socketio());
54
+ tasks.push(new GCStat());
55
+ tasks.push(new Sql());
56
+ tasks.push(new HttpC());
25
57
  tasks.push(new GCAction());
26
58
 
59
+ // metering
60
+ tasks.push(new MeteringInfo());
27
61
  self.intervalIndex = setInterval(function(){
28
62
  self.process(tasks);
29
63
  },5000);
30
-
31
64
  self.process(tasks);
32
65
  });
66
+
67
+ if(conf.whatap_micro_enabled || process.env.WHATAP_MICRO_ENABLED === "true"){
68
+ KubeUtil.loadContainerId();
69
+ if (conf.enabled_master_agent_call) KubeClient.run();
70
+ }
33
71
  };
34
72
  CounterManager.prototype.stop = function(){
35
73
  if(this.intervalIndex){
@@ -52,16 +90,49 @@ CounterManager.prototype.process = function (tasks) {
52
90
  return;
53
91
  }
54
92
 
93
+ var enumer = TraceContextManager.getContextEnumeration();
94
+ while (enumer.hasMoreElements()) {
95
+ var ctx = enumer.nextElement();
96
+ if (ctx.getElapsedTime() > conf.profile_max_time) {
97
+ //TraceContextManager.end(ctx._id);
98
+ if(conf.getProperty("ignore_http_lost_connection", false) === true){
99
+ Logger.print("WHATAP-072", "Lost Connection was ignored, " + ctx._id, false);
100
+ TraceContextManager.end(ctx._id);
101
+ ctx = null;
102
+ }else{
103
+ // var obj = TraceContextManager.resume(ctx._id);
104
+ TraceContextManager.addStep("Lost Connection","", ctx);
105
+ //ctx.status = 5;
106
+ //ctx.error = StatError.addError(500, "Lost Connection", ctx.service_hash);
107
+ TraceContextManager.endTrace(ctx);
108
+ }
109
+ }
110
+ }
111
+
55
112
  if (conf.counter_enabled) {
113
+ var pack = new CounterPack();
114
+ pack.pcode = secuMaster.PCODE;
115
+ pack.oid = secuMaster.OID;
116
+ pack.time = Math.floor(DateUtil.currentTime() / 5000) * 5000;
117
+ pack.duration = Math.floor(interval / 1000);
56
118
  for (var i = 0; i < len; i++) {
57
119
  task = tasks[i];
58
120
  try{
59
- task.process();
121
+ task.process(pack);
60
122
  } catch (e) {
61
- Logger.printError('WHATAP-603', 'Counter Manager process ', e, true);
123
+ Logger.printError('WHATAP-070', 'Counter Manager process ', e, true);
62
124
  }
63
125
  }
126
+ pack.starttime = this.agent.starttime;
64
127
 
128
+ try {
129
+ if (CounterManager.plugin["extra"]) {
130
+ CounterManager.plugin["extra"](pack);
131
+ }
132
+ } catch (e) {
133
+ Logger.printError('WHATAP-071', 'Counter Manager Plugin ', e, true);
134
+ }
135
+ DataPackSender.sendCounterPack(pack);
65
136
  }
66
137
  };
67
138
 
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Copyright 2016 the WHATAP project authors. All rights reserved.
3
+ * Use of this source code is governed by a license that
4
+ * can be found in the LICENSE file.
5
+ */
6
+
7
+ var conf = require('../../conf/configure'),
8
+ IntIntMap = require('../../util/intint-map'),
9
+ secuMaster = require('../../net/security-master'),
10
+ LinkedMap = require('../../util/linkedmap');
11
+
12
+
13
+ function MeterActiveX() {
14
+ this.statByOid = new IntIntMap().setMax(2001);
15
+ this.statByGroup = createLinkedMap();
16
+ this.stat_sql = new IntIntMap().setMax(301);
17
+ this.stat_httpc = new IntIntMap().setMax(301);
18
+ this.unknown = 0;
19
+ }
20
+
21
+ MeterActiveX.prototype.addTx = function (caller_pcode, caller_okind, caller_oid) {
22
+ if (caller_oid) {
23
+ this.statByGroup.add({pcode:caller_pcode, okind:caller_okind}, 1);
24
+ if (caller_pcode == secuMaster.PCODE) {
25
+ this.statByOid.add(caller_oid, 1);
26
+ }
27
+ } else {
28
+ this.unknown++;
29
+ }
30
+
31
+ };
32
+ MeterActiveX.prototype.addSql = function (dbc) {
33
+ this.stat_sql.add(dbc, 1);
34
+ };
35
+
36
+ MeterActiveX.prototype.addHttpc = function (host) {
37
+ this.stat_httpc.add(host, 1);
38
+ };
39
+
40
+ MeterActiveX.prototype.reinit = function () {
41
+ this.statByOid = new IntIntMap().setMax(2001);
42
+ this.statByGroup = createLinkedMap();
43
+ this.stat_sql = new IntIntMap().setMax(301);
44
+ this.stat_httpc = new IntIntMap().setMax(301);
45
+ this.unknown = 0;
46
+ };
47
+
48
+
49
+ function createLinkedMap() {
50
+ var m = new LinkedMap(1009, 1).setMax(307);
51
+ m.hash = function (k) {
52
+ if (k._hash_) {
53
+ return k._hash_;
54
+ }
55
+ var result = 1;
56
+ result = 31 * result + k.pcode;
57
+ result = 31 * result + k.okind;
58
+
59
+ k._hash_ = result;
60
+ return result;
61
+ };
62
+ m.equals = function (k1, k2) {
63
+ return k1.pcode === k2.pcode && k1.okind === k2.okind;
64
+ };
65
+ return m;
66
+ }
67
+ module.exports = new MeterActiveX();
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Copyright 2016 the WHATAP project authors. All rights reserved.
3
+ * Use of this source code is governed by a license that
4
+ * can be found in the LICENSE file.
5
+ */
6
+
7
+ var IntKeyLinkedMap = require('../../util/intkey-linkedmap');
8
+ var Long = require('long');
9
+ var Logger = require('../../logger');
10
+ var conf = require('../../conf/configure');
11
+
12
+ function Bucket() {
13
+ this.count = 0;
14
+ this.time =0;
15
+ this.error = 0;
16
+ }
17
+
18
+ function MeterHttpC() {
19
+ this.bucket = new Bucket();
20
+ this.stat = new IntKeyLinkedMap(309, 1).setMax(307);
21
+ this.stat.create = function (key) {
22
+ return new Bucket();
23
+ };
24
+ }
25
+
26
+ MeterHttpC.prototype.add = function (host,elapsed, err) {
27
+ try {
28
+ var b = this.bucket;
29
+ b.count++;
30
+ b.time += elapsed;
31
+ if(err) {
32
+ b.error++;
33
+ }
34
+
35
+ if (conf.httpc_host_meter_enabled && host != 0) {
36
+ b = this.stat.intern(host);
37
+ b.count++;
38
+ b.time += elapsed;
39
+ if (err) {
40
+ b.error++;
41
+ }
42
+ }
43
+ } catch(e) {
44
+ Logger.printError("WHATAP-608", "MeterHttpC Error", e);
45
+ }
46
+ };
47
+ MeterHttpC.prototype.getBucketReset = function () {
48
+ var b = this.bucket;
49
+ this.bucket = new Bucket();
50
+ return b;
51
+ };
52
+ MeterHttpC.prototype.resetStat = function () {
53
+ if(this.stat.size() > 0){
54
+ this.stat.clear();
55
+ }
56
+ }
57
+ module.exports = new MeterHttpC();
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright 2016 the WHATAP project authors. All rights reserved.
3
+ * Use of this source code is governed by a license that
4
+ * can be found in the LICENSE file.
5
+ */
6
+
7
+ function MeterResource() {
8
+
9
+ };
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Copyright 2016 the WHATAP project authors. All rights reserved.
3
+ * Use of this source code is governed by a license that
4
+ * can be found in the LICENSE file.
5
+ */
6
+
7
+ var HitMapPack1 = require('../../pack/hitmap-pack1'),
8
+ IntKeyMap = require('../../util/intkey-map'),
9
+ SecurityMaster = require('../../net/security-master'),
10
+ conf = require('../../conf/configure'),
11
+ secu = require('../../net/security-master'),
12
+ IntKeyLinkedMap = require('../../util/intkey-linkedmap'),
13
+ LinkedMap = require('../../util/linkedmap'),
14
+ Logger = require('../../logger'),
15
+ EventLevel = require('../../data/event-level');
16
+ Long = require('long');
17
+
18
+ function Bucket () {
19
+ this.hitmap = new HitMapPack1();
20
+ this.count = 0;
21
+ this.timesum = 0;
22
+ this.error = 0;
23
+ this.count_satisfied = 0;
24
+ this.count_tolerated = 0;
25
+
26
+ this.reset = function () {
27
+ this.count = 0;
28
+ this.timesum = 0;
29
+ this.error = 0;
30
+ this.count_satisfied = 0;
31
+ this.count_tolerated = 0;
32
+ this.hitmap = new HitMapPack1();
33
+ };
34
+ }
35
+ function BucketSimple () {
36
+ this.count = 0;
37
+ this.timesum = 0;
38
+ this.error = 0;
39
+ this.count_satisfied = 0;
40
+ this.count_tolerated = 0;
41
+
42
+ this.reset = function () {
43
+ this.count = 0;
44
+ this.timesum =0;
45
+ this.error = 0;
46
+ this.count_satisfied = 0;
47
+ this.count_tolerated = 0;
48
+ };
49
+ }
50
+
51
+ function MeterService() {
52
+ if(typeof MeterService.instance === 'object') {
53
+ return MeterService.instance;
54
+ }
55
+ this.bucket = new Bucket();
56
+ this.unknown = new BucketSimple();
57
+ this.stat = new IntKeyLinkedMap(309, 1).setMax(307);
58
+ this.stat.create = function (key) {
59
+ return new BucketSimple();
60
+ };
61
+ this.statByGroup = new LinkedMap(309, 1).setMax(307);
62
+ this.statByGroup.create = function (key) {
63
+ return new BucketSimple();
64
+ };
65
+ this.statByGroup.hash = function (k) {
66
+ if(k._hash_){
67
+ return k._hash_;
68
+ }
69
+ var result = 1;
70
+ result = 31 * result + k.pcode;
71
+ result = 31 * result + k.okind;
72
+
73
+ k._hash_=result;
74
+ return result;
75
+ };
76
+ this.statByGroup.equals = function (k1,k2) {
77
+ return k1.pcode === k2.pcode && k1.okind === k2.okind;
78
+ };
79
+
80
+ MeterService.instance = this;
81
+ }
82
+
83
+ MeterService.prototype.add = function (serviceHash, elapsed, errorLevel, caller_pcode, caller_okind, caller_oid , apdex) {
84
+ if(elapsed < 0) {
85
+ elapsed = 0;
86
+ }
87
+
88
+ var b = this.bucket;
89
+ b.count += 1;
90
+ b.timesum +=elapsed;
91
+
92
+ var err = errorLevel >= EventLevel.WARNING;
93
+ if (err) {
94
+ b.error += 1;
95
+ } else {
96
+ if (elapsed <= conf.apdex_time_t) {
97
+ b.count_satisfied += 1;
98
+ apdex=2;
99
+ } else if (elapsed <= conf.apdex_time_4t) {
100
+ b.count_tolerated += 1;
101
+ apdex=1;
102
+ }
103
+ }
104
+ b.hitmap.add(elapsed, err);
105
+
106
+ if (conf.tx_caller_meter_enabled) {
107
+ try{
108
+ var b1 = null;
109
+ if( caller_oid) {
110
+ if (caller_pcode == SecurityMaster.PCODE) {
111
+ b1 = this.stat.intern(caller_oid);
112
+ b1.count++;
113
+ b1.timesum += elapsed;
114
+ if (err) {
115
+ b1.error++;
116
+ }
117
+ }
118
+
119
+ b1 = this.statByGroup.intern({pcode:caller_pcode, okind:caller_okind});
120
+ b1.count++;
121
+ b1.timesum += elapsed;
122
+ if (err) {
123
+ b1.error++;
124
+ }
125
+ }else {
126
+ b1 = this.unknown;
127
+ b1.count++;
128
+ b1.timesum += elapsed;
129
+ if (err) {
130
+ b1.error++;
131
+ }
132
+ }
133
+ }catch(e){
134
+ Logger.printError('WHATAP-080', 'Meter Service add ', e, true);
135
+ }
136
+ }
137
+ };
138
+ MeterService.prototype.getBucket = function () {
139
+ return this.bucket;
140
+ };
141
+ MeterService.prototype.resetStat = function () {
142
+ if(this.stat.size() > 0){
143
+ this.stat.clear();
144
+ }
145
+ if(this.statByGroup.size() > 0){
146
+ this.statByGroup.clear();
147
+ }
148
+ if (this.unknown.count > 0) {
149
+ this.unknown = new Bucket();
150
+ }
151
+ };
152
+
153
+ function TopService(hash) {
154
+ this.hash = hash | 0;
155
+ this.count = 0;
156
+ this.error = 0;
157
+ this.time = 0;
158
+
159
+ this.clear = function () {
160
+ this.count = 0;
161
+ this.error = 0;
162
+ this.time = 0;
163
+ };
164
+ };
165
+
166
+ module.exports.MeterService = new MeterService();
167
+ module.exports.Bucket = Bucket;
168
+ module.exports.TopService = TopService;