whatap 0.4.78 → 0.4.80
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.
- package/.vscode/keep-context.json +3 -3
- package/README.md +51 -51
- package/bindings/darwin/x64/whatap.node +0 -0
- package/bindings/linux/ia32/whatap.node +0 -0
- package/bindings/linux/x64/whatap.node +0 -0
- package/help.txt +10 -10
- package/index.js +8 -8
- package/lib/conf/conf-sys-mon.js +100 -100
- package/lib/conf/config-default.js +238 -238
- package/lib/conf/configure.js +423 -423
- package/lib/conf/license.js +41 -41
- package/lib/control/cmd-config.js +23 -23
- package/lib/control/control-handler.js +344 -344
- package/lib/control/packagectr-helper.js +149 -149
- package/lib/core/agent.js +329 -328
- package/lib/core/interceptor.js +142 -142
- package/lib/core/request-agent.js +26 -26
- package/lib/counter/counter-manager.js +127 -127
- package/lib/counter/meter/meter-activex.js +66 -66
- package/lib/counter/meter/meter-httpc.js +57 -57
- package/lib/counter/meter/meter-resource.js +9 -9
- package/lib/counter/meter/meter-service.js +167 -167
- package/lib/counter/meter/meter-socket.io.js +50 -50
- package/lib/counter/meter/meter-sql.js +70 -70
- package/lib/counter/meter/meter-users.js +57 -57
- package/lib/counter/meter.js +183 -183
- package/lib/counter/task/activetransaction.js +93 -93
- package/lib/counter/task/agentinfo.js +105 -105
- package/lib/counter/task/counter-task.js +9 -9
- package/lib/counter/task/gcstat.js +34 -34
- package/lib/counter/task/heapmem.js +24 -24
- package/lib/counter/task/httpc.js +75 -75
- package/lib/counter/task/proc-cpu.js +28 -28
- package/lib/counter/task/realtimeuser.js +30 -30
- package/lib/counter/task/res/systemECSTask.js +54 -54
- package/lib/counter/task/res/systemKubeTask.js +52 -52
- package/lib/counter/task/res/util/awsEcsClientThread.js +166 -166
- package/lib/counter/task/res/util/linuxProcStatUtil.js +13 -13
- package/lib/counter/task/res-sys-cpu.js +61 -61
- package/lib/counter/task/service.js +201 -201
- package/lib/counter/task/socketio.js +29 -29
- package/lib/counter/task/sql.js +104 -104
- package/lib/counter/task/systemperf.js +42 -42
- package/lib/data/datapack-sender.js +256 -256
- package/lib/data/dataprofile-agent.js +136 -136
- package/lib/data/datatext-agent.js +135 -135
- package/lib/data/event-level.js +15 -15
- package/lib/data/test.js +48 -48
- package/lib/env/constants.js +20 -20
- package/lib/kube/kube-client.js +143 -143
- package/lib/lang/text-types.js +58 -58
- package/lib/logger.js +319 -319
- package/lib/net/netflag.js +54 -54
- package/lib/net/paramdef.js +40 -40
- package/lib/net/receiver.js +65 -65
- package/lib/net/security-master.js +182 -173
- package/lib/net/sender.js +140 -140
- package/lib/net/tcp-return.js +17 -17
- package/lib/net/tcp-session.js +285 -285
- package/lib/net/tcpreq-client-proxy.js +69 -69
- package/lib/net/tcprequest-mgr.js +57 -57
- package/lib/observers/cluster-observer.js +21 -21
- package/lib/observers/express-observer.js +214 -214
- package/lib/observers/file-observer.js +184 -184
- package/lib/observers/global-observer.js +30 -30
- package/lib/observers/http-observer.js +704 -704
- package/lib/observers/maria-observer.js +382 -382
- package/lib/observers/memcached-observer.js +55 -55
- package/lib/observers/mongo-observer.js +262 -265
- package/lib/observers/mongodb-observer.js +197 -197
- package/lib/observers/mongoose-observer.js +83 -83
- package/lib/observers/mssql-observer.js +205 -205
- package/lib/observers/mysql-observer.js +436 -394
- package/lib/observers/net-observer.js +72 -72
- package/lib/observers/pgsql-observer.js +295 -295
- package/lib/observers/process-observer.js +25 -25
- package/lib/observers/promise-observer.js +31 -31
- package/lib/observers/redis-observer.js +156 -109
- package/lib/observers/schedule-observer.js +66 -66
- package/lib/observers/socket.io-observer.js +54 -54
- package/lib/observers/stream-observer.js +19 -19
- package/lib/observers/thrift-observer.js +196 -196
- package/lib/pack/activestack-pack.js +54 -54
- package/lib/pack/counter-pack.js +649 -649
- package/lib/pack/errorsnap-pack.js +68 -68
- package/lib/pack/event-pack.js +53 -53
- package/lib/pack/hitmap-pack.js +62 -62
- package/lib/pack/hitmap-pack1.js +146 -146
- package/lib/pack/netstat.js +14 -14
- package/lib/pack/pack.js +49 -49
- package/lib/pack/packenum.js +60 -60
- package/lib/pack/param-pack.js +213 -213
- package/lib/pack/profile-pack.js +48 -48
- package/lib/pack/realtimeuser-pack.js +40 -40
- package/lib/pack/stat-general-pack.js +95 -95
- package/lib/pack/staterror-pack.js +119 -119
- package/lib/pack/stathttpc-pack.js +66 -66
- package/lib/pack/stathttpc-rec.js +78 -78
- package/lib/pack/statremote-pack.js +45 -45
- package/lib/pack/statservice-pack.js +62 -62
- package/lib/pack/statservice-pack1.js +87 -87
- package/lib/pack/statservice-rec.js +292 -292
- package/lib/pack/statservice-rec_dep.js +151 -151
- package/lib/pack/statsql-pack.js +69 -69
- package/lib/pack/statsql-rec.js +100 -100
- package/lib/pack/statuseragent-pack.js +43 -43
- package/lib/pack/tagcount-pack.js +398 -398
- package/lib/pack/tagctr.js +14 -14
- package/lib/pack/text-pack.js +49 -49
- package/lib/pack/time-count.js +25 -25
- package/lib/pack/websocket.js +14 -14
- package/lib/plugin/plugin-loadermanager.js +56 -56
- package/lib/plugin/plugin.js +75 -75
- package/lib/requestlog.js +326 -326
- package/lib/service/tx-record.js +288 -284
- package/lib/stat/stat-error.js +116 -116
- package/lib/stat/stat-httpc.js +97 -97
- package/lib/stat/stat-remoteip.js +46 -46
- package/lib/stat/stat-sql.js +112 -112
- package/lib/stat/stat-tranx.js +57 -57
- package/lib/stat/stat-tx-caller.js +159 -159
- package/lib/stat/stat-tx-domain.js +110 -110
- package/lib/stat/stat-tx-referer.js +111 -111
- package/lib/stat/stat-useragent.js +48 -48
- package/lib/stat/timingsender.js +72 -72
- package/lib/step/activestack-step.js +37 -37
- package/lib/step/dbc-step.js +35 -35
- package/lib/step/http-stepx.js +66 -66
- package/lib/step/message-step.js +39 -39
- package/lib/step/method-stepx.js +46 -46
- package/lib/step/resultset-step.js +39 -39
- package/lib/step/securemsg-step.js +43 -43
- package/lib/step/socket-step.js +46 -46
- package/lib/step/sql-stepx.js +67 -67
- package/lib/step/sqlxtype.js +15 -15
- package/lib/step/step.js +65 -65
- package/lib/step/stepenum.js +53 -53
- package/lib/trace/local-context.js +13 -13
- package/lib/trace/parsed-sql.js +13 -13
- package/lib/trace/profile-collector.js +70 -70
- package/lib/trace/serviceurl-pattern-detector.js +117 -117
- package/lib/trace/trace-context-manager.js +195 -195
- package/lib/trace/trace-context.js +134 -134
- package/lib/util/anylist.js +102 -102
- package/lib/util/array-util.js +100 -100
- package/lib/util/bitutil.js +27 -27
- package/lib/util/cardinality/hyperloglog.js +105 -105
- package/lib/util/cardinality/murmurhash.js +31 -31
- package/lib/util/cardinality/registerset.js +74 -74
- package/lib/util/config-util.js +17 -17
- package/lib/util/cypher.js +89 -89
- package/lib/util/datetimehelper.js +237 -229
- package/lib/util/dateutil.js +110 -106
- package/lib/util/errordata.js +20 -20
- package/lib/util/escape-literal-sql.js +342 -342
- package/lib/util/hashutil2.js +126 -126
- package/lib/util/hexa32.js +57 -57
- package/lib/util/index.js +78 -78
- package/lib/util/intint-map.js +47 -47
- package/lib/util/intkey-linkedmap.js +26 -26
- package/lib/util/intkey-map.js +25 -25
- package/lib/util/intset.js +82 -82
- package/lib/util/iputil.js +119 -119
- package/lib/util/iputil_x.js +526 -526
- package/lib/util/keygen.js +17 -17
- package/lib/util/kube-util.js +72 -72
- package/lib/util/longint-linkedmap.js +35 -35
- package/lib/util/longkey-linkedmap.js +25 -25
- package/lib/util/longlong-linkedmap.js +37 -37
- package/lib/util/nodeutil.js +67 -67
- package/lib/util/oidutil.js +96 -93
- package/lib/util/paramsecurity.js +78 -78
- package/lib/util/pathtree.js +172 -172
- package/lib/util/pre-process.js +13 -13
- package/lib/util/process-seq.js +165 -165
- package/lib/util/property-util.js +35 -35
- package/lib/util/request-queue.js +42 -42
- package/lib/util/requestdouble-queue.js +72 -72
- package/lib/util/resourceprofile.js +156 -156
- package/lib/util/seedrandom.js +242 -242
- package/lib/util/stop-watch.js +29 -29
- package/lib/util/string-util.js +9 -9
- package/lib/util/stringkey-linkedmap.js +28 -28
- package/lib/util/stringnum-linkedmap.js +31 -31
- package/lib/util/stringset.js +65 -65
- package/lib/util/system-util.js +9 -9
- package/lib/util/userid-util.js +57 -57
- package/lib/util/utils.js +67 -67
- package/lib/value/blob-value.js +61 -61
- package/lib/value/boolean-value.js +51 -51
- package/lib/value/decimal-value.js +71 -71
- package/lib/value/double-summary.js +105 -105
- package/lib/value/double-value.js +50 -50
- package/lib/value/float-array.js +59 -59
- package/lib/value/float-value.js +64 -64
- package/lib/value/int-array.js +59 -59
- package/lib/value/int-map-value.js +151 -151
- package/lib/value/int-value.js +64 -64
- package/lib/value/ip4-value.js +83 -83
- package/lib/value/list-value.js +136 -136
- package/lib/value/long-array.js +59 -59
- package/lib/value/long-summary.js +105 -105
- package/lib/value/map-value.js +175 -175
- package/lib/value/metric-value.js +157 -157
- package/lib/value/null-value.js +42 -42
- package/lib/value/number-value.js +34 -34
- package/lib/value/summary-value.js +29 -29
- package/lib/value/text-array.js +117 -117
- package/lib/value/text-value.js +59 -59
- package/lib/value/texthash-value.js +49 -49
- package/lib/value/value.js +14 -14
- package/lib/value/valueenum.js +99 -99
- package/logs/whatap-20230906.log +54 -0
- package/package.json +28 -28
- package/whatap.conf +1 -1
- package/logs/whatap-20230616.log +0 -13
|
@@ -1,196 +1,196 @@
|
|
|
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 IntKeyMap = require('../util/intkey-map'),
|
|
8
|
-
HashUtil = require('../util/hashutil'),
|
|
9
|
-
TraceContext = require('./trace-context'),
|
|
10
|
-
Logger = require('../logger'),
|
|
11
|
-
EventLevel = require('../data/event-level');
|
|
12
|
-
Long = require('long');
|
|
13
|
-
|
|
14
|
-
function TraceContextManager() {
|
|
15
|
-
this.initialized = false;
|
|
16
|
-
this.nextId = 1;
|
|
17
|
-
this.currentId = null;
|
|
18
|
-
this.entry = new IntKeyMap(1021,1).setMax(5000);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
TraceContextManager.prototype.keys = function () {
|
|
22
|
-
return this.entry.keys();
|
|
23
|
-
};
|
|
24
|
-
TraceContextManager.prototype.getContextEnumeration = function () {
|
|
25
|
-
return this.entry.values();
|
|
26
|
-
};
|
|
27
|
-
TraceContextManager.prototype.size = function () {
|
|
28
|
-
return this.entry.size();
|
|
29
|
-
};
|
|
30
|
-
TraceContextManager.prototype.getContext = function (key) {
|
|
31
|
-
if(key == null ) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
return this.entry.get(key);
|
|
35
|
-
};
|
|
36
|
-
TraceContextManager.prototype.getCurrentContext = function () {
|
|
37
|
-
return this.getContext(this.currentId);
|
|
38
|
-
};
|
|
39
|
-
TraceContextManager.prototype.start = function () {
|
|
40
|
-
|
|
41
|
-
if(this.initialized === false) { return null; }
|
|
42
|
-
|
|
43
|
-
// var conf = require('../conf/configure');
|
|
44
|
-
// if(this.size() > conf.profile_max_count) { return null; }
|
|
45
|
-
|
|
46
|
-
var ctx = new TraceContext(this.getNextId());
|
|
47
|
-
ctx.start_time = Date.now();
|
|
48
|
-
this.entry.put(ctx._id, ctx);
|
|
49
|
-
this.currentId = ctx._id;
|
|
50
|
-
|
|
51
|
-
return ctx;
|
|
52
|
-
};
|
|
53
|
-
TraceContextManager.prototype.end = function (id) {
|
|
54
|
-
if(id == null) {
|
|
55
|
-
this.entry.remove(this.currentId); // important: high risky
|
|
56
|
-
this.currentId = null;
|
|
57
|
-
} else {
|
|
58
|
-
this.entry.remove(id);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
TraceContextManager.prototype.getNextId = function () {
|
|
63
|
-
this.nextId = (this.nextId + 1) % 10000000;
|
|
64
|
-
return this.nextId;
|
|
65
|
-
};
|
|
66
|
-
TraceContextManager.prototype.getCurrentId = function () {
|
|
67
|
-
return this.currentId;
|
|
68
|
-
};
|
|
69
|
-
TraceContextManager.prototype.resume = function (id) {
|
|
70
|
-
if(id == null) { return null; }
|
|
71
|
-
if(id instanceof TraceContext) {
|
|
72
|
-
id = id._id;
|
|
73
|
-
}
|
|
74
|
-
var c = this.getContext(id);
|
|
75
|
-
if(c){
|
|
76
|
-
this.currentId = id;
|
|
77
|
-
return c;
|
|
78
|
-
} else {
|
|
79
|
-
this.currentId = null;
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
TraceContextManager.prototype.getTxProfile = function(n) {
|
|
84
|
-
var ctx = this.getCurrentContext();
|
|
85
|
-
if(ctx == null)
|
|
86
|
-
return null;
|
|
87
|
-
return ctx.profile.getLastSteps(n);
|
|
88
|
-
};
|
|
89
|
-
TraceContextManager.prototype.isExist = function (id) {
|
|
90
|
-
return this.entry.containsKey(id);
|
|
91
|
-
};
|
|
92
|
-
var DataTextAgent = require('../data/datatext-agent');
|
|
93
|
-
var MessageStep = require('../step/message-step');
|
|
94
|
-
TraceContextManager.prototype.addStep = function (title, desc) {
|
|
95
|
-
var ctx = this.getCurrentContext();
|
|
96
|
-
if(ctx == null) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
var step = new MessageStep();
|
|
101
|
-
step.start_time = ctx.getElapsedTime();
|
|
102
|
-
step.hash = HashUtil.hashFromString(title);
|
|
103
|
-
DataTextAgent.MESSAGE.add(step.hash, title);
|
|
104
|
-
step.desc = desc;
|
|
105
|
-
step.ctx = ctx;
|
|
106
|
-
ctx.profile.push(step);
|
|
107
|
-
return step;
|
|
108
|
-
} catch(e) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
TraceContextManager.prototype.endStep = function (step) {
|
|
113
|
-
if(step == null || step.ctx == null) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
this.resume(step.ctx);
|
|
117
|
-
step.time = step.ctx.getElapsedTime() - step.start_time;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
TraceContextManager.prototype.startTrace = function (title) {
|
|
121
|
-
try{
|
|
122
|
-
var ctx = this.start();
|
|
123
|
-
if(ctx == null) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
ctx.service_name = title;
|
|
127
|
-
ctx.service_hash = HashUtil.hashFromString(title);
|
|
128
|
-
var DataTextAgent = require('../data/datatext-agent'),
|
|
129
|
-
ResourceProfile = require('../util/resourceprofile');
|
|
130
|
-
DataTextAgent.SERVICE.add(ctx.service_hash, title);
|
|
131
|
-
ctx.start_cpu = ResourceProfile.getCPUTime();
|
|
132
|
-
ctx.start_malloc = ResourceProfile.getUsedHeapSize();
|
|
133
|
-
|
|
134
|
-
return ctx;
|
|
135
|
-
}catch(e){
|
|
136
|
-
Logger.printError('WHATAP-998', 'TraceContext (startTrace)', e, true);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
TraceContextManager.prototype.endTrace = function (ctx) {
|
|
140
|
-
if(ctx == null) {return;}
|
|
141
|
-
var ProfilePack = require('../pack/profile-pack'),
|
|
142
|
-
TxRecord = require('../service/tx-record'),
|
|
143
|
-
DateUtil = require('../util/dateutil'),
|
|
144
|
-
MeterService = require('../counter/meter/meter-service').MeterService,
|
|
145
|
-
DataProfileAgent = require('../data/dataprofile-agent'),
|
|
146
|
-
ResourceProfile = require('../util/resourceprofile'),
|
|
147
|
-
SecurityMaster = require('../net/security-master');
|
|
148
|
-
|
|
149
|
-
var profile = new ProfilePack();
|
|
150
|
-
var service = new TxRecord();
|
|
151
|
-
profile.time = Long.fromValue(ctx.start_time);
|
|
152
|
-
service.endTime = DateUtil.currentTime();
|
|
153
|
-
service.elapsed = ctx.getElapsedTime();
|
|
154
|
-
service.service = ctx.service_hash;
|
|
155
|
-
service.cpuTime = ResourceProfile.getCPUTime() - ctx.start_cpu;
|
|
156
|
-
service.malloc = ResourceProfile.getUsedHeapSize() - ctx.start_malloc;
|
|
157
|
-
if(service.malloc < 0) { service.malloc = 0; }
|
|
158
|
-
service.seq = ctx.txid;
|
|
159
|
-
service.sqlCount = ctx.sql_count;
|
|
160
|
-
service.sqlTime = ctx.sql_time;
|
|
161
|
-
service.sqlFetchCount = ctx.rs_count;
|
|
162
|
-
service.sqlFetchTime = parseInt(ctx.rs_time);
|
|
163
|
-
service.ipaddr = ctx.remoteIp;
|
|
164
|
-
service.userid = ctx.userid;
|
|
165
|
-
|
|
166
|
-
service.mcaller_pcode = ctx.mcaller_pcode;
|
|
167
|
-
service.mcaller_okind = ctx.mcaller_okind;
|
|
168
|
-
service.mcaller_oid = ctx.mcaller_oid;
|
|
169
|
-
|
|
170
|
-
if (ctx.error.isZero()==false/*long*/) {
|
|
171
|
-
service.error = ctx.error;
|
|
172
|
-
service.errorLevel = EventLevel.WARNING;
|
|
173
|
-
}
|
|
174
|
-
service.userAgent = ctx.userAgent;
|
|
175
|
-
service.referer = ctx.referer;
|
|
176
|
-
|
|
177
|
-
service.httpcCount = ctx.httpc_count;
|
|
178
|
-
service.httpcTime = ctx.httpc_time;
|
|
179
|
-
service.status = ctx.status;
|
|
180
|
-
|
|
181
|
-
service.http_method=TxRecord.HTTP_METHOD[ctx.http_method] || TxRecord.WEB_GET;
|
|
182
|
-
|
|
183
|
-
MeterService.add(service.service, service.elapsed, service.errorLevel, service.mcaller_pcode, service.mcaller_okind, service.mcaller_oid , service.apdex);
|
|
184
|
-
|
|
185
|
-
profile.oid = SecurityMaster.OID;
|
|
186
|
-
profile.service = service;
|
|
187
|
-
|
|
188
|
-
var self = this;
|
|
189
|
-
setTimeout(function () {
|
|
190
|
-
DataProfileAgent.sendProfile(ctx, profile, false);
|
|
191
|
-
self.end(ctx._id);
|
|
192
|
-
ctx = null;
|
|
193
|
-
}, 100);
|
|
194
|
-
};
|
|
195
|
-
|
|
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 IntKeyMap = require('../util/intkey-map'),
|
|
8
|
+
HashUtil = require('../util/hashutil'),
|
|
9
|
+
TraceContext = require('./trace-context'),
|
|
10
|
+
Logger = require('../logger'),
|
|
11
|
+
EventLevel = require('../data/event-level');
|
|
12
|
+
Long = require('long');
|
|
13
|
+
|
|
14
|
+
function TraceContextManager() {
|
|
15
|
+
this.initialized = false;
|
|
16
|
+
this.nextId = 1;
|
|
17
|
+
this.currentId = null;
|
|
18
|
+
this.entry = new IntKeyMap(1021,1).setMax(5000);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
TraceContextManager.prototype.keys = function () {
|
|
22
|
+
return this.entry.keys();
|
|
23
|
+
};
|
|
24
|
+
TraceContextManager.prototype.getContextEnumeration = function () {
|
|
25
|
+
return this.entry.values();
|
|
26
|
+
};
|
|
27
|
+
TraceContextManager.prototype.size = function () {
|
|
28
|
+
return this.entry.size();
|
|
29
|
+
};
|
|
30
|
+
TraceContextManager.prototype.getContext = function (key) {
|
|
31
|
+
if(key == null ) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return this.entry.get(key);
|
|
35
|
+
};
|
|
36
|
+
TraceContextManager.prototype.getCurrentContext = function () {
|
|
37
|
+
return this.getContext(this.currentId);
|
|
38
|
+
};
|
|
39
|
+
TraceContextManager.prototype.start = function () {
|
|
40
|
+
|
|
41
|
+
if(this.initialized === false) { return null; }
|
|
42
|
+
|
|
43
|
+
// var conf = require('../conf/configure');
|
|
44
|
+
// if(this.size() > conf.profile_max_count) { return null; }
|
|
45
|
+
|
|
46
|
+
var ctx = new TraceContext(this.getNextId());
|
|
47
|
+
ctx.start_time = Date.now();
|
|
48
|
+
this.entry.put(ctx._id, ctx);
|
|
49
|
+
this.currentId = ctx._id;
|
|
50
|
+
|
|
51
|
+
return ctx;
|
|
52
|
+
};
|
|
53
|
+
TraceContextManager.prototype.end = function (id) {
|
|
54
|
+
if(id == null) {
|
|
55
|
+
this.entry.remove(this.currentId); // important: high risky
|
|
56
|
+
this.currentId = null;
|
|
57
|
+
} else {
|
|
58
|
+
this.entry.remove(id);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
TraceContextManager.prototype.getNextId = function () {
|
|
63
|
+
this.nextId = (this.nextId + 1) % 10000000;
|
|
64
|
+
return this.nextId;
|
|
65
|
+
};
|
|
66
|
+
TraceContextManager.prototype.getCurrentId = function () {
|
|
67
|
+
return this.currentId;
|
|
68
|
+
};
|
|
69
|
+
TraceContextManager.prototype.resume = function (id) {
|
|
70
|
+
if(id == null) { return null; }
|
|
71
|
+
if(id instanceof TraceContext) {
|
|
72
|
+
id = id._id;
|
|
73
|
+
}
|
|
74
|
+
var c = this.getContext(id);
|
|
75
|
+
if(c){
|
|
76
|
+
this.currentId = id;
|
|
77
|
+
return c;
|
|
78
|
+
} else {
|
|
79
|
+
this.currentId = null;
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
TraceContextManager.prototype.getTxProfile = function(n) {
|
|
84
|
+
var ctx = this.getCurrentContext();
|
|
85
|
+
if(ctx == null)
|
|
86
|
+
return null;
|
|
87
|
+
return ctx.profile.getLastSteps(n);
|
|
88
|
+
};
|
|
89
|
+
TraceContextManager.prototype.isExist = function (id) {
|
|
90
|
+
return this.entry.containsKey(id);
|
|
91
|
+
};
|
|
92
|
+
var DataTextAgent = require('../data/datatext-agent');
|
|
93
|
+
var MessageStep = require('../step/message-step');
|
|
94
|
+
TraceContextManager.prototype.addStep = function (title, desc) {
|
|
95
|
+
var ctx = this.getCurrentContext();
|
|
96
|
+
if(ctx == null) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
var step = new MessageStep();
|
|
101
|
+
step.start_time = ctx.getElapsedTime();
|
|
102
|
+
step.hash = HashUtil.hashFromString(title);
|
|
103
|
+
DataTextAgent.MESSAGE.add(step.hash, title);
|
|
104
|
+
step.desc = desc;
|
|
105
|
+
step.ctx = ctx;
|
|
106
|
+
ctx.profile.push(step);
|
|
107
|
+
return step;
|
|
108
|
+
} catch(e) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
TraceContextManager.prototype.endStep = function (step) {
|
|
113
|
+
if(step == null || step.ctx == null) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.resume(step.ctx);
|
|
117
|
+
step.time = step.ctx.getElapsedTime() - step.start_time;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
TraceContextManager.prototype.startTrace = function (title) {
|
|
121
|
+
try{
|
|
122
|
+
var ctx = this.start();
|
|
123
|
+
if(ctx == null) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
ctx.service_name = title;
|
|
127
|
+
ctx.service_hash = HashUtil.hashFromString(title);
|
|
128
|
+
var DataTextAgent = require('../data/datatext-agent'),
|
|
129
|
+
ResourceProfile = require('../util/resourceprofile');
|
|
130
|
+
DataTextAgent.SERVICE.add(ctx.service_hash, title);
|
|
131
|
+
ctx.start_cpu = ResourceProfile.getCPUTime();
|
|
132
|
+
ctx.start_malloc = ResourceProfile.getUsedHeapSize();
|
|
133
|
+
|
|
134
|
+
return ctx;
|
|
135
|
+
}catch(e){
|
|
136
|
+
Logger.printError('WHATAP-998', 'TraceContext (startTrace)', e, true);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
TraceContextManager.prototype.endTrace = function (ctx) {
|
|
140
|
+
if(ctx == null) {return;}
|
|
141
|
+
var ProfilePack = require('../pack/profile-pack'),
|
|
142
|
+
TxRecord = require('../service/tx-record'),
|
|
143
|
+
DateUtil = require('../util/dateutil'),
|
|
144
|
+
MeterService = require('../counter/meter/meter-service').MeterService,
|
|
145
|
+
DataProfileAgent = require('../data/dataprofile-agent'),
|
|
146
|
+
ResourceProfile = require('../util/resourceprofile'),
|
|
147
|
+
SecurityMaster = require('../net/security-master');
|
|
148
|
+
|
|
149
|
+
var profile = new ProfilePack();
|
|
150
|
+
var service = new TxRecord();
|
|
151
|
+
profile.time = Long.fromValue(ctx.start_time);
|
|
152
|
+
service.endTime = DateUtil.currentTime();
|
|
153
|
+
service.elapsed = ctx.getElapsedTime();
|
|
154
|
+
service.service = ctx.service_hash;
|
|
155
|
+
service.cpuTime = ResourceProfile.getCPUTime() - ctx.start_cpu;
|
|
156
|
+
service.malloc = ResourceProfile.getUsedHeapSize() - ctx.start_malloc;
|
|
157
|
+
if(service.malloc < 0) { service.malloc = 0; }
|
|
158
|
+
service.seq = ctx.txid;
|
|
159
|
+
service.sqlCount = ctx.sql_count;
|
|
160
|
+
service.sqlTime = ctx.sql_time;
|
|
161
|
+
service.sqlFetchCount = ctx.rs_count;
|
|
162
|
+
service.sqlFetchTime = parseInt(ctx.rs_time);
|
|
163
|
+
service.ipaddr = ctx.remoteIp;
|
|
164
|
+
service.userid = ctx.userid;
|
|
165
|
+
|
|
166
|
+
service.mcaller_pcode = ctx.mcaller_pcode;
|
|
167
|
+
service.mcaller_okind = ctx.mcaller_okind;
|
|
168
|
+
service.mcaller_oid = ctx.mcaller_oid;
|
|
169
|
+
|
|
170
|
+
if (ctx.error.isZero()==false/*long*/) {
|
|
171
|
+
service.error = ctx.error;
|
|
172
|
+
service.errorLevel = EventLevel.WARNING;
|
|
173
|
+
}
|
|
174
|
+
service.userAgent = ctx.userAgent;
|
|
175
|
+
service.referer = ctx.referer;
|
|
176
|
+
|
|
177
|
+
service.httpcCount = ctx.httpc_count;
|
|
178
|
+
service.httpcTime = ctx.httpc_time;
|
|
179
|
+
service.status = ctx.status;
|
|
180
|
+
|
|
181
|
+
service.http_method=TxRecord.HTTP_METHOD[ctx.http_method] || TxRecord.WEB_GET;
|
|
182
|
+
|
|
183
|
+
MeterService.add(service.service, service.elapsed, service.errorLevel, service.mcaller_pcode, service.mcaller_okind, service.mcaller_oid , service.apdex);
|
|
184
|
+
|
|
185
|
+
profile.oid = SecurityMaster.OID;
|
|
186
|
+
profile.service = service;
|
|
187
|
+
|
|
188
|
+
var self = this;
|
|
189
|
+
setTimeout(function () {
|
|
190
|
+
DataProfileAgent.sendProfile(ctx, profile, false);
|
|
191
|
+
self.end(ctx._id);
|
|
192
|
+
ctx = null;
|
|
193
|
+
}, 100);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
196
|
module.exports = new TraceContextManager();
|
|
@@ -1,135 +1,135 @@
|
|
|
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 ProfileCollector = require('./profile-collector'),
|
|
8
|
-
IntKeyMap = require('../util/intkey-map'),
|
|
9
|
-
KeyGen = require('../util/keygen'),
|
|
10
|
-
StringKeyLinkedMap = require('../util/stringkey-linkedmap');
|
|
11
|
-
Hexa32 = require('../util/hexa32'),
|
|
12
|
-
Logger = require('../logger'),
|
|
13
|
-
Long = require('long');
|
|
14
|
-
|
|
15
|
-
function TraceContext(id) {
|
|
16
|
-
this._id = id;
|
|
17
|
-
this.isStaticContents = false;
|
|
18
|
-
this.profile = new ProfileCollector(this);
|
|
19
|
-
|
|
20
|
-
this.txid = KeyGen.next();
|
|
21
|
-
this.thread = null;
|
|
22
|
-
this.thread_id = 0;
|
|
23
|
-
|
|
24
|
-
this.start_cpu = 0;
|
|
25
|
-
this.start_malloc = 0;
|
|
26
|
-
this.start_time = 0;
|
|
27
|
-
|
|
28
|
-
this.status = 0;
|
|
29
|
-
|
|
30
|
-
this.service_hash = 0;
|
|
31
|
-
this.service_name = '';
|
|
32
|
-
this.remoteIp = 0;
|
|
33
|
-
this.error = Long.ZERO;
|
|
34
|
-
|
|
35
|
-
this.http_method = '';
|
|
36
|
-
this.http_query = '';
|
|
37
|
-
this.http_content_type = '';
|
|
38
|
-
|
|
39
|
-
this.sql_count = 0;
|
|
40
|
-
this.sql_time = 0;
|
|
41
|
-
|
|
42
|
-
this.sql_insert = 0;
|
|
43
|
-
this.sql_update = 0;
|
|
44
|
-
this.sql_delete = 0;
|
|
45
|
-
this.sql_select = 0;
|
|
46
|
-
this.sql_others = 0;
|
|
47
|
-
|
|
48
|
-
this.executed_sqlhash = 0;
|
|
49
|
-
this.active_sqlhash = 0;
|
|
50
|
-
this.active_dbc = 0;
|
|
51
|
-
//this.active_crud = 0;
|
|
52
|
-
|
|
53
|
-
this.httpc_count = 0;
|
|
54
|
-
this.httpc_time = 0;
|
|
55
|
-
this.httpc_url = '';
|
|
56
|
-
|
|
57
|
-
this.active_httpc_hash = 0;
|
|
58
|
-
this.httpc_host = '';
|
|
59
|
-
this.httpc_port = 0;
|
|
60
|
-
|
|
61
|
-
this.userid = Long.ZERO;
|
|
62
|
-
this.userAgent = 0;
|
|
63
|
-
this.userAgentString = '';
|
|
64
|
-
this.referer = 0;
|
|
65
|
-
this.login = '';
|
|
66
|
-
this.debug_sql_call = false;
|
|
67
|
-
this.lastSqlStep = null; /*SqlStepX*/
|
|
68
|
-
this.profileActive = 0;
|
|
69
|
-
|
|
70
|
-
this.jdbc_updated = false;
|
|
71
|
-
this.jdbc_update_record = 0;
|
|
72
|
-
this.jdbc_identity = 0;
|
|
73
|
-
this.jdbc_commit = 0;
|
|
74
|
-
this.resultSql = new IntKeyMap().setMax(11);
|
|
75
|
-
|
|
76
|
-
this.rs_count = 0;
|
|
77
|
-
this.rs_time = 0;
|
|
78
|
-
this.db_opening = false;
|
|
79
|
-
this.socket_connecting = false;
|
|
80
|
-
|
|
81
|
-
this.mtid=Long.ZERO;
|
|
82
|
-
this.mdepth = 0;
|
|
83
|
-
this.mcaller_pcode = 0;
|
|
84
|
-
this.mcaller_okind = 0;
|
|
85
|
-
this.mcaller_oid = 0;
|
|
86
|
-
this.mcallee = Long.ZERO;
|
|
87
|
-
this.custid = null;
|
|
88
|
-
this.mcaller_txid = Long.ZERO;
|
|
89
|
-
this.mcaller_spec = null;
|
|
90
|
-
this.mcaller_url_hash = 0;
|
|
91
|
-
this.mtid_build_checked = false;
|
|
92
|
-
|
|
93
|
-
this.stack = [];
|
|
94
|
-
|
|
95
|
-
this.http_host='';
|
|
96
|
-
this.http_host_hash=0;
|
|
97
|
-
|
|
98
|
-
this.last_footprint_time=Date.now();
|
|
99
|
-
this.last_footprint_desc="start transaction";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
TraceContext.prototype.footprint=function(desc){
|
|
103
|
-
this.last_footprint_desc=desc;
|
|
104
|
-
}
|
|
105
|
-
TraceContext.prototype.getElapsedTime = function () {
|
|
106
|
-
return Date.now() - this.start_time;
|
|
107
|
-
}
|
|
108
|
-
TraceContext.prototype.resetStartTime = function () {
|
|
109
|
-
this.start_time = Date.now();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
var poids= new StringKeyLinkedMap(7, 1).setMax(301);
|
|
113
|
-
TraceContext.prototype.setCallerPOID= function (poidStr) {
|
|
114
|
-
try {
|
|
115
|
-
var poid = poids.get(poidStr);
|
|
116
|
-
if (poid==null) {
|
|
117
|
-
var x = poidStr.indexOf(',');
|
|
118
|
-
var s1 = poidStr.substring(0, x);
|
|
119
|
-
var pcode = Hexa32.toNumber32(s1);
|
|
120
|
-
var y = poidStr.indexOf( ',',x + 1);
|
|
121
|
-
s1 = poidStr.substring(x + 1, y);
|
|
122
|
-
var okind = ((s1.length == 0) ? 0 :Hexa32.toNumber32(s1));
|
|
123
|
-
s1 = poidStr.substring(y + 1);
|
|
124
|
-
var oid = s1.length == 0 ? 0 : Hexa32.toNumber32(s1);
|
|
125
|
-
poid = {pcode : pcode, okind :okind, oid:oid};
|
|
126
|
-
poids.put(poidStr, poid);
|
|
127
|
-
}
|
|
128
|
-
this.mcaller_pcode = poid.pcode;
|
|
129
|
-
this.mcaller_okind = poid.okind;
|
|
130
|
-
this.mcaller_oid = poid.oid;
|
|
131
|
-
} catch (e) {
|
|
132
|
-
Logger.printError('WHATAP-999', 'TraceContext (setCallerPOID)', e, true);
|
|
133
|
-
}
|
|
134
|
-
};
|
|
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 ProfileCollector = require('./profile-collector'),
|
|
8
|
+
IntKeyMap = require('../util/intkey-map'),
|
|
9
|
+
KeyGen = require('../util/keygen'),
|
|
10
|
+
StringKeyLinkedMap = require('../util/stringkey-linkedmap');
|
|
11
|
+
Hexa32 = require('../util/hexa32'),
|
|
12
|
+
Logger = require('../logger'),
|
|
13
|
+
Long = require('long');
|
|
14
|
+
|
|
15
|
+
function TraceContext(id) {
|
|
16
|
+
this._id = id;
|
|
17
|
+
this.isStaticContents = false;
|
|
18
|
+
this.profile = new ProfileCollector(this);
|
|
19
|
+
|
|
20
|
+
this.txid = KeyGen.next();
|
|
21
|
+
this.thread = null;
|
|
22
|
+
this.thread_id = 0;
|
|
23
|
+
|
|
24
|
+
this.start_cpu = 0;
|
|
25
|
+
this.start_malloc = 0;
|
|
26
|
+
this.start_time = 0;
|
|
27
|
+
|
|
28
|
+
this.status = 0;
|
|
29
|
+
|
|
30
|
+
this.service_hash = 0;
|
|
31
|
+
this.service_name = '';
|
|
32
|
+
this.remoteIp = 0;
|
|
33
|
+
this.error = Long.ZERO;
|
|
34
|
+
|
|
35
|
+
this.http_method = '';
|
|
36
|
+
this.http_query = '';
|
|
37
|
+
this.http_content_type = '';
|
|
38
|
+
|
|
39
|
+
this.sql_count = 0;
|
|
40
|
+
this.sql_time = 0;
|
|
41
|
+
|
|
42
|
+
this.sql_insert = 0;
|
|
43
|
+
this.sql_update = 0;
|
|
44
|
+
this.sql_delete = 0;
|
|
45
|
+
this.sql_select = 0;
|
|
46
|
+
this.sql_others = 0;
|
|
47
|
+
|
|
48
|
+
this.executed_sqlhash = 0;
|
|
49
|
+
this.active_sqlhash = 0;
|
|
50
|
+
this.active_dbc = 0;
|
|
51
|
+
//this.active_crud = 0;
|
|
52
|
+
|
|
53
|
+
this.httpc_count = 0;
|
|
54
|
+
this.httpc_time = 0;
|
|
55
|
+
this.httpc_url = '';
|
|
56
|
+
|
|
57
|
+
this.active_httpc_hash = 0;
|
|
58
|
+
this.httpc_host = '';
|
|
59
|
+
this.httpc_port = 0;
|
|
60
|
+
|
|
61
|
+
this.userid = Long.ZERO;
|
|
62
|
+
this.userAgent = 0;
|
|
63
|
+
this.userAgentString = '';
|
|
64
|
+
this.referer = 0;
|
|
65
|
+
this.login = '';
|
|
66
|
+
this.debug_sql_call = false;
|
|
67
|
+
this.lastSqlStep = null; /*SqlStepX*/
|
|
68
|
+
this.profileActive = 0;
|
|
69
|
+
|
|
70
|
+
this.jdbc_updated = false;
|
|
71
|
+
this.jdbc_update_record = 0;
|
|
72
|
+
this.jdbc_identity = 0;
|
|
73
|
+
this.jdbc_commit = 0;
|
|
74
|
+
this.resultSql = new IntKeyMap().setMax(11);
|
|
75
|
+
|
|
76
|
+
this.rs_count = 0;
|
|
77
|
+
this.rs_time = 0;
|
|
78
|
+
this.db_opening = false;
|
|
79
|
+
this.socket_connecting = false;
|
|
80
|
+
|
|
81
|
+
this.mtid=Long.ZERO;
|
|
82
|
+
this.mdepth = 0;
|
|
83
|
+
this.mcaller_pcode = 0;
|
|
84
|
+
this.mcaller_okind = 0;
|
|
85
|
+
this.mcaller_oid = 0;
|
|
86
|
+
this.mcallee = Long.ZERO;
|
|
87
|
+
this.custid = null;
|
|
88
|
+
this.mcaller_txid = Long.ZERO;
|
|
89
|
+
this.mcaller_spec = null;
|
|
90
|
+
this.mcaller_url_hash = 0;
|
|
91
|
+
this.mtid_build_checked = false;
|
|
92
|
+
|
|
93
|
+
this.stack = [];
|
|
94
|
+
|
|
95
|
+
this.http_host='';
|
|
96
|
+
this.http_host_hash=0;
|
|
97
|
+
|
|
98
|
+
this.last_footprint_time=Date.now();
|
|
99
|
+
this.last_footprint_desc="start transaction";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
TraceContext.prototype.footprint=function(desc){
|
|
103
|
+
this.last_footprint_desc=desc;
|
|
104
|
+
}
|
|
105
|
+
TraceContext.prototype.getElapsedTime = function () {
|
|
106
|
+
return Date.now() - this.start_time;
|
|
107
|
+
}
|
|
108
|
+
TraceContext.prototype.resetStartTime = function () {
|
|
109
|
+
this.start_time = Date.now();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
var poids= new StringKeyLinkedMap(7, 1).setMax(301);
|
|
113
|
+
TraceContext.prototype.setCallerPOID= function (poidStr) {
|
|
114
|
+
try {
|
|
115
|
+
var poid = poids.get(poidStr);
|
|
116
|
+
if (poid==null) {
|
|
117
|
+
var x = poidStr.indexOf(',');
|
|
118
|
+
var s1 = poidStr.substring(0, x);
|
|
119
|
+
var pcode = Hexa32.toNumber32(s1);
|
|
120
|
+
var y = poidStr.indexOf( ',',x + 1);
|
|
121
|
+
s1 = poidStr.substring(x + 1, y);
|
|
122
|
+
var okind = ((s1.length == 0) ? 0 :Hexa32.toNumber32(s1));
|
|
123
|
+
s1 = poidStr.substring(y + 1);
|
|
124
|
+
var oid = s1.length == 0 ? 0 : Hexa32.toNumber32(s1);
|
|
125
|
+
poid = {pcode : pcode, okind :okind, oid:oid};
|
|
126
|
+
poids.put(poidStr, poid);
|
|
127
|
+
}
|
|
128
|
+
this.mcaller_pcode = poid.pcode;
|
|
129
|
+
this.mcaller_okind = poid.okind;
|
|
130
|
+
this.mcaller_oid = poid.oid;
|
|
131
|
+
} catch (e) {
|
|
132
|
+
Logger.printError('WHATAP-999', 'TraceContext (setCallerPOID)', e, true);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
135
|
module.exports = TraceContext;
|