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
@@ -0,0 +1,123 @@
1
+ const DataOutputX = require('../io/data-outputx');
2
+ const DataInputX = require('../io/data-inputx');
3
+ const MapValue = require('../value/map-value');
4
+ const LINK = require('./link');
5
+ const net = require('net');
6
+
7
+ function NodeInfo() {
8
+ this.attr = new MapValue();
9
+ this.listen = new Set();
10
+ this.outter = new Set();
11
+
12
+ this.addListen = function (localIPs, address) {
13
+ const ipo = this.getIPPORT(address);
14
+ if (!ipo || this.isLocal127(ipo)) return;
15
+
16
+ if (ipo.ip === '*' || ipo.ip === '0.0.0.0' || ipo.ip === '::') {
17
+ localIPs.forEach(local_ip => {
18
+ const k = LINK.create(local_ip, parseInt(ipo.port, 10));
19
+ if (k) this.listen.add(k);
20
+ });
21
+ } else {
22
+ const k = LINK.create(ipo.ip, parseInt(ipo.port, 10));
23
+ if (k) this.listen.add(k);
24
+ }
25
+ };
26
+
27
+ this.addOutter = function (local, remote) {
28
+ const localIPO = this.getIPPORT(local);
29
+ if (!localIPO || this.isIPv6(localIPO)) return;
30
+ if (this.hasListen(localIPO.ip, localIPO.port)) return;
31
+
32
+ const remoteIPO = this.getIPPORT(remote);
33
+ if (!remoteIPO || this.isIPv6(remoteIPO) || this.isLocal127(remoteIPO)) return;
34
+
35
+ const k = LINK.create(remoteIPO.ip, parseInt(remoteIPO.port, 10));
36
+ if (k) this.outter.add(k);
37
+ };
38
+
39
+ this.hasListen = function (ip, port) {
40
+ const k = LINK.create(ip, parseInt(port, 10));
41
+ return this.listen.has(k);
42
+ };
43
+
44
+ this.getIPPORT = function (address) {
45
+ try {
46
+ const ipo = {};
47
+ const x = address.lastIndexOf(':');
48
+ ipo.ip = address.substring(0, x);
49
+ ipo.port = address.substring(x + 1);
50
+ return ipo;
51
+ } catch (e) {
52
+ return null;
53
+ }
54
+ };
55
+
56
+ this.toBytes = function () {
57
+ const out = new DataOutputX();
58
+ out.writeByte(0);
59
+ out.writeValue(this.attr);
60
+ this.toLinkBytes(this.listen, out);
61
+ this.toLinkBytes(this.outter, out);
62
+ return out.toByteArray();
63
+ };
64
+
65
+ this.toObject = function (b) {
66
+ const din = new DataInputX(b);
67
+ const ver = din.readByte();
68
+ this.attr = din.readValue();
69
+ this.listen = this.toLinkObject(din);
70
+ this.outter = this.toLinkObject(din);
71
+ return this;
72
+ };
73
+
74
+ this.toLinkObject = function (din) {
75
+ const data = new Set();
76
+ const sz = din.readDecimal();
77
+ for (let i = 0; i < sz; i++) {
78
+ data.add(new LINK().toObject(din));
79
+ }
80
+ return data;
81
+ };
82
+
83
+ this.toLinkBytes = function (data, out) {
84
+ out.writeDecimal(data.size);
85
+ if (data.size === 0) return;
86
+ data.forEach(k => k.toBytes(out));
87
+ };
88
+
89
+ this.toJSON = function () {
90
+ const o = new Map();
91
+ o.put('attr', JSON.stringify(this.attr));
92
+ o.put('listen', JSON.parse(this.listen));
93
+ o.put('outter', JSON.parse(this.outter));
94
+ return o;
95
+ };
96
+
97
+ this.toJSON = function (data) {
98
+ const out = new JSONArray();
99
+ data.forEach(k => out.put(k.toString()));
100
+ return out;
101
+ };
102
+
103
+ this.isIPv6 = function(data) {
104
+ var ip = data.ip;
105
+ if(ip){
106
+ return net.isIPv6(ip);
107
+ }
108
+ return false;
109
+ };
110
+
111
+ this.isLocal127 = function (data) {
112
+ var ip = data.ip;
113
+ if(ip){
114
+ return ip === '127.0.0.1';
115
+ }
116
+ return false;
117
+ }
118
+ }
119
+
120
+ NodeInfo.prototype = new NodeInfo();
121
+ NodeInfo.prototype.constructor = NodeInfo;
122
+
123
+ module.exports = NodeInfo;
@@ -0,0 +1,111 @@
1
+ var { exec } = require('child_process');
2
+ var os = require('os');
3
+ var NodeInfo = require('./nodeinfo');
4
+ var Logger = require('../logger');
5
+
6
+ function StatusDetector() {
7
+ this.process = async function () {
8
+ let node = new NodeInfo();
9
+ let stat = await this.netstat();
10
+
11
+ if (!stat) {
12
+ node = new NodeInfo();
13
+ } else {
14
+ try {
15
+ node = this.parse(stat);
16
+ } catch (e) {
17
+ node = new NodeInfo();
18
+ Logger.printError("WHATAP-203", "NodeInfo parse error", e, false);
19
+ }
20
+ }
21
+
22
+ node.attr.type = 'nodejs';
23
+ node.attr.time = Date.now();
24
+ node.attr.ip = this.getLocalIpAddress();
25
+ node.attr.pid = process.pid;
26
+ node.attr.pname = process.title;
27
+
28
+ return node;
29
+ };
30
+
31
+ this.netstat = function () {
32
+ return new Promise((resolve, reject) => {
33
+ let cmd = 'netstat -an -t';
34
+ if (os.platform() === 'darwin') {
35
+ cmd = 'netstat -an -p tcp';
36
+ } else if (os.platform() === 'win32') {
37
+ resolve('');
38
+ return;
39
+ }
40
+
41
+ exec(cmd, (error, stdout, stderr) => {
42
+ if (error) {
43
+ reject(error);
44
+ return;
45
+ }
46
+ resolve(stdout);
47
+ });
48
+ });
49
+ };
50
+
51
+ this.parse = function (netstat) {
52
+ var node = new NodeInfo();
53
+ var localIPs = this.getLocalIpSet();
54
+
55
+ var lines = netstat.split('\n');
56
+ lines.forEach(line => {
57
+ if (line.startsWith('tcp')) {
58
+ this.parseLine(node, line, localIPs);
59
+ }
60
+ });
61
+
62
+ return node;
63
+ };
64
+
65
+ this.parseLine = function (node, line, localIPs) {
66
+ var tokens = line.trim().split(/\s+/);
67
+ if (!tokens[0].startsWith('tcp')) return;
68
+
69
+ var localAddress = tokens[3].replace(/(\d+\.\d+\.\d+\.\d+)\.(\d+)/, '$1:$2');
70
+ var remoteAddress = tokens[4].replace(/(\d+\.\d+\.\d+\.\d+)\.(\d+)/, '$1:$2');
71
+
72
+ if (tokens[5] === 'LISTEN') {
73
+ node.addListen(localIPs, localAddress);
74
+ } else {
75
+ node.addOutter(localAddress, remoteAddress);
76
+ }
77
+ };
78
+
79
+ this.getLocalIpSet = function () {
80
+ var ipSet = new Set();
81
+ var interfaces = os.networkInterfaces();
82
+ for (var devName in interfaces) {
83
+ var iface = interfaces[devName];
84
+ iface.forEach(alias => {
85
+ if (alias.family === 'IPv4' && !alias.internal) {
86
+ ipSet.add(alias.address);
87
+ }
88
+ });
89
+ }
90
+ return ipSet;
91
+ };
92
+
93
+ this.getLocalIpAddress = function () {
94
+ var interfaces = os.networkInterfaces();
95
+ for (var devName in interfaces) {
96
+ var iface = interfaces[devName];
97
+ for (let i = 0; i < iface.length; i++) {
98
+ var alias = iface[i];
99
+ if (alias.family === 'IPv4' && !alias.internal) {
100
+ return alias.address;
101
+ }
102
+ }
103
+ }
104
+ return '0.0.0.0';
105
+ };
106
+ }
107
+
108
+ StatusDetector.prototype = new StatusDetector();
109
+ StatusDetector.prototype.constructor = StatusDetector;
110
+
111
+ module.exports = StatusDetector;
@@ -7,12 +7,11 @@
7
7
  var IntKeyMap = require('../util/intkey-map'),
