whatap 0.5.26 → 1.0.0
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/agent/darwin/arm64/whatap_nodejs +0 -0
- package/agent/linux/amd64/whatap_nodejs +0 -0
- package/agent/linux/arm64/whatap_nodejs +0 -0
- package/build.txt +4 -0
- package/lib/conf/config-default.js +3 -10
- package/lib/conf/configure.js +349 -369
- package/lib/conf/license.js +1 -1
- package/lib/control/packagectr-helper.js +3 -34
- package/lib/core/agent.js +882 -176
- package/lib/core/interceptor.js +6 -6
- package/lib/core/shimmer.js +36 -82
- package/lib/counter/counter-manager.js +8 -79
- package/lib/counter/task/activetransaction.js +17 -68
- package/lib/io/data-inputx.js +3 -13
- package/lib/io/data-outputx.js +206 -268
- package/lib/logger.js +6 -6
- package/lib/net/security-master.js +20 -139
- package/lib/observers/apollo-server-observer.js +27 -33
- package/lib/observers/global-observer.js +80 -155
- package/lib/observers/http-observer.js +236 -666
- package/lib/observers/ioredis-observer.js +294 -0
- package/lib/observers/maria-observer.js +362 -204
- package/lib/observers/mongodb-observer.js +226 -169
- package/lib/observers/mongoose-observer.js +323 -518
- package/lib/observers/mssql-observer.js +418 -177
- package/lib/observers/mysql-observer.js +449 -342
- package/lib/observers/mysql2-observer.js +358 -396
- package/lib/observers/oracle-observer.js +384 -559
- package/lib/observers/pgsql-observer.js +489 -231
- package/lib/observers/prisma-observer.js +92 -303
- package/lib/observers/process-observer.js +35 -79
- package/lib/observers/redis-observer.js +331 -166
- package/lib/observers/socket.io-observer.js +187 -226
- package/lib/observers/websocket-observer.js +301 -175
- package/lib/pack/counter-pack.js +0 -3
- package/lib/pack/log-sink-pack.js +52 -14
- package/lib/pack/tagcount-pack.js +4 -4
- package/lib/{counter/task → system}/gc-action.js +74 -27
- package/lib/trace/trace-context-manager.js +25 -113
- package/lib/trace/trace-context.js +7 -21
- package/lib/trace/trace-httpc.js +11 -17
- package/lib/trace/trace-sql.js +21 -29
- package/lib/udp/async_sender.js +119 -0
- package/lib/udp/index.js +17 -0
- package/lib/udp/packet_enum.js +52 -0
- package/lib/udp/packet_queue.js +69 -0
- package/lib/udp/packet_type_enum.js +33 -0
- package/lib/udp/param_def.js +72 -0
- package/lib/udp/udp_session.js +336 -0
- package/lib/util/escape-literal-sql.js +5 -5
- package/lib/util/hashutil.js +18 -18
- package/lib/util/keygen.js +3 -0
- package/lib/util/linkedset.js +2 -1
- package/lib/util/nodeutil.js +1 -2
- package/lib/util/sql-util.js +178 -0
- package/lib/util/trace-helper.js +91 -0
- package/lib/util/transfer.js +58 -0
- package/lib/value/map-value.js +2 -3
- package/package.json +5 -10
- package/lib/conf/conf-sys-mon.js +0 -101
- package/lib/control/cmd-config.js +0 -24
- package/lib/control/control-handler.js +0 -367
- package/lib/core/request-agent.js +0 -27
- package/lib/counter/meter/meter-activex.js +0 -67
- package/lib/counter/meter/meter-httpc.js +0 -57
- package/lib/counter/meter/meter-resource.js +0 -9
- package/lib/counter/meter/meter-service.js +0 -168
- package/lib/counter/meter/meter-socket.io.js +0 -51
- package/lib/counter/meter/meter-sql.js +0 -71
- package/lib/counter/meter/meter-users.js +0 -58
- package/lib/counter/meter.js +0 -183
- package/lib/counter/task/agentinfo.js +0 -107
- package/lib/counter/task/gcstat.js +0 -34
- package/lib/counter/task/heapmem.js +0 -25
- package/lib/counter/task/httpc.js +0 -76
- package/lib/counter/task/metering-info.js +0 -125
- package/lib/counter/task/proc-cpu.js +0 -29
- package/lib/counter/task/realtimeuser.js +0 -31
- package/lib/counter/task/res/systemECSTask.js +0 -39
- package/lib/counter/task/res/systemKubeTask.js +0 -53
- package/lib/counter/task/res/util/awsEcsClientThread.js +0 -218
- package/lib/counter/task/res/util/linuxProcStatUtil.js +0 -14
- package/lib/counter/task/res-sys-cpu.js +0 -62
- package/lib/counter/task/service.js +0 -202
- package/lib/counter/task/socketio.js +0 -30
- package/lib/counter/task/sql.js +0 -105
- package/lib/counter/task/systemperf.js +0 -43
- package/lib/data/datapack-sender.js +0 -289
- package/lib/data/dataprofile-agent.js +0 -162
- package/lib/data/datatext-agent.js +0 -135
- package/lib/data/event-level.js +0 -15
- package/lib/data/test.js +0 -49
- package/lib/data/zipprofile.js +0 -197
- package/lib/env/constants.js +0 -21
- package/lib/error/error-handler.js +0 -437
- package/lib/kube/kube-client.js +0 -144
- package/lib/lang/text-types.js +0 -58
- package/lib/logsink/line-log-util.js +0 -87
- package/lib/logsink/line-log.js +0 -12
- package/lib/logsink/log-sender.js +0 -78
- package/lib/logsink/log-tracer.js +0 -40
- package/lib/logsink/sender-util.js +0 -56
- package/lib/logsink/zip/zip-send.js +0 -177
- package/lib/net/netflag.js +0 -55
- package/lib/net/receiver.js +0 -66
- package/lib/net/sender.js +0 -141
- package/lib/net/tcp-return.js +0 -18
- package/lib/net/tcp-session.js +0 -286
- package/lib/net/tcpreq-client-proxy.js +0 -70
- package/lib/net/tcprequest-mgr.js +0 -58
- package/lib/observers/cluster-observer.js +0 -22
- package/lib/observers/express-observer.js +0 -215
- package/lib/observers/file-observer.js +0 -184
- package/lib/observers/grpc-observer.js +0 -336
- package/lib/observers/memcached-observer.js +0 -56
- package/lib/observers/mongo-observer.js +0 -317
- package/lib/observers/net-observer.js +0 -77
- package/lib/observers/promise-observer.js +0 -31
- package/lib/observers/schedule-observer.js +0 -67
- package/lib/observers/stream-observer.js +0 -19
- package/lib/observers/thrift-observer.js +0 -197
- package/lib/pack/activestack-pack.js +0 -55
- package/lib/pack/apenum.js +0 -8
- package/lib/pack/errorsnap-pack.js +0 -69
- package/lib/pack/event-pack.js +0 -54
- package/lib/pack/hitmap-pack.js +0 -63
- package/lib/pack/hitmap-pack1.js +0 -152
- package/lib/pack/netstat.js +0 -15
- package/lib/pack/otype.js +0 -7
- package/lib/pack/profile-pack.js +0 -49
- package/lib/pack/realtimeuser-pack.js +0 -41
- package/lib/pack/stat-general-pack.js +0 -96
- package/lib/pack/staterror-pack.js +0 -120
- package/lib/pack/stathttpc-pack.js +0 -66
- package/lib/pack/stathttpc-rec.js +0 -78
- package/lib/pack/statremote-pack.js +0 -46
- package/lib/pack/statservice-pack.js +0 -63
- package/lib/pack/statservice-pack1.js +0 -88
- package/lib/pack/statservice-rec.js +0 -292
- package/lib/pack/statservice-rec_dep.js +0 -151
- package/lib/pack/statsql-pack.js +0 -69
- package/lib/pack/statsql-rec.js +0 -100
- package/lib/pack/statuseragent-pack.js +0 -44
- package/lib/pack/tagctr.js +0 -15
- package/lib/pack/text-pack.js +0 -50
- package/lib/pack/time-count.js +0 -25
- package/lib/pack/websocket.js +0 -15
- package/lib/pack/zip-pack.js +0 -70
- package/lib/pii/pii-item.js +0 -31
- package/lib/pii/pii-mask.js +0 -174
- package/lib/plugin/plugin-loadermanager.js +0 -57
- package/lib/plugin/plugin.js +0 -75
- package/lib/service/tx-record.js +0 -332
- package/lib/stat/stat-error.js +0 -116
- package/lib/stat/stat-httpc.js +0 -98
- package/lib/stat/stat-remote-ip.js +0 -46
- package/lib/stat/stat-remote-ipurl.js +0 -88
- package/lib/stat/stat-sql.js +0 -113
- package/lib/stat/stat-tranx.js +0 -58
- package/lib/stat/stat-tx-caller.js +0 -160
- package/lib/stat/stat-tx-domain.js +0 -111
- package/lib/stat/stat-tx-referer.js +0 -112
- package/lib/stat/stat-useragent.js +0 -48
- package/lib/stat/timingsender.js +0 -76
- package/lib/step/activestack-step.js +0 -38
- package/lib/step/dbc-step.js +0 -36
- package/lib/step/http-stepx.js +0 -67
- package/lib/step/message-step.js +0 -40
- package/lib/step/method-stepx.js +0 -45
- package/lib/step/resultset-step.js +0 -40
- package/lib/step/securemsg-step.js +0 -44
- package/lib/step/socket-step.js +0 -46
- package/lib/step/sql-stepx.js +0 -68
- package/lib/step/sqlxtype.js +0 -16
- package/lib/step/step.js +0 -66
- package/lib/step/stepenum.js +0 -54
- package/lib/topology/link.js +0 -63
- package/lib/topology/nodeinfo.js +0 -123
- package/lib/topology/status-detector.js +0 -111
- package/lib/util/anylist.js +0 -103
- package/lib/util/cardinality/hyperloglog.js +0 -106
- package/lib/util/cardinality/murmurhash.js +0 -31
- package/lib/util/cardinality/registerset.js +0 -75
- package/lib/util/errordata.js +0 -21
- package/lib/util/iputil_x.js +0 -527
- package/lib/util/kube-util.js +0 -73
- package/lib/util/paramsecurity.js +0 -80
- package/lib/util/pre-process.js +0 -13
- package/lib/util/process-seq.js +0 -166
- package/lib/util/property-util.js +0 -36
- package/lib/util/request-queue.js +0 -70
- package/lib/util/requestdouble-queue.js +0 -72
- package/lib/util/resourceprofile.js +0 -157
- package/lib/util/stop-watch.js +0 -30
- package/lib/util/system-util.js +0 -10
- package/lib/util/userid-util.js +0 -57
package/lib/util/process-seq.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
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 fs = require('fs'),
|
|
8
|
-
path = require('path'),
|
|
9
|
-
hahsUtil = require('../util/hashutil2'),
|
|
10
|
-
IPUtil = require('../util/iputil');
|
|
11
|
-
function isLiveProcess(pid) {
|
|
12
|
-
if(!pid || pid.length === 0) return true;
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
return process.kill(pid,0)
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
return e.code === 'EPERM'
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function LockCompetition(key){
|
|
23
|
-
this.MAIN_KEY = key;
|
|
24
|
-
var Configuration = require('./../conf/configure');
|
|
25
|
-
var root = Configuration['app.root'];
|
|
26
|
-
var cwd = process.cwd();
|
|
27
|
-
if(root == undefined) {
|
|
28
|
-
root = cwd;
|
|
29
|
-
}
|
|
30
|
-
let gubun = hahsUtil.hash(IPUtil.getIp());
|
|
31
|
-
this.rootFolder = path.join(root,'SSwhatapSS').replace('SSwhatapSS',path.sep + '.'+key);
|
|
32
|
-
if(fs.existsSync(this.rootFolder) == false) {
|
|
33
|
-
fs.mkdirSync(this.rootFolder);
|
|
34
|
-
}
|
|
35
|
-
this.rootFolder += path.sep + gubun;
|
|
36
|
-
if(fs.existsSync(this.rootFolder) == false) {
|
|
37
|
-
fs.mkdirSync(this.rootFolder);
|
|
38
|
-
}
|
|
39
|
-
this.LOCK_FILE = path.join(this.rootFolder,this.MAIN_KEY+'.lock');
|
|
40
|
-
this.initComplete = false;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
LockCompetition.prototype.init = function(cb){
|
|
44
|
-
if(this.initComplete) {
|
|
45
|
-
if(cb) cb();
|
|
46
|
-
}
|
|
47
|
-
fs.mkdir( this.rootFolder, function(err){
|
|
48
|
-
if(!err || err.code === 'EEXIST'){
|
|
49
|
-
this.initComplete = true;
|
|
50
|
-
if(cb) cb();
|
|
51
|
-
}else{
|
|
52
|
-
return console.error(err);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
LockCompetition.prototype.accessAuth = function(cb){
|
|
58
|
-
var self = this;
|
|
59
|
-
self.init(function(){
|
|
60
|
-
var i = setInterval(function(){
|
|
61
|
-
self.createLockFile(path.join(self.LOCK_FILE), function(result){
|
|
62
|
-
if(result){
|
|
63
|
-
self.checkFileIndex(1, function(idx){
|
|
64
|
-
self.releaseLockFile( function(result){
|
|
65
|
-
if(result){
|
|
66
|
-
cb(idx);
|
|
67
|
-
clearInterval(i);
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
},10)
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
LockCompetition.prototype.readLockFile = function(cb){
|
|
78
|
-
fs.readFile( this.LOCK_FILE, 'utf-8', function(err,data){
|
|
79
|
-
if(cb) cb(err, data);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
LockCompetition.prototype.createLockFile = function(file, cb){
|
|
84
|
-
var self = this;
|
|
85
|
-
self.readLockFile(function(err, data){
|
|
86
|
-
if(err){
|
|
87
|
-
fs.writeFile(file, process.pid + '', 'utf-8', function(err,data){
|
|
88
|
-
if(err){
|
|
89
|
-
if(cb) return cb(false);
|
|
90
|
-
}else{
|
|
91
|
-
self.readLockFile( function(err, data){
|
|
92
|
-
if(err && cb) return cb(false);
|
|
93
|
-
if(parseInt(data) === process.pid){
|
|
94
|
-
if(cb) return cb(true);
|
|
95
|
-
}else{
|
|
96
|
-
if(cb) return cb(false);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}else{
|
|
102
|
-
if(isLiveProcess(data)){
|
|
103
|
-
if(cb) return cb(false);
|
|
104
|
-
}else{
|
|
105
|
-
fs.unlink(self.LOCK_FILE, function(err){
|
|
106
|
-
if(err){
|
|
107
|
-
if(cb) return cb(false);
|
|
108
|
-
}else{
|
|
109
|
-
if(cb) return cb(true);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
LockCompetition.prototype.releaseLockFile = function(cb){
|
|
118
|
-
var self = this;
|
|
119
|
-
fs.readFile(self.LOCK_FILE, 'utf-8', function(err,data){
|
|
120
|
-
if(err && cb) return cb(err, data);
|
|
121
|
-
|
|
122
|
-
if(parseInt(data) === process.pid){
|
|
123
|
-
fs.unlink(self.LOCK_FILE, function(err){
|
|
124
|
-
if(err){
|
|
125
|
-
if(cb) return cb(false);
|
|
126
|
-
}else{
|
|
127
|
-
if(cb) return cb(true);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}else{
|
|
131
|
-
if(cb) return cb(false);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
LockCompetition.prototype.checkFileIndex = function(idx,cb){
|
|
137
|
-
var self = this;
|
|
138
|
-
idx = idx || 1;
|
|
139
|
-
fs.readFile(path.join(self.rootFolder, self.MAIN_KEY+idx), 'utf-8', function(err,data){
|
|
140
|
-
if(err){
|
|
141
|
-
fs.writeFile(path.join(self.rootFolder, self.MAIN_KEY+idx), process.pid + '', 'utf-8', function(err){
|
|
142
|
-
if(err){
|
|
143
|
-
self.checkFileIndex(++idx,cb);
|
|
144
|
-
}else{
|
|
145
|
-
if(cb) cb(idx);
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}else{
|
|
149
|
-
if( isLiveProcess(data) ){
|
|
150
|
-
self.checkFileIndex(++idx,cb);
|
|
151
|
-
}else{
|
|
152
|
-
fs.writeFile(path.join(self.rootFolder, self.MAIN_KEY+idx), process.pid + '', 'utf-8', function(result){
|
|
153
|
-
if(err){
|
|
154
|
-
self.checkFileIndex(++idx,cb);
|
|
155
|
-
}else{
|
|
156
|
-
if(cb) cb(idx);
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
module.exports = function(key){
|
|
165
|
-
return new LockCompetition(key);
|
|
166
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
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 MapValue = require('./../value/map-value')
|
|
8
|
-
|
|
9
|
-
module.exports = {
|
|
10
|
-
readProperty: function(str, spliter, type){
|
|
11
|
-
var result = undefined;
|
|
12
|
-
if(type && type.constructor === MapValue){
|
|
13
|
-
result = new MapValue();
|
|
14
|
-
}else{
|
|
15
|
-
result = {};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if(str.constructor === String){
|
|
19
|
-
var rowProps = str.split('\n');
|
|
20
|
-
|
|
21
|
-
for(var i = 0 ; i < rowProps.length; i++){
|
|
22
|
-
if(rowProps.indexOf('#') === 0 ) continue;
|
|
23
|
-
|
|
24
|
-
var p = rowProps[i].split(spliter);
|
|
25
|
-
if(p.length > 1){
|
|
26
|
-
if(result.constructor === MapValue){
|
|
27
|
-
result.put(p[0], p[1]);
|
|
28
|
-
}else{
|
|
29
|
-
result[p[0]] = p[1];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
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 LinkedList = require('./linkedlist');
|
|
8
|
-
|
|
9
|
-
function RequestQueue(capacity) {
|
|
10
|
-
this.capacity = capacity;
|
|
11
|
-
this.queue = new LinkedList();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
RequestQueue.prototype.get = function () {
|
|
15
|
-
if(this.queue.size() > 0) {
|
|
16
|
-
return this.queue.removeFirst();
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
};
|
|
20
|
-
RequestQueue.prototype.getByTimeout = async function (timeout) {
|
|
21
|
-
try{
|
|
22
|
-
if (this.queue.size() > 0) {
|
|
23
|
-
return this.queue.removeFirst()
|
|
24
|
-
}
|
|
25
|
-
var timeto = Date.now() + timeout;
|
|
26
|
-
var time = timeout;
|
|
27
|
-
while (this.queue.size() === 0) {
|
|
28
|
-
try {
|
|
29
|
-
if (time > 0) {
|
|
30
|
-
await new Promise(resolve => setTimeout(resolve, time));
|
|
31
|
-
}
|
|
32
|
-
} catch (e) {
|
|
33
|
-
}
|
|
34
|
-
time = timeto - Date.now();
|
|
35
|
-
if (time <= 0) {
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (this.queue.size() > 0) {
|
|
40
|
-
return this.queue.removeFirst();
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}catch (e) {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
RequestQueue.prototype.put = function (o) {
|
|
48
|
-
if(this.capacity <= 0 || this.queue.size() < this.capacity) {
|
|
49
|
-
this.queue.add(o);
|
|
50
|
-
return true;
|
|
51
|
-
} else {
|
|
52
|
-
failed(o);
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
RequestQueue.prototype.size = function () {
|
|
57
|
-
return this.queue.size();
|
|
58
|
-
};
|
|
59
|
-
RequestQueue.prototype.clear = function () {
|
|
60
|
-
this.queue = new LinkedList();
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
var failed = function (v) {
|
|
64
|
-
|
|
65
|
-
};
|
|
66
|
-
var overflowed = function (v) {
|
|
67
|
-
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
module.exports = RequestQueue;
|
|
@@ -1,72 +0,0 @@
|
|
|
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 LinkedList = require('./linkedlist');
|
|
8
|
-
var RequestDoubleQueue = function(capacity1, capacity2){
|
|
9
|
-
this.capacity1 = capacity1;
|
|
10
|
-
this.capacity2 = capacity2;
|
|
11
|
-
this.queue1 = new LinkedList();
|
|
12
|
-
this.queue2 = new LinkedList();
|
|
13
|
-
};
|
|
14
|
-
RequestDoubleQueue.prototype.size=function(){
|
|
15
|
-
return {q1:this.queue1.size(), q2:this.queue2.size()};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
RequestDoubleQueue.prototype.get = function(){
|
|
19
|
-
if(this.queue1.size() > 0 ){
|
|
20
|
-
return this.queue1.removeFirst();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if(this.queue2.size() > 0){
|
|
24
|
-
return this.queue2.removeFirst();
|
|
25
|
-
}
|
|
26
|
-
return null;
|
|
27
|
-
};
|
|
28
|
-
RequestDoubleQueue.prototype.hasNext = function(){
|
|
29
|
-
if(this.queue1.hasNext() || this.queue2.hasNext()) return true;
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
32
|
-
RequestDoubleQueue.prototype.putForce1 = function(o) {
|
|
33
|
-
return this.putForce(this.queue1, this.capacity1, o);
|
|
34
|
-
};
|
|
35
|
-
RequestDoubleQueue.prototype.putForce2 = function(o) {
|
|
36
|
-
return this.putForce(this.queue2, this.capacity2, o);
|
|
37
|
-
};
|
|
38
|
-
RequestDoubleQueue.prototype.putForce = function(q /* LinkedList */, sz /* int */, o ) {
|
|
39
|
-
if(sz <= 0 || q.size() < this.capacity1){
|
|
40
|
-
q.add(o);
|
|
41
|
-
return true;
|
|
42
|
-
}else{
|
|
43
|
-
while (q.size() >= sz){
|
|
44
|
-
var v = q.removeFirst();
|
|
45
|
-
overflowed(v);
|
|
46
|
-
}
|
|
47
|
-
q.add(o);
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
RequestDoubleQueue.prototype.put = function(q /* LinkedList */, capacity /* int */, o ) {
|
|
52
|
-
if(capacity <= 0 || q.size() < capacity){
|
|
53
|
-
q.add(o);
|
|
54
|
-
return true;
|
|
55
|
-
}else{
|
|
56
|
-
failed(o);
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
RequestDoubleQueue.prototype.put1 = function(o) {
|
|
61
|
-
return this.put(this.queue1, this.capacity1, o);
|
|
62
|
-
};
|
|
63
|
-
RequestDoubleQueue.prototype.put2 = function(o) {
|
|
64
|
-
return this.put(this.queue2, this.capacity2, o);
|
|
65
|
-
};
|
|
66
|
-
var failed = function(v /* object */) {
|
|
67
|
-
};
|
|
68
|
-
var overflowed = function(v /* object */) {
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
module.exports = RequestDoubleQueue;
|
|
72
|
-
|
|
@@ -1,157 +0,0 @@
|
|
|
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 platform = process.platform,
|
|
8
|
-
arch = process.arch,
|
|
9
|
-
version = parseFloat(process.version.slice(1));
|
|
10
|
-
|
|
11
|
-
var os = require('os'),
|
|
12
|
-
v8 = require('v8'),
|
|
13
|
-
// gcstat = require('../../bindings/'+platform+'/'+arch+'/whatap.node'),
|
|
14
|
-
Long = require('long'),
|
|
15
|
-
df = require('df'),
|
|
16
|
-
pusage = require('pidusage');
|
|
17
|
-
|
|
18
|
-
function ResourceProfile() {
|
|
19
|
-
var self = this;
|
|
20
|
-
self.gc_count = 0;
|
|
21
|
-
self.gc_time =0;
|
|
22
|
-
self.cpu_info = {
|
|
23
|
-
times : 0,
|
|
24
|
-
usage : 0,
|
|
25
|
-
core : 0,
|
|
26
|
-
proc : 0
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
/** Disk usage */
|
|
30
|
-
if(os.type() != 'Windows_NT'){
|
|
31
|
-
setInterval(function () {
|
|
32
|
-
df(function (err, table) {
|
|
33
|
-
if(err || table == null) {
|
|
34
|
-
return self.disk = 0;
|
|
35
|
-
}
|
|
36
|
-
table.forEach(function(n, i){
|
|
37
|
-
if(n.mountpoint === '/'){
|
|
38
|
-
self.disk = n.percent;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
}, 1000);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Process cpu */
|
|
46
|
-
setInterval(function () {
|
|
47
|
-
pusage.stat(process.pid, function(err, stat) {
|
|
48
|
-
if(err || stat == null) return;
|
|
49
|
-
self.pcpu = stat.cpu;
|
|
50
|
-
self.cpu_info.proc = stat.cpu;
|
|
51
|
-
});
|
|
52
|
-
}, 1000);
|
|
53
|
-
|
|
54
|
-
/** Machine CPU */
|
|
55
|
-
self.setCPUUsage();
|
|
56
|
-
// gcstat.startMonitor(function (starttime, duration, type, flag) {
|
|
57
|
-
// // starttime => second
|
|
58
|
-
// if(self.gc_count == null) {
|
|
59
|
-
// self.gc_count = 0;
|
|
60
|
-
// self.gc_time = 0;
|
|
61
|
-
// }
|
|
62
|
-
// self.gc_count = self.gc_count.add(1);
|
|
63
|
-
// self.gc_time = self.gc_time.add(Number(duration));
|
|
64
|
-
// });
|
|
65
|
-
}
|
|
66
|
-
ResourceProfile.prototype.setCPUUsage = function () {
|
|
67
|
-
var self = this;
|
|
68
|
-
var before = self.getCPUInfo();
|
|
69
|
-
|
|
70
|
-
setTimeout(function () {
|
|
71
|
-
|
|
72
|
-
var after = self.getCPUInfo();
|
|
73
|
-
|
|
74
|
-
var idle = after.idle - before.idle;
|
|
75
|
-
var total = after.total - before.total;
|
|
76
|
-
|
|
77
|
-
var percent = idle / total * 100;
|
|
78
|
-
self.cpu_info.times = total;
|
|
79
|
-
self.cpu_info.usage = 100 - percent;
|
|
80
|
-
self.cpu_info.core = os.cpus().length;
|
|
81
|
-
|
|
82
|
-
setTimeout(function () {
|
|
83
|
-
self.setCPUUsage();
|
|
84
|
-
}, 100);
|
|
85
|
-
|
|
86
|
-
}, 1000);
|
|
87
|
-
|
|
88
|
-
};
|
|
89
|
-
ResourceProfile.prototype.getCPUInfo = function () {
|
|
90
|
-
var cpus = os.cpus();
|
|
91
|
-
|
|
92
|
-
var user = 0;
|
|
93
|
-
var nice = 0;
|
|
94
|
-
var sys = 0;
|
|
95
|
-
var idle = 0;
|
|
96
|
-
var irq = 0;
|
|
97
|
-
var total = 0;
|
|
98
|
-
|
|
99
|
-
for(var cpu in cpus){
|
|
100
|
-
if (!cpus.hasOwnProperty(cpu)) continue;
|
|
101
|
-
user += cpus[cpu].times.user;
|
|
102
|
-
nice += cpus[cpu].times.nice;
|
|
103
|
-
sys += cpus[cpu].times.sys;
|
|
104
|
-
irq += cpus[cpu].times.irq;
|
|
105
|
-
idle += cpus[cpu].times.idle;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
var total = user + nice + sys + idle + irq;
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
'user' : user,
|
|
112
|
-
'idle': idle,
|
|
113
|
-
'total': total
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
ResourceProfile.prototype.getCPU = function(){
|
|
117
|
-
return this.cpu_info;
|
|
118
|
-
};
|
|
119
|
-
ResourceProfile.prototype.getMemory = function(){
|
|
120
|
-
var stat = v8.getHeapStatistics();
|
|
121
|
-
var data = {};
|
|
122
|
-
data.heap_total = parseInt(stat.total_heap_size/1024);
|
|
123
|
-
data.heap_used = parseInt(stat.used_heap_size/1024);
|
|
124
|
-
data.usage = (os.totalmem() - os.freemem()) * 100/os.totalmem();
|
|
125
|
-
|
|
126
|
-
return data;
|
|
127
|
-
};
|
|
128
|
-
ResourceProfile.prototype.getMemoryV2 = function(){
|
|
129
|
-
var stat = v8.getHeapStatistics();
|
|
130
|
-
var data = {};
|
|
131
|
-
data.heap_total = parseInt(stat.total_heap_size);
|
|
132
|
-
data.heap_used = parseInt(stat.used_heap_size);
|
|
133
|
-
data.usage = (os.totalmem() - os.freemem()) * 100/os.totalmem();
|
|
134
|
-
|
|
135
|
-
return data;
|
|
136
|
-
};
|
|
137
|
-
ResourceProfile.prototype.getDisk = function(){
|
|
138
|
-
return {'usage' : this.disk};
|
|
139
|
-
};
|
|
140
|
-
ResourceProfile.prototype.getCPUTime = function () {
|
|
141
|
-
var total = 0;
|
|
142
|
-
var cpus = os.cpus();
|
|
143
|
-
cpus.forEach(function(n){
|
|
144
|
-
total += n.times['user'];
|
|
145
|
-
});
|
|
146
|
-
total = parseInt(total / cpus.length );
|
|
147
|
-
return total;
|
|
148
|
-
};
|
|
149
|
-
ResourceProfile.prototype.getUsedHeapSize = function () {
|
|
150
|
-
var stat = v8.getHeapStatistics();
|
|
151
|
-
return stat.used_heap_size;
|
|
152
|
-
};
|
|
153
|
-
ResourceProfile.prototype.getCurrentProcGcInfo = function () {
|
|
154
|
-
return [this.gc_count, this.gc_time];
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
module.exports = new ResourceProfile();
|
package/lib/util/stop-watch.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
var DateUtil = require('./../util/dateutil')
|
|
2
|
-
|
|
3
|
-
var StopWatch = function(){
|
|
4
|
-
this.stime = DateUtil.currentTime();
|
|
5
|
-
this.etime = 0;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
StopWatch.prototype.start = function(){
|
|
9
|
-
this.stime = DateUtil.currentTime();
|
|
10
|
-
this.etime = 0;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
StopWatch.prototype.getTime = function(){
|
|
14
|
-
if(this.etime === 0){
|
|
15
|
-
var now = DateUtil.currentTime();
|
|
16
|
-
return now - this.stime;
|
|
17
|
-
}else{
|
|
18
|
-
return this.etime = this.stime;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
StopWatch.prototype.stop = function(){
|
|
23
|
-
if(this.etime === 0){
|
|
24
|
-
this.etime = DateUtil.currentTime()
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return this.etime - this.stime;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
module.exports = StopWatch;
|
package/lib/util/system-util.js
DELETED
package/lib/util/userid-util.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
const WHATAP_R = "WHATAP";
|
|
8
|
-
|
|
9
|
-
var conf = require('../conf/configure'),
|
|
10
|
-
HashUtil = require('./hashutil'),
|
|
11
|
-
Hexa32 = require('./hexa32'),
|
|
12
|
-
KeyGen = require('./keygen'),
|
|
13
|
-
Long = require('long'),
|
|
14
|
-
Logger = require('../logger');
|
|
15
|
-
|
|
16
|
-
var getUserId = function (req, res, defValue) {
|
|
17
|
-
try {
|
|
18
|
-
if (conf.user_header_ticket_enabled === true) {
|
|
19
|
-
var ticket = req.headers[conf.user_header_ticket];
|
|
20
|
-
if (ticket != null && ticket.length > 0) {
|
|
21
|
-
return Long.fromNumber(HashUtil.hash(ticket));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
var cookie = req.headers.cookie;
|
|
25
|
-
if (cookie != null) {
|
|
26
|
-
if (cookie.length >= conf.trace_user_cookie_limit) {
|
|
27
|
-
return defValue;
|
|
28
|
-
}
|
|
29
|
-
var x1 = cookie.indexOf(WHATAP_R);
|
|
30
|
-
if (x1 >= 0) {
|
|
31
|
-
var value = '';
|
|
32
|
-
var x2 = cookie.indexOf(';', x1);
|
|
33
|
-
if (x2 > 0) {
|
|
34
|
-
value = cookie.substring(x1 + WHATAP_R.length + 1, x2);
|
|
35
|
-
} else {
|
|
36
|
-
value = cookie.substring(x1 + WHATAP_R.length + 1);
|
|
37
|
-
}
|
|
38
|
-
try {
|
|
39
|
-
return Hexa32.toLong32(value);
|
|
40
|
-
} catch (th) {
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
var expires= new Date(Date.now() + (86409000*365*5)).toUTCString();
|
|
45
|
-
var cookie_str = WHATAP_R + "=" + Hexa32.toString32(KeyGen.next()) + "; expires=" + expires +"; path=/";
|
|
46
|
-
res.setHeader("Set-Cookie", cookie_str);
|
|
47
|
-
} catch (e) {
|
|
48
|
-
Logger.printError('WHATAP-193', 'UserIdUtil Error', e);
|
|
49
|
-
}
|
|
50
|
-
return Long.ZERO;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
var UserIdUtil = {
|
|
54
|
-
getUserId : getUserId
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
module.exports = UserIdUtil;
|