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.
Files changed (198) hide show
  1. package/README.md +32 -78
  2. package/lib/conf/conf-sys-mon.js +101 -0
  3. package/lib/conf/config-default.js +10 -3
  4. package/lib/conf/configure.js +369 -349
  5. package/lib/conf/license.js +1 -1
  6. package/lib/control/cmd-config.js +24 -0
  7. package/lib/control/control-handler.js +367 -0
  8. package/lib/control/packagectr-helper.js +34 -3
  9. package/lib/core/agent.js +176 -882
  10. package/lib/core/interceptor.js +6 -6
  11. package/lib/core/request-agent.js +27 -0
  12. package/lib/core/shimmer.js +82 -36
  13. package/lib/counter/counter-manager.js +79 -8
  14. package/lib/counter/meter/meter-activex.js +67 -0
  15. package/lib/counter/meter/meter-httpc.js +57 -0
  16. package/lib/counter/meter/meter-resource.js +9 -0
  17. package/lib/counter/meter/meter-service.js +168 -0
  18. package/lib/counter/meter/meter-socket.io.js +51 -0
  19. package/lib/counter/meter/meter-sql.js +71 -0
  20. package/lib/counter/meter/meter-users.js +58 -0
  21. package/lib/counter/meter.js +183 -0
  22. package/lib/counter/task/activetransaction.js +68 -17
  23. package/lib/counter/task/agentinfo.js +107 -0
  24. package/lib/{system → counter/task}/gc-action.js +27 -74
  25. package/lib/counter/task/gcstat.js +34 -0
  26. package/lib/counter/task/heapmem.js +25 -0
  27. package/lib/counter/task/httpc.js +76 -0
  28. package/lib/counter/task/metering-info.js +125 -0
  29. package/lib/counter/task/proc-cpu.js +29 -0
  30. package/lib/counter/task/realtimeuser.js +31 -0
  31. package/lib/counter/task/res/systemECSTask.js +39 -0
  32. package/lib/counter/task/res/systemKubeTask.js +53 -0
  33. package/lib/counter/task/res/util/awsEcsClientThread.js +218 -0
  34. package/lib/counter/task/res/util/linuxProcStatUtil.js +14 -0
  35. package/lib/counter/task/res-sys-cpu.js +62 -0
  36. package/lib/counter/task/service.js +202 -0
  37. package/lib/counter/task/socketio.js +30 -0
  38. package/lib/counter/task/sql.js +105 -0
  39. package/lib/counter/task/systemperf.js +43 -0
  40. package/lib/data/datapack-sender.js +289 -0
  41. package/lib/data/dataprofile-agent.js +162 -0
  42. package/lib/data/datatext-agent.js +135 -0
  43. package/lib/data/event-level.js +15 -0
  44. package/lib/data/test.js +49 -0
  45. package/lib/data/zipprofile.js +197 -0
  46. package/lib/env/constants.js +21 -0
  47. package/lib/error/error-handler.js +437 -0
  48. package/lib/io/data-inputx.js +13 -3
  49. package/lib/io/data-outputx.js +268 -206
  50. package/lib/kube/kube-client.js +144 -0
  51. package/lib/lang/text-types.js +58 -0
  52. package/lib/logger.js +6 -6
  53. package/lib/logsink/line-log-util.js +87 -0
  54. package/lib/logsink/line-log.js +12 -0
  55. package/lib/logsink/log-sender.js +78 -0
  56. package/lib/logsink/log-tracer.js +40 -0
  57. package/lib/logsink/sender-util.js +56 -0
  58. package/lib/logsink/zip/zip-send.js +177 -0
  59. package/lib/net/netflag.js +55 -0
  60. package/lib/net/receiver.js +66 -0
  61. package/lib/net/security-master.js +139 -20
  62. package/lib/net/sender.js +141 -0
  63. package/lib/net/tcp-return.js +18 -0
  64. package/lib/net/tcp-session.js +286 -0
  65. package/lib/net/tcpreq-client-proxy.js +70 -0
  66. package/lib/net/tcprequest-mgr.js +58 -0
  67. package/lib/observers/apollo-server-observer.js +33 -27
  68. package/lib/observers/cluster-observer.js +22 -0
  69. package/lib/observers/express-observer.js +215 -0
  70. package/lib/observers/file-observer.js +184 -0
  71. package/lib/observers/global-observer.js +155 -80
  72. package/lib/observers/grpc-observer.js +336 -0
  73. package/lib/observers/http-observer.js +666 -236
  74. package/lib/observers/maria-observer.js +204 -362
  75. package/lib/observers/memcached-observer.js +56 -0
  76. package/lib/observers/mongo-observer.js +317 -0
  77. package/lib/observers/mongodb-observer.js +169 -226
  78. package/lib/observers/mongoose-observer.js +518 -323
  79. package/lib/observers/mssql-observer.js +177 -418
  80. package/lib/observers/mysql-observer.js +342 -449
  81. package/lib/observers/mysql2-observer.js +396 -358
  82. package/lib/observers/net-observer.js +77 -0
  83. package/lib/observers/oracle-observer.js +559 -384
  84. package/lib/observers/pgsql-observer.js +231 -489
  85. package/lib/observers/prisma-observer.js +303 -92
  86. package/lib/observers/process-observer.js +79 -35
  87. package/lib/observers/promise-observer.js +31 -0
  88. package/lib/observers/redis-observer.js +166 -331
  89. package/lib/observers/schedule-observer.js +67 -0
  90. package/lib/observers/socket.io-observer.js +226 -187
  91. package/lib/observers/stream-observer.js +19 -0
  92. package/lib/observers/thrift-observer.js +197 -0
  93. package/lib/observers/websocket-observer.js +175 -301
  94. package/lib/pack/activestack-pack.js +55 -0
  95. package/lib/pack/apenum.js +8 -0
  96. package/lib/pack/counter-pack.js +3 -0
  97. package/lib/pack/errorsnap-pack.js +69 -0
  98. package/lib/pack/event-pack.js +54 -0
  99. package/lib/pack/hitmap-pack.js +63 -0
  100. package/lib/pack/hitmap-pack1.js +152 -0
  101. package/lib/pack/log-sink-pack.js +14 -52
  102. package/lib/pack/netstat.js +15 -0
  103. package/lib/pack/otype.js +7 -0
  104. package/lib/pack/profile-pack.js +49 -0
  105. package/lib/pack/realtimeuser-pack.js +41 -0
  106. package/lib/pack/stat-general-pack.js +96 -0
  107. package/lib/pack/staterror-pack.js +120 -0
  108. package/lib/pack/stathttpc-pack.js +66 -0
  109. package/lib/pack/stathttpc-rec.js +78 -0
  110. package/lib/pack/statremote-pack.js +46 -0
  111. package/lib/pack/statservice-pack.js +63 -0
  112. package/lib/pack/statservice-pack1.js +88 -0
  113. package/lib/pack/statservice-rec.js +292 -0
  114. package/lib/pack/statservice-rec_dep.js +151 -0
  115. package/lib/pack/statsql-pack.js +69 -0
  116. package/lib/pack/statsql-rec.js +100 -0
  117. package/lib/pack/statuseragent-pack.js +44 -0
  118. package/lib/pack/tagcount-pack.js +4 -4
  119. package/lib/pack/tagctr.js +15 -0
  120. package/lib/pack/text-pack.js +50 -0
  121. package/lib/pack/time-count.js +25 -0
  122. package/lib/pack/websocket.js +15 -0
  123. package/lib/pack/zip-pack.js +70 -0
  124. package/lib/pii/pii-item.js +31 -0
  125. package/lib/pii/pii-mask.js +174 -0
  126. package/lib/plugin/plugin-loadermanager.js +57 -0
  127. package/lib/plugin/plugin.js +75 -0
  128. package/lib/service/tx-record.js +332 -0
  129. package/lib/stat/stat-error.js +116 -0
  130. package/lib/stat/stat-httpc.js +98 -0
  131. package/lib/stat/stat-remote-ip.js +46 -0
  132. package/lib/stat/stat-remote-ipurl.js +88 -0
  133. package/lib/stat/stat-sql.js +113 -0
  134. package/lib/stat/stat-tranx.js +58 -0
  135. package/lib/stat/stat-tx-caller.js +160 -0
  136. package/lib/stat/stat-tx-domain.js +111 -0
  137. package/lib/stat/stat-tx-referer.js +112 -0
  138. package/lib/stat/stat-useragent.js +48 -0
  139. package/lib/stat/timingsender.js +76 -0
  140. package/lib/step/activestack-step.js +38 -0
  141. package/lib/step/dbc-step.js +36 -0
  142. package/lib/step/http-stepx.js +67 -0
  143. package/lib/step/message-step.js +40 -0
  144. package/lib/step/method-stepx.js +45 -0
  145. package/lib/step/resultset-step.js +40 -0
  146. package/lib/step/securemsg-step.js +44 -0
  147. package/lib/step/socket-step.js +46 -0
  148. package/lib/step/sql-stepx.js +68 -0
  149. package/lib/step/sqlxtype.js +16 -0
  150. package/lib/step/step.js +66 -0
  151. package/lib/step/stepenum.js +54 -0
  152. package/lib/topology/link.js +63 -0
  153. package/lib/topology/nodeinfo.js +123 -0
  154. package/lib/topology/status-detector.js +111 -0
  155. package/lib/trace/trace-context-manager.js +113 -25
  156. package/lib/trace/trace-context.js +21 -7
  157. package/lib/trace/trace-httpc.js +17 -11
  158. package/lib/trace/trace-sql.js +29 -21
  159. package/lib/util/anylist.js +103 -0
  160. package/lib/util/cardinality/hyperloglog.js +106 -0
  161. package/lib/util/cardinality/murmurhash.js +31 -0
  162. package/lib/util/cardinality/registerset.js +75 -0
  163. package/lib/util/errordata.js +21 -0
  164. package/lib/util/escape-literal-sql.js +5 -5
  165. package/lib/util/hashutil.js +18 -18
  166. package/lib/util/iputil_x.js +527 -0
  167. package/lib/util/keygen.js +0 -3
  168. package/lib/util/kube-util.js +73 -0
  169. package/lib/util/linkedset.js +1 -2
  170. package/lib/util/nodeutil.js +2 -1
  171. package/lib/util/paramsecurity.js +80 -0
  172. package/lib/util/pre-process.js +13 -0
  173. package/lib/util/process-seq.js +166 -0
  174. package/lib/util/property-util.js +36 -0
  175. package/lib/util/request-queue.js +70 -0
  176. package/lib/util/requestdouble-queue.js +72 -0
  177. package/lib/util/resourceprofile.js +157 -0
  178. package/lib/util/stop-watch.js +30 -0
  179. package/lib/util/system-util.js +10 -0
  180. package/lib/util/userid-util.js +57 -0
  181. package/lib/value/map-value.js +3 -2
  182. package/package.json +9 -4
  183. package/whatap.conf +1 -4
  184. package/agent/darwin/arm64/whatap_nodejs +0 -0
  185. package/agent/linux/amd64/whatap_nodejs +0 -0
  186. package/agent/linux/arm64/whatap_nodejs +0 -0
  187. package/build.txt +0 -4
  188. package/lib/observers/ioredis-observer.js +0 -294
  189. package/lib/udp/async_sender.js +0 -119
  190. package/lib/udp/index.js +0 -17
  191. package/lib/udp/packet_enum.js +0 -52
  192. package/lib/udp/packet_queue.js +0 -69
  193. package/lib/udp/packet_type_enum.js +0 -33
  194. package/lib/udp/param_def.js +0 -72
  195. package/lib/udp/udp_session.js +0 -336
  196. package/lib/util/sql-util.js +0 -178
  197. package/lib/util/trace-helper.js +0 -91
  198. package/lib/util/transfer.js +0 -58
