whatap 0.4.94 → 0.4.95

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.
@@ -64,6 +64,14 @@ var ConfigDefault = {
64
64
  "profile_http_parameter_url_prefix": "/",
65
65
  "profile_http_header_url_prefix": "/",
66
66
  "profile_connection_open_enabled": true,
67
+ "profile_zip_enabled": bool('profile_zip_enabled', false),
68
+ "profile_zip_queue_size": num('profile_zip_queue_size', 1000),
69
+ "profile_zip_max_buffer_size": num('profile_zip_max_buffer_size', 1024*1024),
70
+ "profile_zip_min_size": num('profile_zip_min_size', 100),
71
+ "debug_profile_zip_enabled": bool('debug_profile_zip_enabled', false),
72
+ "debug_profile_zip_interval": num('debug_profile_zip_interval', 5000),
73
+ "profile_zip_max_wait_time": num('profile_zip_max_wait_time', 1000),
74
+ "profile_zip_max_wait2_time": num('profile_zip_max_wait2_time', 5000),
67
75
 
68
76
  "hook_method_patterns": str('hook_method_patterns',""),
69
77
  "hook_method_access_public_enabled": true,
@@ -4,134 +4,143 @@
4
4
  * can be found in the LICENSE file.
5
5
  */
6
6
 
7
- var DataPackSender = require('./datapack-sender'),
8
- StatTranX = require('../stat/stat-tranx'),
9
- StatRemoteIp = require('../stat/stat-remoteip'),
10
- StatUserAgent = require('../stat/stat-useragent'),
11
- StatTranxDomain = require('../stat/stat-tx-domain'),
12
- StatTranxMtCaller = require('../stat/stat-tx-caller'),
13
- StatTranxReferer = require('../stat/stat-tx-referer'),
14
- conf = require('../conf/configure'),
15
- HashUtil = require('../util/hashutil'),
16
- EventLevel = require('../data/event-level'),
17
- DataTextAgent = require('../data/datatext-agent'),
18
- Long = require('long'),
19
- Logger = require('../logger');
7
+ var DataPackSender = require('./datapack-sender'),
8
+ StatTranX = require('../stat/stat-tranx'),
9
+ StatRemoteIp = require('../stat/stat-remoteip'),
10
+ StatUserAgent = require('../stat/stat-useragent'),
11
+ StatTranxDomain = require('../stat/stat-tx-domain'),
12
+ StatTranxMtCaller = require('../stat/stat-tx-caller'),
13
+ StatTranxReferer = require('../stat/stat-tx-referer'),
14
+ conf = require('../conf/configure'),
15
+ HashUtil = require('../util/hashutil'),
16
+ EventLevel = require('../data/event-level'),
17
+ DataTextAgent = require('../data/datatext-agent'),
18
+ Long = require('long'),
19
+ Logger = require('../logger');
20
20
 
21
+ var ZipProfile = require('./zipprofile');
22
+ var profile_zip_enabled = conf.getProperty('profile_zip_enabled', false);
23
+ conf.on('profile_zip_enabled', function(newProperty) {
24
+ profile_zip_enabled = newProperty;
25
+ });
21
26
 
22
27
  var DataProfileAgent = {
23
- last_reject : 0,
24
- sendProfile : function (ctx, profile, rejected) {
25
- try {
26
- StatRemoteIp.incRemoteIp(ctx.remoteIp);
27
- StatUserAgent.incUserAgent(ctx.userAgent);
28
-
29
- var transaction = profile.service;
30
- if(conf.stat_domain_enabled && ctx.http_host_hash!=0) {
31
- StatTranxDomain.add(ctx.http_host_hash, ctx.service_hash, transaction.elapsed, ctx.error != 0);
32
- }
33
-
34
- if(conf.trace_referer_enabled && ctx.referer!=0) {
35
- StatTranxReferer.add(ctx.referer, ctx.service_hash, transaction.elapsed, ctx.error != 0);
36
- }
37
-
38
- if(conf.stat_mtrace_enabled && ctx.mcaller_pcode!=0) {
39
- var key = StatTranxMtCaller.getService(ctx.mcaller_pcode, ctx.mcaller_okind, ctx.mcaller_spec, ctx.mcaller_url,ctx.service_hash);
40
- transaction.mthis_spec = conf.mtrace_spec_hash
41
-
42
- if (ctx.mcaller_spec && ctx.mcaller_spec!='') {
43
- transaction.mcaller_spec = key.mcaller_spec = HashUtil.hashFromString(ctx.mcaller_spec);
44
- DataTextAgent.MTRACE_SPEC.add(transaction.mcaller_spec, ctx.mcaller_spec);
45
- }
46
- if (ctx.mcaller_url && ctx.mcaller_url!='') {
47
- transaction.mcaller_url = key.mcaller_url = HashUtil.hashFromString(ctx.mcaller_url);
48
- DataTextAgent.MTRACE_CALLER_URL.add(transaction.mcaller_url, ctx.mcaller_url);
49
- }
50
-
51
- // additional multi transaction
52
- //key.url = ctx.service_hash;
53
- var tc = StatTranxMtCaller.getService(key);
54
- if (tc != null) {
55
- tc.count++;
56
- if (transaction.errorLevel >= EventLevel.WARNING) {
57
- tc.error++;
58
- }
59
- tc.time += transaction.elapsed;
60
- }
61
-
62
- // StatTranxMtCaller.add(ctx.mcaller_pcode,
63
- // ctx.mcaller_okind,
64
- // transaction.mcaller_spec,
65
- // transaction.mcaller_url,
66
- // ctx.service_hash,
67
- // transaction.elapsed,
68
- // ctx.error != 0);
69
- }
70
-
71
- var stat = StatTranX.getService(transaction.service);
72
-
73
- if(stat !== null) {
74
- stat.count++;
75
- if(transaction.error.isZero() ==false) {
76
- stat.error++;
77
- }
78
- if(transaction.elapsed < 0) {
79
- transaction.elapsed = 0;
80
- }
81
-
82
- stat.actived += ctx.profileActive;
83
- stat.time_sum += transaction.elapsed;
84
- if (transaction.elapsed > stat.time_max) {
85
- stat.time_max = transaction.elapsed;
86
- }
87
-
88
- switch (transaction.apdex) {
89
- case 2:
90
- stat.apdex_satisfied++;
91
- break;
92
- case 1:
93
- stat.apdex_tolerated++;
94
- break;
28
+ last_reject : 0,
29
+ sendProfile : function (ctx, profile, rejected) {
30
+ try {
31
+ StatRemoteIp.incRemoteIp(ctx.remoteIp);
32
+ StatUserAgent.incUserAgent(ctx.userAgent);
33
+
34
+ var transaction = profile.service;
35
+ if(conf.stat_domain_enabled && ctx.http_host_hash!=0) {
36
+ StatTranxDomain.add(ctx.http_host_hash, ctx.service_hash, transaction.elapsed, ctx.error != 0);
37
+ }
38
+
39
+ if(conf.trace_referer_enabled && ctx.referer!=0) {
40
+ StatTranxReferer.add(ctx.referer, ctx.service_hash, transaction.elapsed, ctx.error != 0);
95
41
  }
96
- if (stat.time_min==0 || transaction.elapsed < stat.time_min) {
97
- stat.time_min = transaction.elapsed;
42
+
43
+ if(conf.stat_mtrace_enabled && ctx.mcaller_pcode!=0) {
44
+ var key = StatTranxMtCaller.getService(ctx.mcaller_pcode, ctx.mcaller_okind, ctx.mcaller_spec, ctx.mcaller_url,ctx.service_hash);
45
+ transaction.mthis_spec = conf.mtrace_spec_hash
46
+
47
+ if (ctx.mcaller_spec && ctx.mcaller_spec!='') {
48
+ transaction.mcaller_spec = key.mcaller_spec = HashUtil.hashFromString(ctx.mcaller_spec);
49
+ DataTextAgent.MTRACE_SPEC.add(transaction.mcaller_spec, ctx.mcaller_spec);
50
+ }
51
+ if (ctx.mcaller_url && ctx.mcaller_url!='') {
52
+ transaction.mcaller_url = key.mcaller_url = HashUtil.hashFromString(ctx.mcaller_url);
53
+ DataTextAgent.MTRACE_CALLER_URL.add(transaction.mcaller_url, ctx.mcaller_url);
54
+ }
55
+
56
+ // additional multi transaction
57
+ //key.url = ctx.service_hash;
58
+ var tc = StatTranxMtCaller.getService(key);
59
+ if (tc != null) {
60
+ tc.count++;
61
+ if (transaction.errorLevel >= EventLevel.WARNING) {
62
+ tc.error++;
63
+ }
64
+ tc.time += transaction.elapsed;
65
+ }
66
+
67
+ // StatTranxMtCaller.add(ctx.mcaller_pcode,
68
+ // ctx.mcaller_okind,
69
+ // transaction.mcaller_spec,
70
+ // transaction.mcaller_url,
71
+ // ctx.service_hash,
72
+ // transaction.elapsed,
73
+ // ctx.error != 0);
98
74
  }
99
- stat.time_std += (Long.fromInt(transaction.elapsed) * Long.fromInt(transaction.elapsed));
100
-
101
- stat.sql_count += transaction.sqlCount;
102
- stat.sql_time +=transaction.sqlTime;
103
- stat.sql_fetch += ctx.rs_count;
104
- stat.sql_fetch_time +=ctx.rs_time;
105
-
106
- stat.httpc_count += transaction.httpcCount;
107
- stat.httpc_time +=transaction.httpcTime;
108
-
109
- stat.malloc_sum +=transaction.malloc;
110
- stat.cpu_sum +=transaction.cpuTime;
111
-
112
- if (rejected) {
113
- var now = Date.now();
114
- if (now < this.last_reject + 1000) {
115
- return;
116
- }
117
- this.last_reject = now;
118
- } else if (stat.profiled == true // 이전(5분구간 내)에 프로파일이 수집된점이 있음
119
- && ctx.profileActive == 0 // 액티브 스택을 추적한적이 없음
120
- && transaction.elapsed < conf.profile_basetime
121
- && transaction.error.isZero()) {
122
- return;
123
- }
124
- stat.profiled = true;
125
- }
126
-
127
- var steps = ctx.profile.getSteps();
128
- profile.setProfile(steps);
129
- DataPackSender.sendProfilePack(profile);
130
-
131
- } catch(e) {
132
- Logger.printError('WHATAP-199', 'dataprofile-agent error', e);
133
- }
134
- }
75
+
76
+ var stat = StatTranX.getService(transaction.service);
77
+
78
+ if(stat !== null) {
79
+ stat.count++;
80
+ if(transaction.error.isZero() ==false) {
81
+ stat.error++;
82
+ }
83
+ if(transaction.elapsed < 0) {
84
+ transaction.elapsed = 0;
85
+ }
86
+
87
+ stat.actived += ctx.profileActive;
88
+ stat.time_sum += transaction.elapsed;
89
+ if (transaction.elapsed > stat.time_max) {
90
+ stat.time_max = transaction.elapsed;
91
+ }
92
+
93
+ switch (transaction.apdex) {
94
+ case 2:
95
+ stat.apdex_satisfied++;
96
+ break;
97
+ case 1:
98
+ stat.apdex_tolerated++;
99
+ break;
100
+ }
101
+ if (stat.time_min==0 || transaction.elapsed < stat.time_min) {
102
+ stat.time_min = transaction.elapsed;
103
+ }
104
+ stat.time_std += (Long.fromInt(transaction.elapsed) * Long.fromInt(transaction.elapsed));
105
+
106
+ stat.sql_count += transaction.sqlCount;
107
+ stat.sql_time +=transaction.sqlTime;
108
+ stat.sql_fetch += ctx.rs_count;
109
+ stat.sql_fetch_time +=ctx.rs_time;
110
+
111
+ stat.httpc_count += transaction.httpcCount;
112
+ stat.httpc_time +=transaction.httpcTime;
113
+
114
+ stat.malloc_sum +=transaction.malloc;
115
+ stat.cpu_sum +=transaction.cpuTime;
116
+
117
+ if (rejected) {
118
+ var now = Date.now();
119
+ if (now < this.last_reject + 1000) {
120
+ return;
121
+ }
122
+ this.last_reject = now;
123
+ } else if (stat.profiled == true // 이전(5분구간 내)에 프로파일이 수집된점이 있음
124
+ && ctx.profileActive == 0 // 액티브 스택을 추적한적이 없음
125
+ && transaction.elapsed < conf.profile_basetime
126
+ && transaction.error.isZero()) {
127
+ return;
128
+ }
129
+ stat.profiled = true;
130
+ }
131
+
132
+ var steps = ctx.profile.getSteps();
133
+ profile.setProfile(steps);
134
+ if(profile_zip_enabled){
135
+ ZipProfile.getInstance().add(profile);
136
+ } else {
137
+ DataPackSender.sendProfilePack(profile);
138
+ }
139
+
140
+ } catch(e) {
141
+ Logger.printError('WHATAP-199', 'dataprofile-agent error', e);
142
+ }
143
+ }
135
144
  };
136
145
 
137
146
  module.exports = DataProfileAgent;
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Copyright 2016 the WHATAP project authors. All rights reserved.
3
+ * Use of this source code is governed by a license that
4
+ * can be found in the LICENSE file.
5
+ */
6
+
7
+ var conf = require('../conf/configure'),
8
+ secuMaster = require('../net/security-master'),
9
+ TcpRequestMgr = require('../net/tcprequest-mgr'),
10
+ DateUtil = require('./../util/dateutil'),
11
+ RequestQueue = require('../util/request-queue'),
12
+ DataPackSender = require('../data/datapack-sender'),
13
+ DataOutputX = require('../io/data-outputx'),
14
+ ZipPack = require('../pack/zip-pack'),
15
+ DataPackSender = require('../data/datapack-sender'),
16
+ Logger = require('../logger');
17
+
18
+ const zlib = require('zlib');
19
+
20
+ var profile_zip_enabled = conf.getProperty('profile_zip_enabled', false);
21
+ var profile_zip_max_buffer_size = conf.getProperty('profile_zip_max_buffer_size', 1024*1024);
22
+ var profile_zip_min_size = conf.getProperty('profile_zip_min_size', 100)
23
+ var profile_zip_queue_size = conf.getProperty('profile_zip_queue_size', 500);
24
+ var profile_zip_max_wait_time = conf.getProperty('profile_zip_max_wait_time', 1000);
25
+ var net_send_max_bytes = conf.getProperty('net_send_max_bytes', 5 * 1024 * 1024);
26
+ var debug_profile_zip_enabled = conf.getProperty('debug_profile_zip_enabled', false);
27
+ var debug_profile_zip_interval = conf.getProperty('debug_profile_zip_interval', 5000);
28
+ conf.on('profile_zip_enabled', function(newProperty) {
29
+ profile_zip_enabled = newProperty;
30
+ if (profile_zip_enabled) {
31
+ ZipProfile.getInstance().startProcessQueue();
32
+ } else {
33
+ ZipProfile.getInstance().stopProcessQueue();
34
+ ZipProfile.resetInstance();
35
+ }
36
+ });
37
+
38
+ class ZipProfile {
39
+ constructor() {
40
+ if (ZipProfile.instance) {
41
+ return ZipProfile.instance;
42
+ }
43
+ this.queue = new RequestQueue(profile_zip_queue_size);
44
+ this.no_zip_sent = 0;
45
+ this.zip_sent = 0;
46
+ this.last_log = null;
47
+ this.buffer = Buffer.alloc(0);
48
+ this.packCount = 0;
49
+ this.first_time = null;
50
+ this.isProcessing = false;
51
+ ZipProfile.instance = this;
52
+
53
+ if (profile_zip_enabled) {
54
+ this.startProcessQueue();
55
+ }
56
+ }
57
+
58
+ static getInstance() {
59
+ if (!ZipProfile.instance) {
60
+ ZipProfile.instance = new ZipProfile();
61
+ }
62
+ return ZipProfile.instance;
63
+ }
64
+
65
+ static resetInstance() {
66
+ if(ZipProfile.instance){
67
+ ZipProfile.instance = null;
68
+ }
69
+ }
70
+
71
+ add(p){
72
+ var ok = this.queue.put(p);
73
+ if(!ok){
74
+ DataPackSender.sendPack(p);
75
+ this.no_zip_sent++;
76
+ }
77
+ }
78
+
79
+ async processQueue() {
80
+ this.isProcessing = true;
81
+ while (this.isProcessing) {
82
+ if(!profile_zip_enabled) { break; }
83
+
84
+ const p = await this.queue.getByTimeout(profile_zip_max_wait_time);
85
+ if(p) {
86
+ await this.append(p);
87
+ }else{
88
+ await this.sendAndClear();
89
+ }
90
+ await new Promise(resolve => setTimeout(resolve, 100));
91
+ }
92
+ }
93
+
94
+ async append(p) {
95
+ var b = DataOutputX.toBytesPack(p);
96
+ if(b.length >= net_send_max_bytes){ return; }
97
+
98
+ this.buffer = Buffer.concat([this.buffer, b]);
99
+ this.packCount++;
100
+
101
+ if(!this.first_time){
102
+ this.first_time = p.time;
103
+ if(this.buffer.length >= profile_zip_max_buffer_size){
104
+ await this.sendAndClear();
105
+ }
106
+ }else{
107
+ if(this.buffer.length >= profile_zip_max_buffer_size || (p.time - this.first_time) >= conf.getProperty('profile_zip_max_wait_time', 5000)){
108
+ await this.sendAndClear();
109
+ }
110
+ }
111
+ }
112
+
113
+ async sendAndClear() {
114
+ if(this.buffer.length === 0){ return; }
115
+
116
+ var p = new ZipPack();
117
+ p.time = DateUtil.currentTime();
118
+ p.recordCount = this.packCount;
119
+ p.records = this.buffer;
120
+
121
+ await this.doZip(p);
122
+ if(debug_profile_zip_enabled){
123
+ if(debug_profile_zip_interval){
124
+ Logger.print('WHATAP-ZIP-DEBUG', `PROFILE status=${p.status} records=${p.recordCount} | ${this.buffer.length} => ${p.records.length} queue=${this.queue.size()}`, false)
125
+ } else {
126
+ this.zip_sent++;
127
+ var now = Date.now();
128
+ if(now > (this.last_log + debug_profile_zip_interval)){
129
+ this.last_log = now;
130
+ this.log(p);
131
+ this.zip_sent = 0;
132
+ }
133
+ }
134
+ }
135
+
136
+ p.pcode = secuMaster.PCODE;
137
+ p.oid = secuMaster.OID;
138
+ p.okind = conf.OKIND;
139
+ p.onode = conf.ONODE;
140
+
141
+ TcpRequestMgr.addProfile(0, p);
142
+
143
+ this.buffer = Buffer.alloc(0);
144
+ this.first_time = 0;
145
+ this.packCount = 0;
146
+ }
147
+
148
+ log(p){
149
+ try{
150
+ var sb = `PROFILE `;
151
+ sb += `zip_sent=${this.zip_sent}`;
152
+ sb += ` records=${p.records}`;
153
+ sb += ` | =${this.buffer.length} => ${p.records.length}`;
154
+ sb += ` queue=${this.queue.size()}`;
155
+ if (this.no_zip_sent > 0) {
156
+ sb += ` no_zip_sent=${this.no_zip_sent}`;
157
+ }
158
+ Logger.print('WHATAP-ZIP-DEBUG', sb, false);
159
+ }catch (e) {
160
+ }
161
+ }
162
+
163
+ async doZip(p){
164
+ if(p.status !== 0){ return; }
165
+ if(p.records.length < profile_zip_min_size){ return; }
166
+ p.status = 1;
167
+
168
+ try{
169
+ p.records = await this._doZip(p.records);
170
+ }catch (e) {
171
+ Logger.print('WHATAP-ZIP-ERROR', 'Error occurred during compression.', false);
172
+ }
173
+ }
174
+
175
+ _doZip(data) {
176
+ return new Promise((resolve, reject) => {
177
+ zlib.gzip(data, (err, buffer) => {
178
+ if (err) {
179
+ reject(err);
180
+ } else {
181
+ resolve(buffer);
182
+ }
183
+ });
184
+ });
185
+ }
186
+
187
+ startProcessQueue() {
188
+ if (!this.processing) {
189
+ this.processQueue()
190
+ }
191
+ }
192
+ stopProcessQueue() {
193
+ this.processing = false;
194
+ }
195
+ }
196
+
197
+ module.exports = ZipProfile;
@@ -4,58 +4,60 @@
4
4
  * can be found in the LICENSE file.
5
5
  */
6
6
 
7
- exports.PARAMETER = 0x0100;
8
- exports.COUNTER_1 = 0x0201;
9
- exports.PROFILE = 0x0300;
10
- exports.ACTIVESTACK_1 = 0x0401;
11
- exports.TEXT = 0x0700;
12
- exports.ERROR_SNAP = 0x0800;
13
- exports.ERROR_SNAP_1 = 0x0801;
14
- exports.REALTIME_USER_1 = 0x0f01;
15
-
16
- exports.STAT_SERVICE= 0x0900;
17
- exports.STAT_SERVICE_1 = 0x0901;
18
- exports.STAT_GENERAL= 0x0910;
19
- exports.STAT_SQL = 0x0a00;
20
- exports.STAT_HTTPC = 0x0b00;
21
- exports.STAT_ERROR = 0x0c00;
22
- exports.STAT_METHOD = 0x0e00;
23
- exports.STAT_TOP_SERVICE= 0x1000;
24
- exports.STAT_REMOTE_IP = 0x1100;
25
- exports.STAT_USER_AGENT = 0x1200;
26
-
27
- exports.EVENT = 0x1400;
28
- exports.HITMAP = 0x1500;
29
- exports.HITMAP_1 = 0x1501;
30
- exports.COUNTER5M = 0x1600;
31
- exports.HITMAP5M = 0x1700;
32
-
33
- exports.TAG_COUNT = 0x1601;
34
-
35
- exports.PACK_NAME = {
36
- 0x0100 : 'PARAMETER',
37
- 0x0201 : 'COUNTER_1',
38
- 0x0300 : 'PROFILE',
39
- 0x0401 : 'ACTIVESTACK_1',
40
- 0x0700 : 'TEXT',
41
- 0x0800 : 'ERROR_SNAP',
42
- 0x0801 : 'ERROR_SNAP_1',
43
- 0x0f01 : 'REALTIME_USER_1',
44
- 0x0900 : 'STAT_SERVICE',
45
- 0x0901 : 'STAT_SERVICE_1',
46
- 0x0910 : 'STAT_GENERAL',
47
- 0x0a00 : 'STAT_SQL',
48
- 0x0b00 : 'STAT_HTTPC',
49
- 0x0c00 : 'STAT_ERROR',
50
- 0x0e00 : 'STAT_METHOD',
51
- 0x1000 : 'STAT_TOP_SERVICE',
52
- 0x1100 : 'STAT_REMOTE_IP',
53
- 0x1200 : 'STAT_USER_AGENT',
54
- 0x1400 : 'EVENT',
55
- 0x1500 : 'HITMAP',
56
- 0x1501 : 'HITMAP_1',
57
- 0x1600 : 'COUNTER5M',
58
- 0x1700 : 'HITMAP5M',
59
- 0x1601 : 'TAG_COUNT'
60
- };
7
+ exports.PARAMETER = 0x0100;
8
+ exports.COUNTER_1 = 0x0201;
9
+ exports.PROFILE = 0x0300;
10
+ exports.ACTIVESTACK_1 = 0x0401;
11
+ exports.TEXT = 0x0700;
12
+ exports.ERROR_SNAP = 0x0800;
13
+ exports.ERROR_SNAP_1 = 0x0801;
14
+ exports.REALTIME_USER_1 = 0x0f01;
15
+
16
+ exports.STAT_SERVICE= 0x0900;
17
+ exports.STAT_SERVICE_1 = 0x0901;
18
+ exports.STAT_GENERAL= 0x0910;
19
+ exports.STAT_SQL = 0x0a00;
20
+ exports.STAT_HTTPC = 0x0b00;
21
+ exports.STAT_ERROR = 0x0c00;
22
+ exports.STAT_METHOD = 0x0e00;
23
+ exports.STAT_TOP_SERVICE= 0x1000;
24
+ exports.STAT_REMOTE_IP = 0x1100;
25
+ exports.STAT_USER_AGENT = 0x1200;
26
+
27
+ exports.EVENT = 0x1400;
28
+ exports.HITMAP = 0x1500;
29
+ exports.HITMAP_1 = 0x1501;
30
+ exports.COUNTER5M = 0x1600;
31
+ exports.HITMAP5M = 0x1700;
32
+
33
+ exports.TAG_COUNT = 0x1601;
34
+ exports.ZIP = 0x170b;
35
+
36
+ exports.PACK_NAME = {
37
+ 0x0100 : 'PARAMETER',
38
+ 0x0201 : 'COUNTER_1',
39
+ 0x0300 : 'PROFILE',
40
+ 0x0401 : 'ACTIVESTACK_1',
41
+ 0x0700 : 'TEXT',
42
+ 0x0800 : 'ERROR_SNAP',
43
+ 0x0801 : 'ERROR_SNAP_1',
44
+ 0x0f01 : 'REALTIME_USER_1',
45
+ 0x0900 : 'STAT_SERVICE',
46
+ 0x0901 : 'STAT_SERVICE_1',
47
+ 0x0910 : 'STAT_GENERAL',
48
+ 0x0a00 : 'STAT_SQL',
49
+ 0x0b00 : 'STAT_HTTPC',
50
+ 0x0c00 : 'STAT_ERROR',
51
+ 0x0e00 : 'STAT_METHOD',
52
+ 0x1000 : 'STAT_TOP_SERVICE',
53
+ 0x1100 : 'STAT_REMOTE_IP',
54
+ 0x1200 : 'STAT_USER_AGENT',
55
+ 0x1400 : 'EVENT',
56
+ 0x1500 : 'HITMAP',
57
+ 0x1501 : 'HITMAP_1',
58
+ 0x1600 : 'COUNTER5M',
59
+ 0x1700 : 'HITMAP5M',
60
+ 0x1601 : 'TAG_COUNT',
61
+ 0x170b : 'ZIP'
62
+ };
61
63
 
@@ -0,0 +1,71 @@
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 PackEnum = require('./packenum'),
8
+ Pack = require('./pack'),
9
+ TxRecord = require('../service/tx-record'),
10
+ Step = require('../step/step'),
11
+ DataOutputX = require('../io/data-outputx'),
12
+ DataInputX = require('../io/data-inputx');
13
+ var zlib = require('zlib');
14
+
15
+ function ZipPack() {
16
+ Pack.call(this);
17
+ this.records = [];
18
+ this.recordCount = null;
19
+ this.status = 0;
20
+ }
21
+ ZipPack.prototype = new Pack();
22
+ ZipPack.prototype.constructor = ZipPack;
23
+ ZipPack.prototype.toString = function() {
24
+ var text = 'ZipPack ' + Pack.prototype.toString.call(this);
25
+ return text;
26
+ };
27
+ ZipPack.prototype.getPackType = function () {
28
+ return PackEnum.ZIP;
29
+ };
30
+ ZipPack.prototype.write = function (dout) {
31
+ Pack.prototype.write.call(this, dout);
32
+ dout.writeByte(this.status);
33
+ dout.writeDecimal(this.recordCount);
34
+ dout.writeBlob(this.records);
35
+ }
36
+ ZipPack.prototype.read = function (din) {
37
+ Pack.prototype.read.call(this, din);
38
+ this.status = din.readByte();
39
+ this.recordCount = din.readDecimal();
40
+ this.records = din.readBlob();
41
+ return this;
42
+ }
43
+ ZipPack.prototype.setRecords = function (items, size) {
44
+ if(size) this.recordCount = size;
45
+ else this.recordCount = items.length;
46
+
47
+ var o = new DataOutputX();
48
+ for(let i = 0; i < items.length; i++){
49
+ o.writePack(items[i]);
50
+ }
51
+ this.records = o.toByteArray();
52
+ return this;
53
+ }
54
+ ZipPack.prototype.getRecords = function () {
55
+ var items = [];
56
+ if(!this.records) {
57
+ return null;
58
+ }
59
+ var dataInputX = new DataInputX(this.records);
60
+ for(let i = 0; i < this.recordCount; i++){
61
+ var p = dataInputX.readPack();
62
+ p.pcode = this.pcode;
63
+ p.oid = this.oid;
64
+ p.okind = this.okind;
65
+ p.onode = this.onode;
66
+ items.push(p);
67
+ }
68
+ return items;
69
+ }
70
+
71
+ module.exports = ZipPack;
@@ -20,7 +20,7 @@ ParamSecurity.prototype.getKey = function () {
20
20
  return buf;
21
21
  };
22
22
 
23
- ParamSecurity.prototype.reload = function () {
23
+ ParamSecurity.prototype.reload = function () {
24
24
  var home = conf['app.root'];
25
25
  if (home == null ) {
26
26
  var self = this;
@@ -30,7 +30,7 @@ ParamSecurity.prototype.reload = function () {
30
30
  return;
31
31
  }
32
32
 
33
- var file = path.join(home, 'paramkey.txt');
33
+ var file = path.join(home, 'security.conf');
34
34
  var self = this;
35
35
  try {
36
36
  var stat = fs.statSync(file);
@@ -40,8 +40,8 @@ ParamSecurity.prototype.reload = function () {
40
40
  }
41
41
  var readable = fs.createReadStream(file, {flags : 'r'});
42
42
  readable.on('readable', function () {
43
- if(self.key !== null
44
- && self.key !== undefined
43
+ if(self.key !== null
44
+ && self.key !== undefined
45
45
  && self.key.length === 0 ) { return; }
46
46
  var chunk;
47
47
  while (null !== (chunk = readable.read())) {
@@ -54,7 +54,7 @@ ParamSecurity.prototype.reload = function () {
54
54
  var printWriter = fs.createWriteStream(file, {flags : 'w'});
55
55
  printWriter.write(self.key);
56
56
  self.key = Buffer.from(self.key);
57
- }
57
+ }
58
58
  };
59
59
  ParamSecurity.prototype.encrypt = function (b, crc) {
60
60
  var self = this;
@@ -17,6 +17,33 @@ RequestQueue.prototype.get = function () {
17
17
  }
18
18
  return null;
19
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
+ };
20
47
  RequestQueue.prototype.put = function (o) {
21
48
  if(this.capacity <= 0 || this.queue.size() < this.capacity) {
22
49
  this.queue.add(o);
@@ -34,10 +61,10 @@ RequestQueue.prototype.clear = function () {
34
61
  };
35
62
 
36
63
  var failed = function (v) {
37
-
64
+
38
65
  };
39
66
  var overflowed = function (v) {
40
-
67
+
41
68
  };
42
69
 
43
70
  module.exports = RequestQueue;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "whatap",
3
3
  "homepage": "http://www.whatap.io",
4
- "version": "0.4.94",
5
- "releaseDate": "20240307",
4
+ "version": "0.4.95",
5
+ "releaseDate": "20240429",
6
6
  "description": "Monitoring and Profiling Service",
7
7
  "main": "index.js",
8
8
  "scripts": {},