whatap 0.4.97 → 0.4.98

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.
@@ -256,6 +256,9 @@ var ConfigDefault = {
256
256
  "cloud_platform":str('cloud_platform', 'kic'),
257
257
  "cloud_platform_chk":str('cloud_platform_chk', 'kr-central-1'),
258
258
  "cloud_platform_httpc":str('cloud_platform_httpc', 'http://169.254.169.254/latest/meta-data/placement/availability-zone'),
259
+
260
+ "stat_ipurl_enabled": bool("stat_ipurl_enabled", false),
261
+ "stat_ipurl_max_count": num("stat_ipurl_max_count", 10000),
259
262
  };
260
263
 
261
264
  ConfigDefault._hook_method_ignore_prefix = ConfigDefault.hook_method_ignore_prefixes.split(',');
@@ -52,7 +52,7 @@ var applyEmptyConf=false;
52
52
  Configuration.prototype.reload = function(cb) {
53
53
  var self = this;
54
54
 
55
- this.getPropertyFilePath( function(err, propertyFile) {
55
+ this.getPropertyFilePath( function(err, propertyFile) {
56
56
  if(err) {
57
57
  if(applyEmptyConf==false){
58
58
  applyEmptyConf=true;
@@ -63,14 +63,14 @@ Configuration.prototype.reload = function(cb) {
63
63
  defKeys.forEach(function (key) {
64
64
  if(ConfigDefault[key]) {
65
65
  p[key] = ConfigDefault[key];
66
- }
66
+ }
67
67
  });
68
68
  if(process.env.WHATAP_SERVER_HOST){
69
69
  p['whatap.server.host']=process.env.WHATAP_SERVER_HOST;
70
- }
70
+ }
71
71
  if(process.env.WHATAP_LICENSE){
72
72
  p['license']=process.env.WHATAP_LICENSE;
73
- }
73
+ }
74
74
  self.apply(p);
75
75
  updatePrivate(self);
76
76
  if(cb) cb();
@@ -121,6 +121,10 @@ Configuration.prototype.reload = function(cb) {
121
121
  require('../logger').print("WHATAP-203", "Config file reloaded", false);
122
122
  }
123
123
 
124
+ if(!self._customProps['license'] && process.env.WHATAP_LICENSE)
125
+ self._customProps['license'] = process.env.WHATAP_LICENSE;
126
+ if(!self._customProps['whatap.server.host'] && process.env.WHATAP_SERVER_HOST)
127
+ self._customProps['whatap.server.host'] = process.env.WHATAP_SERVER_HOST;
124
128
  self.apply( self._customProps );
125
129
  updatePrivate(self);
126
130
  if(cb) cb();
@@ -150,10 +154,10 @@ Configuration.prototype.apply = function(properties) {
150
154
  var ips = Array.from(set);
151
155
  this.whatap_server_host = ips;
152
156
 
153
- if( this.getProperty('whatap_micro_enabled') === true || process.env.WHATAP_MICRO_ENABLED === "true"){
157
+ if( this.getProperty('whatap_micro_enabled', false) === true || process.env.WHATAP_MICRO_ENABLED === "true"){
154
158
  this.kubeNodeName(properties);
155
159
  }
156
-
160
+
157
161
  ConfSysMon.apply(properties);
158
162
  };
159
163
 
@@ -170,12 +174,12 @@ Configuration.prototype.kubeNodeName = function(properties){
170
174
 
171
175
  this.ONODE_NAME = this.getProperty("whatap.onode");
172
176
  if (!this.ONODE_NAME || (this.ONODE_NAME && this.ONODE_NAME.length < 1)) {
173
- this.ONODE_NAME = process.env['NODE_NAME'];
177
+ this.ONODE_NAME = process.env['NODE_NAME'] || process.env['WHATAP_ONODE'];
174
178
  }
175
179
  if (!this.ONODE_NAME || (this.ONODE_NAME && this.ONODE_NAME.length < 1)) {
176
180
  this.ONODE_NAME = process.env["NODE_IP"];
177
181
  }
178
- this.ONODE = StringUtil.isEmpty(this.ONODE_NAME) ? 0 : HashUtil.hash(this.ONODE_NAME);
182
+ this.ONODE = StringUtil.isEmpty(this.ONODE_NAME) ? 0 : HashUtil.hashFromString(this.ONODE_NAME);
179
183
  secu.ONODE = this.ONODE;
180
184
  secu.ONODE_NAME = this.ONODE_NAME;
181
185
  }
@@ -197,7 +201,7 @@ Configuration.prototype.getPropertyFilePath = function(cb) {
197
201
 
198
202
  var default_conf = WHATAP_CONF+".conf";
199
203
  var configFile = this.getProperty('whatap.config', default_conf);
200
-
204
+
201
205
  var confFullPathFile=path.join(confDir, configFile);
202
206
  fs.access(confFullPathFile, function (err) {
203
207
  if (err) {
@@ -230,10 +234,10 @@ Configuration.prototype.saveProperty = function(keyValues){
230
234
 
231
235
  if(!self._customProps['whatap.server.host'] && process.env.WHATAP_SERVER_HOST){
232
236
  self._customProps['whatap.server.host']=process.env.WHATAP_SERVER_HOST;
233
- }
237
+ }
234
238
  if(!self._customProps['license'] && process.env.WHATAP_LICENSE){
235
239
  self._customProps['license']=process.env.WHATAP_LICENSE;
236
- }
240
+ }
237
241
  var writeContents = '';
238
242
  for(var k in self._customProps){
239
243
  var v = self._customProps[k];
@@ -301,11 +305,11 @@ Configuration.prototype.isIgnoreLog = function (id) {
301
305
  };
302
306
  Configuration.prototype.setSocketChk = function (socket) {
303
307
  if(socket.whatapId == undefined) {
304
- socket.whatapId = (new Date()).getTime().toString(36) + Math.random().toString(36).slice(2);
305
- //require('../logger').print("WHATAP-TEST", 'Socket whatapId : ' + socket.whatapId, false);
306
- }
308
+ socket.whatapId = (new Date()).getTime().toString(36) + Math.random().toString(36).slice(2);
309
+ //require('../logger').print("WHATAP-TEST", 'Socket whatapId : ' + socket.whatapId, false);
310
+ }
307
311
  //else {
308
- // require('../logger').print("WHATAP-TEST", '[REUSE] Socket whatapId : ' + socket.whatapId, false);
312
+ // require('../logger').print("WHATAP-TEST", '[REUSE] Socket whatapId : ' + socket.whatapId, false);
309
313
  //}
310
314
  if(this.socketChk.get(socket.whatapId) == null) {
311
315
  this.socketChk.put(socket.whatapId , socket.whatapId);
@@ -319,7 +323,7 @@ Configuration.prototype.getStringSet = function (key, defaultValue, deli) {
319
323
 
320
324
  var arr = value.split(deli);
321
325
  for(var i=0; i<arr.length; i++) {
322
- var x = arr[i].trim();
326
+ var x = arr[i].trim();
323
327
  if(x)set.add(replaceCarriageReturns(x));
324
328
  }
325
329
  return set;
package/lib/core/agent.js CHANGED
@@ -52,7 +52,8 @@ var Configuration = require('./../conf/configure'),
52
52
  require('../stat/stat-tranx');
53
53
  require('../stat/stat-sql');
54
54
  require('../stat/stat-httpc');
55
- require('../stat/stat-remoteip');
55
+ require('../stat/stat-remote-ip');
56
+ require('../stat/stat-remote-ipurl');
56
57
  require('../stat/stat-useragent');
57
58
  require('../stat/timingsender');
58
59
 
@@ -159,6 +159,10 @@ var sendStatRemoteIpPack = function(p){
159
159
  return sendPack(p);
160
160
  };
161
161
 
162
+ var sendStatRemoteIpUrlPack = function(p){
163
+ return sendPack(p);
164
+ };
165
+
162
166
  var sendStatUserAgentPack = function(p){
163
167
  return sendPack(p);
164
168
  };
@@ -245,6 +249,7 @@ var DataPackSender = {
245
249
  sendStatHttpcPack : sendStatHttpcPack,
246
250
  sendStatErrorPack : sendStatErrorPack,
247
251
  sendStatRemoteIpPack : sendStatRemoteIpPack,
252
+ sendStatRemoteIpUrlPack : sendStatRemoteIpUrlPack,
248
253
  sendStatUserAgentPack : sendStatUserAgentPack,
249
254
 
250
255
  sendRealtimeUserPack : sendRealtimeUserPack,
@@ -6,11 +6,12 @@
6
6
 
7
7
  var DataPackSender = require('./datapack-sender'),
8
8
  StatTranX = require('../stat/stat-tranx'),
9
- StatRemoteIp = require('../stat/stat-remoteip'),
9
+ StatRemoteIp = require('../stat/stat-remote-ip'),
10
10
  StatUserAgent = require('../stat/stat-useragent'),
11
11
  StatTranxDomain = require('../stat/stat-tx-domain'),
12
12
  StatTranxMtCaller = require('../stat/stat-tx-caller'),
13
13
  StatTranxReferer = require('../stat/stat-tx-referer'),
14
+ StatRemoteIpUrl = require('../stat/stat-remote-ipurl'),
14
15
  conf = require('../conf/configure'),
15
16
  HashUtil = require('../util/hashutil'),
16
17
  EventLevel = require('../data/event-level'),
@@ -20,9 +21,13 @@ var DataPackSender = require('./datapack-sender'),
20
21
 
21
22
  var ZipProfile = require('./zipprofile');
22
23
  var profile_zip_enabled = conf.getProperty('profile_zip_enabled', false);
24
+ var stat_ipurl_enabled = conf.getProperty('stat_ipurl_enabled', false);
23
25
  conf.on('profile_zip_enabled', function(newProperty) {
24
26
  profile_zip_enabled = newProperty;
25
27
  });
28
+ conf.on('stat_ipurl_enabled', function(newProperty) {
29
+ stat_ipurl_enabled = newProperty;
30
+ });
26
31
 
27
32
  var DataProfileAgent = {
28
33
  last_reject : 0,
@@ -32,6 +37,17 @@ var DataProfileAgent = {
32
37
  StatUserAgent.incUserAgent(ctx.userAgent);
33
38
 
34
39
  var transaction = profile.service;
40
+ if(stat_ipurl_enabled && ctx.remoteIp){
41
+ var tc = StatRemoteIpUrl.getService(ctx.remoteIp, ctx.service_hash);
42
+ if (tc) {
43
+ tc.count++;
44
+ if (tc.errorLevel >= EventLevel.WARNING) {
45
+ tc.error++;
46
+ }
47
+ tc.time += transaction.elapsed;
48
+ }
49
+ }
50
+
35
51
  if(conf.stat_domain_enabled && ctx.http_host_hash!=0) {
36
52
  StatTranxDomain.add(ctx.http_host_hash, ctx.service_hash, transaction.elapsed, ctx.error != 0);
37
53
  }
@@ -90,9 +90,11 @@ var SecurityMaster = {
90
90
  this.OKIND_NAME=null;
91
91
  }
92
92
 
93
- if(Configuration.getProperty('whatap_micro_enabled', false) === false || process.env.WHATAP_MICRO_ENABLED === "true") {
94
- var onodeStr= process.env.WHATAP_ONODE || Configuration.getProperty('whatap.onode');
95
- console.log(onodeStr)
93
+ const whatapMicroEnabledConfig = Configuration.getProperty('whatap_micro_enabled', false);
94
+ const whatapMicroEnabledEnv = process.env.WHATAP_MICRO_ENABLED;
95
+
96
+ if (!whatapMicroEnabledConfig || whatapMicroEnabledEnv === undefined || whatapMicroEnabledEnv === "false") {
97
+ var onodeStr= process.env.WHATAP_ONODE || process.env.NODE_NAME || Configuration.getProperty('whatap.onode', null);
96
98
  if(onodeStr && onodeStr.length>0){
97
99
  this.ONODE = HashUtil.hashFromString(onodeStr);
98
100
  this.ONODE_NAME=onodeStr;
@@ -140,8 +142,11 @@ var SecurityMaster = {
140
142
  this.OKIND_NAME=null;
141
143
  }
142
144
 
143
- if(Configuration.getProperty('whatap_micro_enabled', false) === false || process.env.WHATAP_MICRO_ENABLED === "true") {
144
- var onodeStr= process.env.WHATAP_ONODE || Configuration.getProperty('whatap.onode');
145
+ const whatapMicroEnabledConfig = Configuration.getProperty('whatap_micro_enabled', false);
146
+ const whatapMicroEnabledEnv = process.env.WHATAP_MICRO_ENABLED;
147
+
148
+ if (!whatapMicroEnabledConfig || whatapMicroEnabledEnv === undefined || whatapMicroEnabledEnv === "false") {
149
+ var onodeStr= process.env.WHATAP_ONODE || process.env.NODE_NAME || Configuration.getProperty('whatap.onode', null);
145
150
  if(onodeStr && onodeStr.length>0){
146
151
  this.ONODE = HashUtil.hashFromString(onodeStr);
147
152
  this.ONODE_NAME=onodeStr;
@@ -24,7 +24,7 @@ const MeterUsers = require("whatap/lib/counter/meter/meter-users");
24
24
  const DataPackSender = require("whatap/lib/data/datapack-sender");
25
25
  const MeterService = require('../counter/meter/meter-service').MeterService;
26
26
 
27
- var trace_background_socket_enabled = conf.getProperty('trace_background_socket_enabled', false);
27
+ var trace_background_socket_enabled = conf.getProperty('trace_background_socket_enabled', true);
28
28
  conf.on('trace_background_socket_enabled', function (newProps) {
29
29
  trace_background_socket_enabled = newProps;
30
30
  })
@@ -9,23 +9,23 @@ var StatRemoteIpPack = require('../pack/statremote-pack'),
9
9
 
10
10
  var TABLE_MAX_SIZE = 70000;
11
11
 
12
- function StatRemoteIP() {
13
- if(typeof StatRemoteIP.instance === 'object') {
14
- return StatRemoteIP.instance;
12
+ function StatRemoteIp() {
13
+ if(typeof StatRemoteIp.instance === 'object') {
14
+ return StatRemoteIp.instance;
15
15
  }
16
16
 
17
17
  this.table = new StatRemoteIpPack();
18
18
  this.table.iptable.setMax(TABLE_MAX_SIZE);
19
19
 
20
- StatRemoteIP.instance = this;
20
+ StatRemoteIp.instance = this;
21
21
  }
22
22
 
23
- StatRemoteIP.prototype.incRemoteIp = function (ip) {
23
+ StatRemoteIp.prototype.incRemoteIp = function (ip) {
24
24
  if(ip) {
25
25
  this.table.iptable.addNoOver(ip,1);
26
26
  }
27
27
  };
28
- StatRemoteIP.prototype.send = function (now) {
28
+ StatRemoteIp.prototype.send = function (now) {
29
29
  if(this.table.iptable.size() === 0) {
30
30
  return;
31
31
  }
@@ -37,10 +37,10 @@ StatRemoteIP.prototype.send = function (now) {
37
37
  this.table = new StatRemoteIpPack();
38
38
  this.table.iptable.setMax(TABLE_MAX_SIZE);
39
39
  };
40
- StatRemoteIP.prototype.clear = function () {
40
+ StatRemoteIp.prototype.clear = function () {
41
41
  this.table.iptable.clear();
42
42
  };
43
43
 
44
- module.exports = new StatRemoteIP();
44
+ module.exports = new StatRemoteIp();
45
45
 
46
46
 
@@ -0,0 +1,88 @@
1
+ const StatGeneralPack = require('../pack/stat-general-pack');
2
+ const LongKeyLinkedMap = require('../util/longkey-linkedmap');
3
+ const TimeCount = require('../pack/time-count');
4
+ const conf = require('../conf/configure');
5
+ const BitUtil = require('../util/bitutil');
6
+ const ZipProfile = require('../data/zipprofile');
7
+ const DataPackSender = require('../data/datapack-sender');
8
+ const AnyList = require('../util/anylist');
9
+
10
+ var TABLE_MAX_SIZE = 10000;
11
+
12
+ function StatRemoteIpurl() {
13
+ if (typeof StatRemoteIpurl.instance === 'object') {
14
+ return StatRemoteIpurl.instance;
15
+ }
16
+
17
+ this.TABLE_MAX_SIZE = TABLE_MAX_SIZE;
18
+ this.table = new LongKeyLinkedMap(TABLE_MAX_SIZE + 1, 1).setMax(TABLE_MAX_SIZE);
19
+ this.table.create = function (key) {
20
+ return new TimeCount();
21
+ };
22
+
23
+ StatRemoteIpurl.instance = this;
24
+ }
25
+
26
+ StatRemoteIpurl.prototype.getService = function (ip, url_hash) {
27
+ var key = BitUtil.composite(ip, url_hash);
28
+ if (this.table.size() < conf.getProperty('stat_ipurl_max_count', 10000)) {
29
+ return this.table.intern(key);
30
+ } else {
31
+ return this.table.get(key);
32
+ }
33
+ };
34
+
35
+ StatRemoteIpurl.prototype.send = function (now) {
36
+ if (this.table.size() === 0) return;
37
+
38
+ var currTable = this.table;
39
+ var sz = Math.max(this.TABLE_MAX_SIZE, conf.getProperty('stat_ipurl_max_count', 10000));
40
+ this.table = new LongKeyLinkedMap(sz + 1, 1).setMax(conf.getProperty('stat_ipurl_max_count', 10000));
41
+ this.table.create = function (key) {
42
+ return new TimeCount();
43
+ };
44
+
45
+ var rsize = this.table.size();
46
+ var ip = new AnyList(AnyList.INT, rsize);
47
+ var url = new AnyList(AnyList.INT, rsize);
48
+ var count = new AnyList(AnyList.INT, rsize);
49
+ var error = new AnyList(AnyList.INT, rsize);
50
+ var time = new AnyList(AnyList.LONG, rsize);
51
+
52
+ var entries = currTable.entries();
53
+ var i = 0;
54
+ while(entries.hasMoreElements()){
55
+ var ent = entries.nextElement();
56
+ var k = ent.getKey();
57
+ var v = ent.getValue();
58
+
59
+ ip.put(i, BitUtil.getHigh(k));
60
+ url.put(i, BitUtil.getLow(k));
61
+ count.put(i, v.count);
62
+ error.put(i, v.error);
63
+ time.put(i, v.time);
64
+ i++;
65
+ }
66
+
67
+ const out = new StatGeneralPack();
68
+ out.put("ip", ip);
69
+ out.put("url", url);
70
+ out.put("count", count);
71
+ out.put("error", error);
72
+ out.put("time", time);
73
+
74
+ out.id = "ip-url";
75
+ out.time = now;
76
+
77
+ DataPackSender.sendStatRemoteIpUrlPack(out);
78
+ };
79
+
80
+ StatRemoteIpurl.prototype.clear = function () {
81
+ this.table.clear();
82
+ };
83
+
84
+ StatRemoteIpurl.prototype.size = function () {
85
+ return this.table.size();
86
+ };
87
+
88
+ module.exports = new StatRemoteIpurl();
@@ -9,7 +9,8 @@ var StatError = require('./stat-error'),
9
9
  StatTranx = require('./stat-tranx'),
10
10
  StatSql = require('./stat-sql'),
11
11
  StatHttpc = require('./stat-httpc'),
12
- StatRemoteIp = require('./stat-remoteip'),
12
+ StatRemoteIp = require('./stat-remote-ip'),
13
+ StatRemoteIpUrl = require('./stat-remote-ipurl'),
13
14
  StatUserAgent = require('./stat-useragent'),
14
15
  StatTranxMtCaller = require('./stat-tx-caller'),
15
16
  StatTranxDomain = require('./stat-tx-domain'),
@@ -43,6 +44,7 @@ TimingSender.prototype.run = function(){
43
44
  StatSql.send(now);
44
45
  StatHttpc.send(now);
45
46
  StatRemoteIp.send(now);
47
+ StatRemoteIpUrl.send(now);
46
48
  StatUserAgent.send(now);
47
49
  StatError.send(now);
48
50
  StatTranxDomain.send(now);
@@ -53,6 +55,7 @@ TimingSender.prototype.run = function(){
53
55
  StatSql.clear();
54
56
  StatHttpc.clear();
55
57
  StatRemoteIp.clear();
58
+ StatRemoteIpUrl.clear();
56
59
  StatUserAgent.clear();
57
60
  StatError.clear();
58
61
  StatTranxDomain.clear();
@@ -7,7 +7,7 @@ var KubeUtil = {
7
7
  container_key: 0,
8
8
  container_id: undefined,
9
9
  loadFromMountinfo: function() {
10
- if (this.container_id !== null && this.container_id !== undefined) return;
10
+ if (this.container_id) return;
11
11
 
12
12
  try{
13
13
  var content = fs.readFileSync("/proc/self/mountinfo");
@@ -35,7 +35,7 @@ var KubeUtil = {
35
35
  }
36
36
  },
37
37
  loadContainerId: function(){
38
- if (this.container_id !== null && this.container_id !== undefined) return;
38
+ if (this.container_id) return;
39
39
 
40
40
  try{
41
41
  var content = fs.readFileSync("/proc/self/cgroup");
@@ -67,7 +67,7 @@ var KubeUtil = {
67
67
  }catch(e){
68
68
  Logger.printError('WHATAP-800', 'KubeUtil(loadContainerId) ', e)
69
69
  }
70
- if(this.container_key == 0) this.loadFromMountinfo();
70
+ if(!this.container_key) this.loadFromMountinfo();
71
71
  }
72
72
  }
73
73
  module.exports = KubeUtil;
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.97",
5
- "releaseDate": "20240603",
4
+ "version": "0.4.98",
5
+ "releaseDate": "20240709",
6
6
  "description": "Monitoring and Profiling Service",
7
7
  "main": "index.js",
8
8
  "scripts": {},