8
8
  HashUtil = require('../util/hashutil'),
9
9
  TraceContext = require('./trace-context'),
10
- Logger = require('../logger');
11
- var Long = require('long');
10
+ Logger = require('../logger'),
11
+ EventLevel = require('../data/event-level');
12
+ Long = require('long');
12
13
  var { AsyncLocalStorage } = require('async_hooks');
13
14
  var crypto = require('crypto');
14
- var { v1: uuidv1 } = require('uuid');
15
- const KeyGen = require('../util/keygen');
16
15
 
17
16
  function TraceContextManager() {
18
17
  this.initialized = false;
@@ -20,8 +19,6 @@ function TraceContextManager() {
20
19
  this.currentId = null;
21
20
  this._asyncLocalStorage = new AsyncLocalStorage();
22
21
  this.entry = new IntKeyMap(1021,1).setMax(5000);
23
- this.node = null;
24
- this.clock_seq = null;
25
22
  }
26
23
 
27
24
  TraceContextManager.prototype.keys = function () {
@@ -34,10 +31,14 @@ TraceContextManager.prototype.size = function () {
34
31
  return this.entry.size();
35
32
  };
36
33
  TraceContextManager.prototype.getContext = function (key) {
34
+ // if(key == null ) {
35
+ // return null;
36
+ // }
37
+ // return this.entry.get(key);
37
38
  return this._asyncLocalStorage.getStore();
38
39
  };
39
40
  TraceContextManager.prototype.getCurrentContext = function () {
40
- return this.getContext();
41
+ return this.getContext(this.currentId);
41
42
  };
42
43
  TraceContextManager.prototype.start = function () {
43
44
 
@@ -46,10 +47,10 @@ TraceContextManager.prototype.start = function () {
46
47
  // var conf = require('../conf/configure');
47
48
  // if(this.size() > conf.profile_max_count) { return null; }
48
49
 
49
- var ctx = new TraceContext(KeyGen.next());
50
+ var ctx = new TraceContext(this.getNextId());
50
51
  ctx.start_time = Date.now();
51
- this.entry.put(ctx.id, ctx);
52
- this.currentId = ctx.id;
52
+ this.entry.put(ctx._id, ctx);
53
+ this.currentId = ctx._id;
53
54
 
54
55
  return ctx;
55
56
  };
@@ -87,32 +88,119 @@ TraceContextManager.prototype.resume = function (id) {
87
88
  return null;
88
89
  }
89
90
  };
91
+ TraceContextManager.prototype.getTxProfile = function(n) {
92
+ var ctx = this.getCurrentContext();
93
+ if(ctx == null)
94
+ return null;
95
+ return ctx.profile.getLastSteps(n);
96
+ };
90
97
  TraceContextManager.prototype.isExist = function (id) {
91
98
  return this.entry.containsKey(id);
92
99
  };
100
+ var DataTextAgent = require('../data/datatext-agent');
101
+ var MessageStep = require('../step/message-step');
102
+ TraceContextManager.prototype.addStep = function (title, desc, ctx) {
103
+ // var ctx = this.getCurrentContext();
104
+ if(ctx == null) {
105
+ return null;
106
+ }
107
+ try {
108
+ var step = new MessageStep();
109
+ step.start_time = ctx.getElapsedTime();
110
+ step.hash = HashUtil.hashFromString(title);
111
+ DataTextAgent.MESSAGE.add(step.hash, title);
112
+ step.desc = desc;
113
+ step.ctx = ctx;
114
+ ctx.profile.push(step);
115
+ return step;
116
+ } catch(e) {
117
+ return null;
118
+ }
119
+ };
120
+ TraceContextManager.prototype.endStep = function (step) {
121
+ if(step == null || step.ctx == null) {
122
+ return;
123
+ }
124
+ this.resume(step.ctx);
125
+ step.time = step.ctx.getElapsedTime() - step.start_time;
126
+ };
127
+
128
+ TraceContextManager.prototype.startTrace = function (title) {
129
+ try{
130
+ var ctx = this.start();
131
+ if(ctx == null) {
132
+ return null;
133
+ }
134
+ ctx.service_name = title;
135
+ ctx.service_hash = HashUtil.hashFromString(title);
136
+ var DataTextAgent = require('../data/datatext-agent'),
137
+ ResourceProfile = require('../util/resourceprofile');
138
+ DataTextAgent.SERVICE.add(ctx.service_hash, title);
139
+ ctx.start_cpu = ResourceProfile.getCPUTime();
140
+ ctx.start_malloc = ResourceProfile.getUsedHeapSize();
93
141
 
94
- TraceContextManager.prototype.getId = function () {
95
- if (!this.node) {
96
- this.node = Math.floor(Math.random() * 0xffffffffffff);
142
+ return ctx;
143
+ }catch(e){
144
+ Logger.printError('WHATAP-998', 'TraceContext (startTrace)', e, true);
97
145
  }
146
+ };
147
+ TraceContextManager.prototype.endTrace = function (ctx) {
148
+ if(ctx == null) {return;}
149
+ var ProfilePack = require('../pack/profile-pack'),
150
+ TxRecord = require('../service/tx-record'),
151
+ DateUtil = require('../util/dateutil'),
152
+ MeterService = require('../counter/meter/meter-service').MeterService,
153
+ DataProfileAgent = require('../data/dataprofile-agent'),
154
+ ResourceProfile = require('../util/resourceprofile'),
155
+ SecurityMaster = require('../net/security-master');
156
+
157
+ var profile = new ProfilePack();
158
+ var service = new TxRecord();
159
+ profile.time = Long.fromValue(ctx.start_time);
160
+ service.endTime = DateUtil.currentTime();
161
+ service.elapsed = ctx.getElapsedTime();
162
+ service.service = ctx.service_hash;
163
+ DataTextAgent.SERVICE.add(ctx.service_hash, ctx.service_name);
98
164
 
99
- if (!this.clock_seq) {
100
- this.clock_seq = Math.floor(Math.random() * (1 << 14));
165
+ service.cpuTime = ResourceProfile.getCPUTime() - ctx.start_cpu;
166
+ service.malloc = ResourceProfile.getUsedHeapSize() - ctx.start_malloc;
167
+ if(service.malloc < 0) { service.malloc = 0; }
168
+ service.seq = ctx.txid;
169
+ service.sqlCount = ctx.sql_count;
170
+ service.sqlTime = ctx.sql_time;
171
+ service.sqlFetchCount = ctx.rs_count;
172
+ service.sqlFetchTime = parseInt(ctx.rs_time);
173
+ service.ipaddr = ctx.remoteIp;
174
+ service.userid = ctx.userid;
175
+
176
+ service.mcaller_pcode = ctx.mcaller_pcode;
177
+ service.mcaller_okind = ctx.mcaller_okind;
178
+ service.mcaller_oid = ctx.mcaller_oid;
179
+
180
+ if (ctx.error.isZero()==false/*long*/) {
181
+ service.error = ctx.error;
182
+ service.errorLevel = EventLevel.WARNING;
101
183
  }
184
+ service.userAgent = ctx.userAgent;
185
+ service.referer = ctx.referer;
186
+
187
+ service.httpcCount = ctx.httpc_count;
188
+ service.httpcTime = ctx.httpc_time;
189
+ service.status = ctx.status;
102
190
 
103
- const uuid1 = uuidv1({
104
- node: this.node,
105
- clockseq: this.clock_seq
106
- });
191
+ service.http_method=TxRecord.HTTP_METHOD[ctx.http_method] || TxRecord.WEB_GET;
107
192
 
108
- const buffer = Buffer.from(uuid1.replace(/-/g, ''), 'hex');
109
- const uuidInt = BigInt('0x' + buffer.toString('hex'));
193
+ MeterService.add(service.service, service.elapsed, service.errorLevel, service.mcaller_pcode, service.mcaller_okind, service.mcaller_oid , service.apdex);
110
194
 
111
- const upperBits = (uuidInt >> 64n) & 0xffffffffffffffffn;
112
- const lowerBits = (uuidInt << 64n) & 0xffffffffffffffffn;
113
- const key = upperBits ^ lowerBits;
195
+ profile.oid = SecurityMaster.OID;
196
+ profile.service = service;
114
197
 
115
- return Long.fromString(key.toString()).toNumber();
198
+ var self = this;
199
+ setTimeout(function () {
200
+ DataProfileAgent.sendProfile(ctx, profile, false);
201
+ self.end(ctx._id);
202
+ ctx = null;
203
+ }, 100);
116
204
  };
117
205
 
118
206
  module.exports = new TraceContextManager();
@@ -13,29 +13,39 @@ var ProfileCollector = require('./profile-collector'),
13
13
  Long = require('long');
14
14
 
15
15
  function TraceContext(id) {
16
- this.id = id;
16
+ this._id = id;
17
17
  this.isStaticContents = false;
18
18
  this.profile = new ProfileCollector(this);
19
19
 
20
- this.pid = process.pid;
21
-
22
20
  this.txid = KeyGen.next();
23
21
  this.thread = null;
24
22
  this.thread_id = 0;
25
23
 
26
24
  this.start_cpu = 0;
25
+ this.start_malloc = 0;
26
+ this.start_time = 0;
27
+
27
28
  this.status = 0;
28
29
 
29
30
  this.service_hash = 0;
30
31
  this.service_name = '';
31
32
  this.remoteIp = 0;
32
- this.error = 0;
33
+ this.error = Long.ZERO;
34
+ this.error_class = '';
35
+ this.error_message = '';
33
36
 
34
37
  this.http_method = '';
35
38
  this.http_query = '';
36
39
  this.http_content_type = '';
40
+
41
+ this.sql_count = 0;
42
+ this.sql_time = 0;
37
43
 
38
- this.host = '';
44
+ this.sql_insert = 0;
45
+ this.sql_update = 0;
46
+ this.sql_delete = 0;
47
+ this.sql_select = 0;
48
+ this.sql_others = 0;
39
49
 
40
50
  this.executed_sqlhash = 0;
41
51
  this.active_sqlhash = 0;
@@ -59,6 +69,10 @@ function TraceContext(id) {
59
69
  this.lastSqlStep = null; /*SqlStepX*/
60
70
  this.profileActive = 0;
61
71
 
72
+ this.jdbc_updated = false;
73
+ this.jdbc_update_record = 0;
74
+ this.jdbc_identity = 0;
75
+ this.jdbc_commit = 0;
62
76
  this.resultSql = new IntKeyMap().setMax(11);
63
77
 
64
78
  this.rs_count = 0;
@@ -66,7 +80,7 @@ function TraceContext(id) {
66
80
  this.db_opening = false;
67
81
  this.socket_connecting = false;
68
82
 
69
- this.mtid= Long.ZERO;
83
+ this.mtid=Long.ZERO;
70
84
  this.mdepth = 0;
71
85
  this.mcaller_pcode = 0;
72
86
  this.mcaller_okind = 0;
@@ -119,7 +133,7 @@ TraceContext.prototype.setCallerPOID= function (poidStr) {
119
133
  this.mcaller_okind = poid.okind;
120
134
  this.mcaller_oid = poid.oid;
121
135
  } catch (e) {
122
- Logger.printError('WHATAP-701', 'TraceContext (setCallerPOID)', e, true);
136
+ Logger.printError('WHATAP-999', 'TraceContext (setCallerPOID)', e, true);
123
137
  }
124
138
  };
125
139
  module.exports = TraceContext;
@@ -1,19 +1,25 @@
1
- const conf = require('../conf/configure'),
2
- AsyncSender = require('../udp/async_sender'),
3
- PacketTypeEnum = require('../udp/packet_type_enum');
1
+ const HttpStepX = require('../step/http-stepx'),
2
+ conf = require('../conf/configure'),
3
+ StatError= require('../stat/stat-error'),
4
+ TextTypes= require("../lang/text-types");
4
5
 
5
6
  var TraceHttpc = function () {}
6
- TraceHttpc.prototype.isSlowHttpc = function (ctx) {
7
- if(!ctx)
7
+
8
+ TraceHttpc.prototype.hasHttpStepX = function (buffer) {
9
+ if (!Array.isArray(buffer)) {
10
+ return [];
11
+ }
12
+
13
+ return buffer.filter(item => item instanceof HttpStepX);
14
+ }
15
+
16
+ TraceHttpc.prototype.isSlowHttpc = function (ctx, httpc_step) {
17
+ if(!ctx.profile.buffer)
8
18
  return;
9
19
  var profile_error_httpc_time_max = conf.getProperty('profile_error_httpc_time_max', 10000);
10
20
 
11
- if(ctx.elapsed && (ctx.elapsed > profile_error_httpc_time_max)){
12
- if (!ctx.error) ctx.error = 1;
13
- ctx.status = 500;
14
-
15
- var errors = ['SlOW_HTTPC', 'SlOW HTTPC'];
16
- AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
21
+ if(httpc_step.elapsed && (httpc_step.elapsed > profile_error_httpc_time_max)){
22
+ httpc_step.error = StatError.addError('SLOW_HTTPC', 'SLOW HTTPC', ctx.service_hash, TextTypes.HTTPC_URL, null);
17
23
  }
18
24
  }
19
25
 
@@ -1,36 +1,44 @@
1
- const conf = require('../conf/configure'),
2
- AsyncSender = require('../udp/async_sender'),
3
- PacketTypeEnum = require('../udp/packet_type_enum');
1
+ const SqlStepX = require('../step/sql-stepx'),
2
+ conf = require('../conf/configure'),
3
+ StatError = require('../stat/stat-error'),
4
+ TextTypes = require("../lang/text-types");
4
5
 
5
6
  var TraceSql = function () {}
6
7
 
7
- TraceSql.prototype.isSlowSQL = function (ctx) {
8
- if (!ctx) return;
8
+ TraceSql.prototype.hasSqlStepX = function (buffer) {
9
+ if (!Array.isArray(buffer)) {
10
+ return [];
11
+ }
9
12
 
10
- var profile_error_sql_time_max = conf.getProperty('profile_error_sql_time_max', 30000);
11
- var sql_elapsed = ctx.elapsed || 0;
13
+ return buffer.filter(item => item instanceof SqlStepX);
14
+ }
12
15
 
13
- if (sql_elapsed > profile_error_sql_time_max) {
14
- if (!ctx.error) ctx.error = 1;
15
- ctx.status = 500;
16
+ TraceSql.prototype.isSlowSQL = function (ctx) {
17
+ if(!ctx.profile.buffer)
18
+ return;
16
19
 
17
- var errors = ['SLOW_SQL', 'SLOW SQL'];
18
- AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
20
+ var profile_error_sql_time_max = conf.getProperty('profile_error_sql_time_max', 30000);
21
+ var sqlStepX = this.hasSqlStepX(ctx.profile.buffer);
22
+ var slow_sql_step = sqlStepX.find(step => step.elapsed > profile_error_sql_time_max);
23
+ if(slow_sql_step){
24
+ slow_sql_step.error = StatError.addError('SLOW_SQL', 'SLOW SQL', ctx.service_hash, TextTypes.SQL, null);
25
+ if(ctx.error.isZero()){
26
+ ctx.error = slow_sql_step.error;
27
+ }
19
28
  }
20
29
  return;
21
30
  }
22
31
 
23
- TraceSql.prototype.isTooManyRecords = function (rs_count, ctx) {
24
- if (!ctx) return;
32
+ TraceSql.prototype.isTooManyRecords = function (sql_step, rs_count, ctx) {
33
+ if(!ctx.profile.buffer)
34
+ return;
25
35
 
26
36
  var profile_error_sql_fetch_max = conf.getProperty('profile_error_sql_fetch_max', 10000);
27
- if (rs_count && rs_count > profile_error_sql_fetch_max) {
28
- // Too many records 에러 처리
29
- if (!ctx.error) ctx.error = 1;
30
- ctx.status = 500;
31
-
32
- var errors = ['TOO_MANY_RECORDS', 'Too many records'];
33
- AsyncSender.send_packet(PacketTypeEnum.TX_ERROR, ctx, errors);
37
+ if(rs_count && rs_count > profile_error_sql_fetch_max){
38
+ sql_step.error = StatError.addError('TOO_MANY_RECORDS', 'Too many records', ctx.service_hash, TextTypes.SQL, null)
39
+ if(ctx.error.isZero()){
40
+ ctx.error = sql_step.error;
41
+ }
34
42
  }
35
43
  }
36
44