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.
- package/README.md +32 -78
- package/lib/conf/conf-sys-mon.js +101 -0
- package/lib/conf/config-default.js +10 -3
- package/lib/conf/configure.js +369 -349
- package/lib/conf/license.js +1 -1
- package/lib/control/cmd-config.js +24 -0
- package/lib/control/control-handler.js +367 -0
- package/lib/control/packagectr-helper.js +34 -3
- package/lib/core/agent.js +176 -882
- package/lib/core/interceptor.js +6 -6
- package/lib/core/request-agent.js +27 -0
- package/lib/core/shimmer.js +82 -36
- package/lib/counter/counter-manager.js +79 -8
- package/lib/counter/meter/meter-activex.js +67 -0
- package/lib/counter/meter/meter-httpc.js +57 -0
- package/lib/counter/meter/meter-resource.js +9 -0
- package/lib/counter/meter/meter-service.js +168 -0
- package/lib/counter/meter/meter-socket.io.js +51 -0
- package/lib/counter/meter/meter-sql.js +71 -0
- package/lib/counter/meter/meter-users.js +58 -0
- package/lib/counter/meter.js +183 -0
- package/lib/counter/task/activetransaction.js +68 -17
- package/lib/counter/task/agentinfo.js +107 -0
- package/lib/{system → counter/task}/gc-action.js +27 -74
- package/lib/counter/task/gcstat.js +34 -0
- package/lib/counter/task/heapmem.js +25 -0
- package/lib/counter/task/httpc.js +76 -0
- package/lib/counter/task/metering-info.js +125 -0
- package/lib/counter/task/proc-cpu.js +29 -0
- package/lib/counter/task/realtimeuser.js +31 -0
- package/lib/counter/task/res/systemECSTask.js +39 -0
- package/lib/counter/task/res/systemKubeTask.js +53 -0
- package/lib/counter/task/res/util/awsEcsClientThread.js +218 -0
- package/lib/counter/task/res/util/linuxProcStatUtil.js +14 -0
- package/lib/counter/task/res-sys-cpu.js +62 -0
- package/lib/counter/task/service.js +202 -0
- package/lib/counter/task/socketio.js +30 -0
- package/lib/counter/task/sql.js +105 -0
- package/lib/counter/task/systemperf.js +43 -0
- package/lib/data/datapack-sender.js +289 -0
- package/lib/data/dataprofile-agent.js +162 -0
- package/lib/data/datatext-agent.js +135 -0
- package/lib/data/event-level.js +15 -0
- package/lib/data/test.js +49 -0
- package/lib/data/zipprofile.js +197 -0
- package/lib/env/constants.js +21 -0
- package/lib/error/error-handler.js +437 -0
- package/lib/io/data-inputx.js +13 -3
- package/lib/io/data-outputx.js +268 -206
- package/lib/kube/kube-client.js +144 -0
- package/lib/lang/text-types.js +58 -0
- package/lib/logger.js +6 -6
- package/lib/logsink/line-log-util.js +87 -0
- package/lib/logsink/line-log.js +12 -0
- package/lib/logsink/log-sender.js +78 -0
- package/lib/logsink/log-tracer.js +40 -0
- package/lib/logsink/sender-util.js +56 -0
- package/lib/logsink/zip/zip-send.js +177 -0
- package/lib/net/netflag.js +55 -0
- package/lib/net/receiver.js +66 -0
- package/lib/net/security-master.js +139 -20
- package/lib/net/sender.js +141 -0
- package/lib/net/tcp-return.js +18 -0
- package/lib/net/tcp-session.js +286 -0
- package/lib/net/tcpreq-client-proxy.js +70 -0
- package/lib/net/tcprequest-mgr.js +58 -0
- package/lib/observers/apollo-server-observer.js +33 -27
- package/lib/observers/cluster-observer.js +22 -0
- package/lib/observers/express-observer.js +215 -0
- package/lib/observers/file-observer.js +184 -0
- package/lib/observers/global-observer.js +155 -80
- package/lib/observers/grpc-observer.js +336 -0
- package/lib/observers/http-observer.js +666 -236
- package/lib/observers/maria-observer.js +204 -362
- package/lib/observers/memcached-observer.js +56 -0
- package/lib/observers/mongo-observer.js +317 -0
- package/lib/observers/mongodb-observer.js +169 -226
- package/lib/observers/mongoose-observer.js +518 -323
- package/lib/observers/mssql-observer.js +177 -418
- package/lib/observers/mysql-observer.js +342 -449
- package/lib/observers/mysql2-observer.js +396 -358
- package/lib/observers/net-observer.js +77 -0
- package/lib/observers/oracle-observer.js +559 -384
- package/lib/observers/pgsql-observer.js +231 -489
- package/lib/observers/prisma-observer.js +303 -92
- package/lib/observers/process-observer.js +79 -35
- package/lib/observers/promise-observer.js +31 -0
- package/lib/observers/redis-observer.js +166 -331
- package/lib/observers/schedule-observer.js +67 -0
- package/lib/observers/socket.io-observer.js +226 -187
- package/lib/observers/stream-observer.js +19 -0
- package/lib/observers/thrift-observer.js +197 -0
- package/lib/observers/websocket-observer.js +175 -301
- package/lib/pack/activestack-pack.js +55 -0
- package/lib/pack/apenum.js +8 -0
- package/lib/pack/counter-pack.js +3 -0
- package/lib/pack/errorsnap-pack.js +69 -0
- package/lib/pack/event-pack.js +54 -0
- package/lib/pack/hitmap-pack.js +63 -0
- package/lib/pack/hitmap-pack1.js +152 -0
- package/lib/pack/log-sink-pack.js +14 -52
- package/lib/pack/netstat.js +15 -0
- package/lib/pack/otype.js +7 -0
- package/lib/pack/profile-pack.js +49 -0
- package/lib/pack/realtimeuser-pack.js +41 -0
- package/lib/pack/stat-general-pack.js +96 -0
- package/lib/pack/staterror-pack.js +120 -0
- package/lib/pack/stathttpc-pack.js +66 -0
- package/lib/pack/stathttpc-rec.js +78 -0
- package/lib/pack/statremote-pack.js +46 -0
- package/lib/pack/statservice-pack.js +63 -0
- package/lib/pack/statservice-pack1.js +88 -0
- package/lib/pack/statservice-rec.js +292 -0
- package/lib/pack/statservice-rec_dep.js +151 -0
- package/lib/pack/statsql-pack.js +69 -0
- package/lib/pack/statsql-rec.js +100 -0
- package/lib/pack/statuseragent-pack.js +44 -0
- package/lib/pack/tagcount-pack.js +4 -4
- package/lib/pack/tagctr.js +15 -0
- package/lib/pack/text-pack.js +50 -0
- package/lib/pack/time-count.js +25 -0
- package/lib/pack/websocket.js +15 -0
- package/lib/pack/zip-pack.js +70 -0
- package/lib/pii/pii-item.js +31 -0
- package/lib/pii/pii-mask.js +174 -0
- package/lib/plugin/plugin-loadermanager.js +57 -0
- package/lib/plugin/plugin.js +75 -0
- package/lib/service/tx-record.js +332 -0
- package/lib/stat/stat-error.js +116 -0
- package/lib/stat/stat-httpc.js +98 -0
- package/lib/stat/stat-remote-ip.js +46 -0
- package/lib/stat/stat-remote-ipurl.js +88 -0
- package/lib/stat/stat-sql.js +113 -0
- package/lib/stat/stat-tranx.js +58 -0
- package/lib/stat/stat-tx-caller.js +160 -0
- package/lib/stat/stat-tx-domain.js +111 -0
- package/lib/stat/stat-tx-referer.js +112 -0
- package/lib/stat/stat-useragent.js +48 -0
- package/lib/stat/timingsender.js +76 -0
- package/lib/step/activestack-step.js +38 -0
- package/lib/step/dbc-step.js +36 -0
- package/lib/step/http-stepx.js +67 -0
- package/lib/step/message-step.js +40 -0
- package/lib/step/method-stepx.js +45 -0
- package/lib/step/resultset-step.js +40 -0
- package/lib/step/securemsg-step.js +44 -0
- package/lib/step/socket-step.js +46 -0
- package/lib/step/sql-stepx.js +68 -0
- package/lib/step/sqlxtype.js +16 -0
- package/lib/step/step.js +66 -0
- package/lib/step/stepenum.js +54 -0
- package/lib/topology/link.js +63 -0
- package/lib/topology/nodeinfo.js +123 -0
- package/lib/topology/status-detector.js +111 -0
- package/lib/trace/trace-context-manager.js +113 -25
- package/lib/trace/trace-context.js +21 -7
- package/lib/trace/trace-httpc.js +17 -11
- package/lib/trace/trace-sql.js +29 -21
- package/lib/util/anylist.js +103 -0
- package/lib/util/cardinality/hyperloglog.js +106 -0
- package/lib/util/cardinality/murmurhash.js +31 -0
- package/lib/util/cardinality/registerset.js +75 -0
- package/lib/util/errordata.js +21 -0
- package/lib/util/escape-literal-sql.js +5 -5
- package/lib/util/hashutil.js +18 -18
- package/lib/util/iputil_x.js +527 -0
- package/lib/util/keygen.js +0 -3
- package/lib/util/kube-util.js +73 -0
- package/lib/util/linkedset.js +1 -2
- package/lib/util/nodeutil.js +2 -1
- package/lib/util/paramsecurity.js +80 -0
- package/lib/util/pre-process.js +13 -0
- package/lib/util/process-seq.js +166 -0
- package/lib/util/property-util.js +36 -0
- package/lib/util/request-queue.js +70 -0
- package/lib/util/requestdouble-queue.js +72 -0
- package/lib/util/resourceprofile.js +157 -0
- package/lib/util/stop-watch.js +30 -0
- package/lib/util/system-util.js +10 -0
- package/lib/util/userid-util.js +57 -0
- package/lib/value/map-value.js +3 -2
- package/package.json +9 -4
- package/whatap.conf +1 -4
- 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 +0 -4
- package/lib/observers/ioredis-observer.js +0 -294
- package/lib/udp/async_sender.js +0 -119
- package/lib/udp/index.js +0 -17
- package/lib/udp/packet_enum.js +0 -52
- package/lib/udp/packet_queue.js +0 -69
- package/lib/udp/packet_type_enum.js +0 -33
- package/lib/udp/param_def.js +0 -72
- package/lib/udp/udp_session.js +0 -336
- package/lib/util/sql-util.js +0 -178
- package/lib/util/trace-helper.js +0 -91
- package/lib/util/transfer.js +0 -58
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
var KeyGen = require('./keygen'),
|
|
3
|
+
conf = require('../conf/configure'),
|
|
4
|
+
fs = require('fs'),
|
|
5
|
+
path = require('path');
|
|
6
|
+
var Buffer = require('buffer').Buffer;
|
|
7
|
+
|
|
8
|
+
var ParamSecurity = function () {
|
|
9
|
+
this.key = null;
|
|
10
|
+
this.reload();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
ParamSecurity.prototype.getKey = function () {
|
|
14
|
+
var s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
|
15
|
+
var buf = '';
|
|
16
|
+
for(var i=0; i<6; i++) {
|
|
17
|
+
var x = Math.abs(parseInt(KeyGen.next() % s.length));
|
|
18
|
+
buf += s.charAt(x);
|
|
19
|
+
}
|
|
20
|
+
return buf;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
ParamSecurity.prototype.reload = function () {
|
|
24
|
+
var home = conf['app.root'];
|
|
25
|
+
if (home == null ) {
|
|
26
|
+
var self = this;
|
|
27
|
+
setTimeout(function () {
|
|
28
|
+
self.reload();
|
|
29
|
+
}, 5000);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var file = path.join(home, 'security.conf');
|
|
34
|
+
var self = this;
|
|
35
|
+
try {
|
|
36
|
+
var stat = fs.statSync(file);
|
|
37
|
+
if(stat.size != 6) {
|
|
38
|
+
self.key = Buffer.from("WHATAP");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
var readable = fs.createReadStream(file, {flags : 'r'});
|
|
42
|
+
readable.on('readable', function () {
|
|
43
|
+
if(self.key !== null
|
|
44
|
+
&& self.key !== undefined
|
|
45
|
+
&& self.key.length === 0 ) { return; }
|
|
46
|
+
var chunk;
|
|
47
|
+
while (null !== (chunk = readable.read())) {
|
|
48
|
+
self.key = chunk;
|
|
49
|
+
}
|
|
50
|
+
self.key = Buffer.from(self.key);
|
|
51
|
+
});
|
|
52
|
+
} catch (e) {
|
|
53
|
+
// self.key = self.getKey();
|
|
54
|
+
self.key = 'WHATAP';
|
|
55
|
+
var printWriter = fs.createWriteStream(file, {flags : 'w'});
|
|
56
|
+
printWriter.write(self.key);
|
|
57
|
+
self.key = Buffer.from(self.key);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
ParamSecurity.prototype.encrypt = function (b, crc) {
|
|
61
|
+
var self = this;
|
|
62
|
+
if(self.key == null || self.key.length === 0) {
|
|
63
|
+
self.reload();
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
for(var i=0, j=0; i<b.length; i++, j = (j + 1) % self.key.length) {
|
|
67
|
+
crc.value ^= b[i];
|
|
68
|
+
b[i] ^= self.key[j];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return b;
|
|
72
|
+
};
|
|
73
|
+
ParamSecurity.prototype.decrypt = function (b, crc, dkey) {
|
|
74
|
+
for(var i=0, j=0; i<b.length; i++, j = (j+1) % dkey.length) {
|
|
75
|
+
b[i] ^= dkey[j];
|
|
76
|
+
crc.value ^= b[i];
|
|
77
|
+
}
|
|
78
|
+
return b;
|
|
79
|
+
};
|
|
80
|
+
module.exports = new ParamSecurity();
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
// config 파일 확인
|
|
8
|
+
// 지원 되는 버전 확인
|
|
9
|
+
//(node version 확인)
|
|
10
|
+
//(지원 되는 라이브러리 버전 확인 )
|
|
11
|
+
|
|
12
|
+
// 라이센스 파일 확인
|
|
13
|
+
// 라이센스 확인
|
|
@@ -0,0 +1,166 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
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;
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,157 @@
|
|
|
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();
|
|
@@ -0,0 +1,30 @@
|
|
|
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;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
+
* Use of this source code is governed by a license that
|
|
4
|
+
* can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
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;
|