@@ -0,0 +1,113 @@
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 TABLE_MAX_SIZE = 5000;
8
+
9
+ var LinkedMap = require('../util/linkedmap'),
10
+ SqlRec = require('../pack/statsql-rec'),
11
+ StatSqlPack = require('../pack/statsql-pack'),
12
+ DataPackSender = require('../data/datapack-sender');
13
+
14
+ function StatSql() {
15
+ if(typeof StatSql.instance === 'object') {
16
+ return StatSql.instance;
17
+ }
18
+
19
+ this.table = new LinkedMap(TABLE_MAX_SIZE + 1, 1).setMax(TABLE_MAX_SIZE);
20
+ this.table.hash = function (k) {
21
+ if(k._hash_){
22
+ return k._hash_;
23
+ }
24
+ var result = 1;
25
+ result = 31 * result + k.dbc;
26
+ result = 31 * result + k.sql;
27
+
28
+ k._hash_=result;
29
+ return result;
30
+ }
31
+ this.table.equals = function (k1,k2) {
32
+ return k1.dbc === k2.dbc && k1.sql === k2.sql;
33
+ }
34
+ this.table.create = function (key) {
35
+ if(this.isFull()) {
36
+ return null;
37
+ }
38
+ var rec = new SqlRec();
39
+ rec.dbc = key.dbc;
40
+ rec.sql = key.sql;
41
+ rec.time_min = Number.MAX_SAFE_INTEGER;
42
+ return rec;
43
+ };
44
+
45
+ StatSql.instance = this;
46
+ }
47
+ StatSql.prototype.getSql = function (dbc, sql) {
48
+ var key = {dbc: dbc ,
49
+ sql: sql
50
+ };
51
+ return this.table.intern(key);
52
+ };
53
+ StatSql.prototype.addFetch = function (dbc, sql, fetch, fetchTime) {
54
+ if(sql === 0) {
55
+ return;
56
+ }
57
+ var r = this.getSql(dbc, sql);
58
+ if(r != null) {
59
+ r.fetch_count += fetch;
60
+ r.fetch_time += fetchTime;
61
+ }
62
+ };
63
+ // StatSql.prototype.addUpdate = function (dbc, sql, updated) {
64
+ // if(sql === 0) {
65
+ // return;
66
+ // }
67
+ // var r = this.getSql(dbc, sql);
68
+ // if(r != null) {
69
+ // r.update_count = r.update_count.add(updated);
70
+ // }
71
+ // };
72
+
73
+ StatSql.prototype.addSqlTime = function (urlHash, dbc, sql, time, isErr, updated) {
74
+
75
+ urlHash = urlHash || 0;
76
+ sql = sql || 0;
77
+ time = time || 0;
78
+ updated = updated || 0;
79
+
80
+ if(sql === 0) {
81
+ return;
82
+ }
83
+ var sqlRec = this.getSql(dbc, sql);
84
+ if(sqlRec != null) {
85
+ sqlRec.count_total++;
86
+ sqlRec.time_sum +=time;
87
+ sqlRec.time_std += time*time;
88
+ sqlRec.time_min = Math.min(sqlRec.time_min, time);
89
+ sqlRec.time_max = Math.max(sqlRec.time_max, time);
90
+ if(isErr) {
91
+ sqlRec.count_error++;
92
+ }
93
+ sqlRec.update_count +=updated;
94
+ sqlRec.service = urlHash;
95
+ }
96
+ };
97
+ StatSql.prototype.send = function (now) {
98
+ if(this.table.size() === 0) {
99
+ return;
100
+ }
101
+
102
+ var p = new StatSqlPack().setRecords(this.table.size(), this.table.values());
103
+ p.time = now;
104
+ this.table.clear();
105
+ DataPackSender.sendStatSqlPack(p);
106
+ };
107
+ StatSql.prototype.clear = function () {
108
+ this.table.clear();
109
+ };
110
+
111
+
112
+ //싱글톤으로 동작해야한다.
113
+ module.exports = new StatSql();
@@ -0,0 +1,58 @@
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 IntKeyLinkedMap = require('../util/intkey-linkedmap'),
8
+ TransactionRec = require('../pack/statservice-rec'),
9
+ StatServicePack = require('../pack/statservice-pack'),
10
+ StatServicePack1 = require('../pack/statservice-pack1'),
11
+ conf = require('./../conf/configure'),
12
+ Logger = require('../logger'),
13
+ DataPackSender = require('../data/datapack-sender')
14
+
15
+ const TABLE_MAX_SIZE = 5000;
16
+
17
+ function StatTranx() {
18
+ if(typeof StatTranx.instance === 'object') {
19
+ return StatTranx.instance;
20
+ }
21
+
22
+ this.table = new IntKeyLinkedMap(TABLE_MAX_SIZE + 1, 1).setMax(TABLE_MAX_SIZE);
23
+ this.table.create = function (hash) {
24
+ if(this.isFull()) {
25
+ return null;
26
+ }
27
+ var rec = new TransactionRec();
28
+ rec.setUrlHash(hash);
29
+ rec.time_min = Number.MAX_VALUE;
30
+ return rec;
31
+ };
32
+
33
+ StatTranx.instance = this;
34
+ }
35
+
36
+ StatTranx.prototype.getService = function (hash) {
37
+ return this.table.intern(hash);
38
+ };
39
+ StatTranx.prototype.send = function (now) {
40
+ if(this.table.size() === 0) {
41
+ return;
42
+ }
43
+ var p = undefined;
44
+ if(conf.stat_service1_enabled){
45
+ p = new StatServicePack1().setRecords(this.table.size(), this.table.values());
46
+ p.spec = conf.mtrace_spec_hash;
47
+ }else{
48
+ p = new StatServicePack().setRecords(this.table.size(), this.table.values());
49
+ }
50
+ p.time = now;
51
+ this.table.clear();
52
+ DataPackSender.sendStatServicePack(p);
53
+ };
54
+ StatTranx.prototype.clear = function () {
55
+ this.table.clear();
56
+ };
57
+
58
+ module.exports = new StatTranx();
@@ -0,0 +1,160 @@
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 LinkedMap = require('../util/linkedmap'),
8
+ AnyList = require('../util/anylist'),
9
+ StatGeneralPack = require('../pack/stat-general-pack'),
10
+ DataPackSender = require('../data/datapack-sender'),
11
+ Logger = require('../logger'),
12
+ HashUtil = require('../util/hashutil'),
13
+ StringUtil = require('../util/string-util'),
14
+ DataTextAgent = require('../data/datatext-agent'),
15
+ conf = require('../conf/configure'),
16
+ TimeCount = require('../pack/time-count');
17
+
18
+ const TABLE_MAX_SIZE = 5000;
19
+
20
+ function PK(caller_pcode, caller_okind, caller_spec, caller_url, url) {
21
+ this.caller_pcode = caller_pcode;
22
+ this.caller_okind = caller_okind;
23
+ this.caller_spec = caller_spec ;
24
+ this.caller_url = caller_url;
25
+ this.url = url ;
26
+ }
27
+
28
+ PK.prototype.hashCode = function () {
29
+ if(this._hash_){
30
+ return this._hash_;
31
+ }
32
+ var prime = 31;
33
+ var result = 1;
34
+ result = prime * result + this.caller_pcode;
35
+ result = prime * result + this.caller_okind;
36
+ result = prime * result + this.caller_spec;
37
+ result = prime * result + this.caller_url;
38
+ result = prime * result + this.url;
39
+ this._hash_=result;
40
+ return result;
41
+ };
42
+ PK.prototype.equals = function (other) {
43
+ if(this === other) {
44
+ return true;
45
+ }
46
+ if(other == null) {
47
+ return false;
48
+ }
49
+ if(other instanceof PK === false) {
50
+ return false;
51
+ }
52
+ return this.caller_pcode === other.caller_pcode
53
+ && this.caller_okind === other.caller_okind
54
+ && this.caller_spec === other.caller_spec
55
+ && this.caller_url === other.caller_url
56
+ && this.url === other.url;
57
+ };
58
+
59
+
60
+ function StatTranxMtCaller() {
61
+ if(typeof StatTranxMtCaller.instance === 'object') {
62
+ return StatTranxMtCaller.instance;
63
+ }
64
+
65
+ this.table = new LinkedMap(TABLE_MAX_SIZE + 1 , 1).setMax(TABLE_MAX_SIZE);
66
+ this.table.create = function (key) {
67
+ if(this.size() >= TABLE_MAX_SIZE) {
68
+ return null;
69
+ }
70
+ return new TimeCount();
71
+ };
72
+
73
+ conf.on('stat_mtrace_max_count', function(props){
74
+ StatTranxMtCaller.instance.table.setMax(props);
75
+ })
76
+
77
+ StatTranxMtCaller.instance = this;
78
+ }
79
+
80
+ StatTranxMtCaller.prototype.getService = function (caller_pcode, caller_okind, caller_spec, caller_url,url) {
81
+ return this.table.intern(new PK(caller_pcode,caller_okind,caller_spec, caller_url, url));
82
+ };
83
+ StatTranxMtCaller.prototype.add = function (caller_pcode, caller_spec, caller_url, url,
84
+ time, isErr) {
85
+ try {
86
+ var rec = this.getService(caller_pcode, caller_spec, caller_url,url);
87
+ if(rec) {
88
+ rec.count++;
89
+ if(isErr){
90
+ rec.error++;
91
+ }
92
+ rec.toime +=time;
93
+ }
94
+ } catch(e) {
95
+ Logger.printError("WHATAP-610", "StatTranxMtCaller add error", e, false);
96
+ }
97
+ };
98
+ StatTranxMtCaller.prototype.send = function (now) {
99
+ if(this.table.size() === 0) {
100
+ return;
101
+ }
102
+ var mtrace_spec_hash = 0;
103
+ // if(conf.mtrace_spec) {
104
+ // mtrace_spec_hash = HashUtil.hash(conf.mtrace_spec);
105
+ // DataTextAgent.MTRACE_SPEC.add(mtrace_spec_hash,conf.mtrace_spec);
106
+ // }
107
+ if( StringUtil.isNotEmpty(conf.mtrace_spec) ){
108
+ DataTextAgent.MTRACE_SPEC.add(conf.mtrace_spec_hash, conf.mtrace_spec);
109
+ }
110
+
111
+ var rsize=this.table.size();
112
+ var caller_pcode =new AnyList(AnyList.LONG, rsize); /*pcode=LONG*/
113
+ var caller_okind =new AnyList(AnyList.INT, rsize);
114
+ var caller_spec =new AnyList(AnyList.INT, rsize);
115
+ var caller_url =new AnyList(AnyList.INT, rsize);
116
+ var spec =new AnyList(AnyList.INT, rsize);
117
+ var url =new AnyList(AnyList.INT, rsize);
118
+ var count = new AnyList(AnyList.INT, rsize);
119
+ var error = new AnyList(AnyList.INT, rsize);
120
+ var time = new AnyList(AnyList.LONG, rsize);
121
+
122
+ var en = this.table.entries();
123
+ for (var i = 0; i<rsize && en.hasMoreElements(); i++) {
124
+ var ent = en.nextElement();
125
+ var k = ent.getKey();
126
+ var v = ent.getValue();
127
+
128
+ caller_pcode.put(i, k.caller_pcode);
129
+ caller_okind.put(i, k.caller_okind);
130
+ caller_spec.put(i, k.caller_spec);
131
+ caller_url.put(i, k.caller_url);
132
+ spec.put(i, mtrace_spec_hash);
133
+ url.put(i, k.url);
134
+ count.put(i, v.count);
135
+ error.put(i, v.error);
136
+ time.put(i, v.time);
137
+ }
138
+ this.table.clear();
139
+
140
+ var out = new StatGeneralPack();
141
+ out.put("caller_pcode", caller_pcode);
142
+ out.put("caller_okind", caller_okind);
143
+ out.put("caller_spec", caller_spec);
144
+ out.put("caller_url", caller_url);
145
+ out.put("spec", spec);
146
+ out.put("url", url);
147
+ out.put("count", count);
148
+ out.put("error", error);
149
+ out.put("time", time);
150
+
151
+ out.id = "mt";
152
+ out.time = now;
153
+
154
+ DataPackSender.sendPack(out);
155
+ };
156
+ StatTranxMtCaller.prototype.clear = function () {
157
+ this.table.clear();
158
+ };
159
+
160
+ module.exports = new StatTranxMtCaller();
@@ -0,0 +1,111 @@
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 LinkedMap = require('../util/linkedmap'),
8
+ AnyList = require('../util/anylist'),
9
+ StatGeneralPack = require('../pack/stat-general-pack'),
10
+ DataPackSender = require('../data/datapack-sender'),
11
+ Logger = require('../logger'),
12
+ TimeCount = require('../pack/time-count');
13
+
14
+ const TABLE_MAX_SIZE = 5000;
15
+
16
+ function PK(domain, url) {
17
+ this.domain = domain || 0;
18
+ this.url = url || 0;
19
+ }
20
+
21
+ PK.prototype.hashCode = function () {
22
+ var prime = 31;
23
+ var result = 1;
24
+ result = prime * result + this.domain;
25
+ result = prime * result + this.url;
26
+ return result;
27
+ };
28
+ PK.prototype.equals = function (other) {
29
+ if(this === other) {
30
+ return true;
31
+ }
32
+ if(other == null) {
33
+ return false;
34
+ }
35
+ return this.domain === other.domain && this.url === other.url;
36
+ };
37
+
38
+
39
+ function StatTranxDomain() {
40
+ if(typeof StatTranxDomain.instance === 'object') {
41
+ return StatTranxDomain.instance;
42
+ }
43
+
44
+ this.table = new LinkedMap(TABLE_MAX_SIZE + 1 , 1).setMax(TABLE_MAX_SIZE);
45
+ this.table.create = function (key) {
46
+ if(this.size() >= TABLE_MAX_SIZE) {
47
+ return null;
48
+ }
49
+ return new TimeCount();
50
+ };
51
+ StatTranxDomain.instance = this;
52
+ }
53
+
54
+ StatTranxDomain.prototype.getService = function (domain, url) {
55
+ return this.table.intern(new PK(domain,url));
56
+ };
57
+ StatTranxDomain.prototype.add = function (domain, url, time, isErr) {
58
+ try {
59
+ var rec = this.getService(domain, url);
60
+ if(rec) {
61
+ rec.count++;
62
+ if(isErr){
63
+ rec.error++;
64
+ }
65
+ rec.toime +=time;
66
+ }
67
+ } catch(e) {
68
+ Logger.printError("WHATAP-610", "StatTranxDomain add error", e, false);
69
+ }
70
+ };
71
+ StatTranxDomain.prototype.send = function (now) {
72
+ if(this.table.size() === 0) {
73
+ return;
74
+ }
75
+ var rsize=this.table.size();
76
+ var domain =new AnyList(AnyList.INT, rsize);
77
+ var url =new AnyList(AnyList.INT, rsize);
78
+ var count = new AnyList(AnyList.INT, rsize);
79
+ var error = new AnyList(AnyList.INT, rsize);
80
+ var time = new AnyList(AnyList.LONG, rsize);
81
+
82
+ var en = this.table.entries();
83
+ for (var i = 0; i<rsize && en.hasMoreElements(); i++) {
84
+ var ent = en.nextElement();
85
+ var k = ent.getKey();
86
+ var v = ent.getValue();
87
+
88
+ domain.put(i, k.domain);
89
+ url.put(i, k.url);
90
+ count.put(i, v.count);
91
+ error.put(i, v.error);
92
+ time.put(i, v.time);
93
+ }
94
+ this.table.clear();
95
+
96
+ var out = new StatGeneralPack();
97
+ out.put("domain", domain);
98
+ out.put("url", url);
99
+ out.put("count", count);
100
+ out.put("error", error);
101
+ out.put("time", time);
102
+
103
+ out.id = "dom";
104
+ out.time = now;
105
+ DataPackSender.sendPack(out);
106
+ };
107
+ StatTranxDomain.prototype.clear = function () {
108
+ this.table.clear();
109
+ };
110
+
111
+ module.exports = new StatTranxDomain();
@@ -0,0 +1,112 @@
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 LinkedMap = require('../util/linkedmap'),
8
+ AnyList = require('../util/anylist'),
9
+ StatGeneralPack = require('../pack/stat-general-pack'),
10
+ DataPackSender = require('../data/datapack-sender'),
11
+ Logger = require('../logger'),
12
+ TimeCount = require('../pack/time-count');
13
+
14
+ const TABLE_MAX_SIZE = 5000;
15
+
16
+ function PK(referer, url) {
17
+ this.referer = referer || 0;
18
+ this.url = url || 0;
19
+ }
20
+
21
+ PK.prototype.hashCode = function () {
22
+ var prime = 31;
23
+ var result = 1;
24
+ result = prime * result + this.referer;
25
+ result = prime * result + this.url;
26
+ return result;
27
+ };
28
+ PK.prototype.equals = function (other) {
29
+ if(this === other) {
30
+ return true;
31
+ }
32
+ if(other == null) {
33
+ return false;
34
+ }
35
+ return this.referer === other.referer && this.url === other.url;
36
+ };
37
+
38
+
39
+ function StatTranxReferer() {
40
+ if(typeof StatTranxReferer.instance === 'object') {
41
+ return StatTranxReferer.instance;
42
+ }
43
+
44
+ this.table = new LinkedMap(TABLE_MAX_SIZE + 1 , 1).setMax(TABLE_MAX_SIZE);
45
+ this.table.create = function (key) {
46
+ if(this.size() >= TABLE_MAX_SIZE) {
47
+ return null;
48
+ }
49
+ return new TimeCount();
50
+ };
51
+ StatTranxReferer.instance = this;
52
+ }
53
+
54
+ StatTranxReferer.prototype.getService = function (referer, url) {
55
+ return this.table.intern(new PK(referer,url));
56
+ };
57
+ StatTranxReferer.prototype.add = function (referer, url, time, isErr) {
58
+ try {
59
+ var rec = this.getService(referer, url);
60
+ if(rec) {
61
+ rec.count++;
62
+ if(isErr){
63
+ rec.error++;
64
+ }
65
+ rec.time +=time;
66
+ }
67
+ } catch(e) {
68
+ Logger.printError("WHATAP-610", "StatTranxReferer add error", e, false);
69
+ }
70
+ };
71
+ StatTranxReferer.prototype.send = function (now) {
72
+ if(this.table.size() === 0) {
73
+ return;
74
+ }
75
+ var rsize=this.table.size();
76
+ var referer =new AnyList(AnyList.INT, rsize);
77
+ var url =new AnyList(AnyList.INT, rsize);
78
+ var count = new AnyList(AnyList.INT, rsize);
79
+ var error = new AnyList(AnyList.INT, rsize);
80
+ var time = new AnyList(AnyList.LONG, rsize);
81
+
82
+ var en = this.table.entries();
83
+ for (var i = 0; i<rsize && en.hasMoreElements(); i++) {
84
+ var ent = en.nextElement();
85
+ var k = ent.getKey();
86
+ var v = ent.getValue();
87
+
88
+ referer.put(i, k.referer);
89
+ url.put(i, k.url);
90
+ count.put(i, v.count);
91
+ error.put(i, v.error);
92
+ time.put(i, v.time);
93
+ }
94
+ this.table.clear();
95
+
96
+ var out = new StatGeneralPack();
97
+
98
+ out.put("referer", referer);
99
+ out.put("url", url);
100
+ out.put("count", count);
101
+ out.put("error", error);
102
+ out.put("time", time);
103
+
104
+ out.id = "referer";
105
+ out.time = now;
106
+ DataPackSender.sendPack(out);
107
+ };
108
+ StatTranxReferer.prototype.clear = function () {
109
+ this.table.clear();
110
+ };
111
+
112
+ module.exports = new StatTranxReferer();
@@ -0,0 +1,48 @@
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 IntIntMap = require('../util/intint-map'),
8
+ StatUserAgentPack = require('../pack/statuseragent-pack'),
9
+ DataPackSender = require('../data/datapack-sender'),
10
+ Long = require('long');
11
+
12
+ const TABLE_MAX_SIZE = 1000;
13
+
14
+ function StatUserAgent() {
15
+ if(typeof StatUserAgent.instance === 'object') {
16
+ return StatUserAgent.instance;
17
+ }
18
+
19
+ this.table = new StatUserAgentPack();
20
+ this.table.userAgents.setMax(TABLE_MAX_SIZE);
21
+
22
+ StatUserAgent.instance = this;
23
+ }
24
+
25
+ StatUserAgent.prototype.incUserAgent = function (userAgent) {
26
+ if(userAgent === 0) {
27
+ return;
28
+ }
29
+ this.table.userAgents.addNoOver(userAgent, 1);
30
+ };
31
+ StatUserAgent.prototype.send = function (now) {
32
+ if(this.table.userAgents.size() === 0) {
33
+ return;
34
+ }
35
+
36
+ var p = this.table;
37
+ p.time = now;
38
+ DataPackSender.sendStatUserAgentPack(p);
39
+
40
+ this.table = new StatUserAgentPack();
41
+ this.table.userAgents.setMax(TABLE_MAX_SIZE);
42
+
43
+ };
44
+ StatUserAgent.prototype.clear = function () {
45
+ this.table.userAgents.clear();
46
+ };
47
+
48
+ module.exports = new StatUserAgent();
@@ -0,0 +1,76 @@
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
+
8
+ var StatError = require('./stat-error'),
9
+ StatTranx = require('./stat-tranx'),
10
+ StatSql = require('./stat-sql'),
11
+ StatHttpc = require('./stat-httpc'),
12
+ StatRemoteIp = require('./stat-remote-ip'),
13
+ StatRemoteIpUrl = require('./stat-remote-ipurl'),
14
+ StatUserAgent = require('./stat-useragent'),
15
+ StatTranxMtCaller = require('./stat-tx-caller'),
16
+ StatTranxDomain = require('./stat-tx-domain'),
17
+ StatTranxReferer = require('./stat-tx-referer'),
18
+ Logger = require('../logger'),
19
+ DateUtil = require('./../util/dateutil');
20
+
21
+ const MILLIS_FIVE_MINUTE = 5 * 60 * 1000;
22
+
23
+ function TimingSender(){
24
+ this.time = Date.now();
25
+ this.run();
26
+ this.intervalIndex = undefined;
27
+ }
28
+ TimingSender.prototype.run = function(){
29
+ var lastUnit = getCurrentFiveMinUnit();
30
+ if(this.intervalIndex){
31
+ clearInterval(this.intervalIndex); this.intervalIndex = undefined;
32
+ }
33
+
34
+ this.intervalIndex = setInterval(function () {
35
+ var nowUnit = getCurrentFiveMinUnit();
36
+ if(nowUnit === lastUnit) { return; }
37
+ try{
38
+ lastUnit = nowUnit;
39
+ var now = DateUtil.currentTime();
40
+ var conf = require('../conf/configure');
41
+
42
+ if(conf.stat_enabled) {
43
+ StatTranx.send(now);
44
+ StatSql.send(now);
45
+ StatHttpc.send(now);
46
+ StatRemoteIp.send(now);
47
+ StatRemoteIpUrl.send(now);
48
+ StatUserAgent.send(now);
49
+ StatError.send(now);
50
+ StatTranxDomain.send(now);
51
+ StatTranxMtCaller.send(now);
52
+ StatTranxReferer.send(now);
53
+ } else {
54
+ StatTranx.clear();
55
+ StatSql.clear();
56
+ StatHttpc.clear();
57
+ StatRemoteIp.clear();
58
+ StatRemoteIpUrl.clear();
59
+ StatUserAgent.clear();
60
+ StatError.clear();
61
+ StatTranxDomain.clear();
62
+ StatTranxMtCaller.clear();
63
+ StatTranxReferer.clear();
64
+ }
65
+ }catch(e){
66
+ Logger.printError('WHATAP-997', 'TimingSender (run)', e, true);
67
+ }
68
+
69
+ }, 1000);
70
+ };
71
+
72
+ function getCurrentFiveMinUnit() {
73
+ return parseInt(DateUtil.currentTime() / MILLIS_FIVE_MINUTE) * MILLIS_FIVE_MINUTE
74
+ }
75
+
76
+ module.exports = new TimingSender();