whatap 0.5.26 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/agent/darwin/arm64/whatap_nodejs +0 -0
  2. package/agent/linux/amd64/whatap_nodejs +0 -0
  3. package/agent/linux/arm64/whatap_nodejs +0 -0
  4. package/build.txt +4 -0
  5. package/lib/conf/config-default.js +3 -10
  6. package/lib/conf/configure.js +349 -369
  7. package/lib/conf/license.js +1 -1
  8. package/lib/control/packagectr-helper.js +3 -34
  9. package/lib/core/agent.js +882 -176
  10. package/lib/core/interceptor.js +6 -6
  11. package/lib/core/shimmer.js +36 -82
  12. package/lib/counter/counter-manager.js +8 -79
  13. package/lib/counter/task/activetransaction.js +17 -68
  14. package/lib/io/data-inputx.js +3 -13
  15. package/lib/io/data-outputx.js +206 -268
  16. package/lib/logger.js +6 -6
  17. package/lib/net/security-master.js +20 -139
  18. package/lib/observers/apollo-server-observer.js +27 -33
  19. package/lib/observers/global-observer.js +80 -155
  20. package/lib/observers/http-observer.js +236 -666
  21. package/lib/observers/ioredis-observer.js +294 -0
  22. package/lib/observers/maria-observer.js +362 -204
  23. package/lib/observers/mongodb-observer.js +226 -169
  24. package/lib/observers/mongoose-observer.js +323 -518
  25. package/lib/observers/mssql-observer.js +418 -177
  26. package/lib/observers/mysql-observer.js +449 -342
  27. package/lib/observers/mysql2-observer.js +358 -396
  28. package/lib/observers/oracle-observer.js +384 -559
  29. package/lib/observers/pgsql-observer.js +489 -231
  30. package/lib/observers/prisma-observer.js +92 -303
  31. package/lib/observers/process-observer.js +35 -79
  32. package/lib/observers/redis-observer.js +331 -166
  33. package/lib/observers/socket.io-observer.js +187 -226
  34. package/lib/observers/websocket-observer.js +301 -175
  35. package/lib/pack/counter-pack.js +0 -3
  36. package/lib/pack/log-sink-pack.js +52 -14
  37. package/lib/pack/tagcount-pack.js +4 -4
  38. package/lib/{counter/task → system}/gc-action.js +74 -27
  39. package/lib/trace/trace-context-manager.js +25 -113
  40. package/lib/trace/trace-context.js +7 -21
  41. package/lib/trace/trace-httpc.js +11 -17
  42. package/lib/trace/trace-sql.js +21 -29
  43. package/lib/udp/async_sender.js +119 -0
  44. package/lib/udp/index.js +17 -0
  45. package/lib/udp/packet_enum.js +52 -0
  46. package/lib/udp/packet_queue.js +69 -0
  47. package/lib/udp/packet_type_enum.js +33 -0
  48. package/lib/udp/param_def.js +72 -0
  49. package/lib/udp/udp_session.js +336 -0
  50. package/lib/util/escape-literal-sql.js +5 -5
  51. package/lib/util/hashutil.js +18 -18
  52. package/lib/util/keygen.js +3 -0
  53. package/lib/util/linkedset.js +2 -1
  54. package/lib/util/nodeutil.js +1 -2
  55. package/lib/util/sql-util.js +178 -0
  56. package/lib/util/trace-helper.js +91 -0
  57. package/lib/util/transfer.js +58 -0
  58. package/lib/value/map-value.js +2 -3
  59. package/package.json +5 -10
  60. package/lib/conf/conf-sys-mon.js +0 -101
  61. package/lib/control/cmd-config.js +0 -24
  62. package/lib/control/control-handler.js +0 -367
  63. package/lib/core/request-agent.js +0 -27
  64. package/lib/counter/meter/meter-activex.js +0 -67
  65. package/lib/counter/meter/meter-httpc.js +0 -57
  66. package/lib/counter/meter/meter-resource.js +0 -9
  67. package/lib/counter/meter/meter-service.js +0 -168
  68. package/lib/counter/meter/meter-socket.io.js +0 -51
  69. package/lib/counter/meter/meter-sql.js +0 -71
  70. package/lib/counter/meter/meter-users.js +0 -58
  71. package/lib/counter/meter.js +0 -183
  72. package/lib/counter/task/agentinfo.js +0 -107
  73. package/lib/counter/task/gcstat.js +0 -34
  74. package/lib/counter/task/heapmem.js +0 -25
  75. package/lib/counter/task/httpc.js +0 -76
  76. package/lib/counter/task/metering-info.js +0 -125
  77. package/lib/counter/task/proc-cpu.js +0 -29
  78. package/lib/counter/task/realtimeuser.js +0 -31
  79. package/lib/counter/task/res/systemECSTask.js +0 -39
  80. package/lib/counter/task/res/systemKubeTask.js +0 -53
  81. package/lib/counter/task/res/util/awsEcsClientThread.js +0 -218
  82. package/lib/counter/task/res/util/linuxProcStatUtil.js +0 -14
  83. package/lib/counter/task/res-sys-cpu.js +0 -62
  84. package/lib/counter/task/service.js +0 -202
  85. package/lib/counter/task/socketio.js +0 -30
  86. package/lib/counter/task/sql.js +0 -105
  87. package/lib/counter/task/systemperf.js +0 -43
  88. package/lib/data/datapack-sender.js +0 -289
  89. package/lib/data/dataprofile-agent.js +0 -162
  90. package/lib/data/datatext-agent.js +0 -135
  91. package/lib/data/event-level.js +0 -15
  92. package/lib/data/test.js +0 -49
  93. package/lib/data/zipprofile.js +0 -197
  94. package/lib/env/constants.js +0 -21
  95. package/lib/error/error-handler.js +0 -437
  96. package/lib/kube/kube-client.js +0 -144
  97. package/lib/lang/text-types.js +0 -58
  98. package/lib/logsink/line-log-util.js +0 -87
  99. package/lib/logsink/line-log.js +0 -12
  100. package/lib/logsink/log-sender.js +0 -78
  101. package/lib/logsink/log-tracer.js +0 -40
  102. package/lib/logsink/sender-util.js +0 -56
  103. package/lib/logsink/zip/zip-send.js +0 -177
  104. package/lib/net/netflag.js +0 -55
  105. package/lib/net/receiver.js +0 -66
  106. package/lib/net/sender.js +0 -141
  107. package/lib/net/tcp-return.js +0 -18
  108. package/lib/net/tcp-session.js +0 -286
  109. package/lib/net/tcpreq-client-proxy.js +0 -70
  110. package/lib/net/tcprequest-mgr.js +0 -58
  111. package/lib/observers/cluster-observer.js +0 -22
  112. package/lib/observers/express-observer.js +0 -215
  113. package/lib/observers/file-observer.js +0 -184
  114. package/lib/observers/grpc-observer.js +0 -336
  115. package/lib/observers/memcached-observer.js +0 -56
  116. package/lib/observers/mongo-observer.js +0 -317
  117. package/lib/observers/net-observer.js +0 -77
  118. package/lib/observers/promise-observer.js +0 -31
  119. package/lib/observers/schedule-observer.js +0 -67
  120. package/lib/observers/stream-observer.js +0 -19
  121. package/lib/observers/thrift-observer.js +0 -197
  122. package/lib/pack/activestack-pack.js +0 -55
  123. package/lib/pack/apenum.js +0 -8
  124. package/lib/pack/errorsnap-pack.js +0 -69
  125. package/lib/pack/event-pack.js +0 -54
  126. package/lib/pack/hitmap-pack.js +0 -63
  127. package/lib/pack/hitmap-pack1.js +0 -152
  128. package/lib/pack/netstat.js +0 -15
  129. package/lib/pack/otype.js +0 -7
  130. package/lib/pack/profile-pack.js +0 -49
  131. package/lib/pack/realtimeuser-pack.js +0 -41
  132. package/lib/pack/stat-general-pack.js +0 -96
  133. package/lib/pack/staterror-pack.js +0 -120
  134. package/lib/pack/stathttpc-pack.js +0 -66
  135. package/lib/pack/stathttpc-rec.js +0 -78
  136. package/lib/pack/statremote-pack.js +0 -46
  137. package/lib/pack/statservice-pack.js +0 -63
  138. package/lib/pack/statservice-pack1.js +0 -88
  139. package/lib/pack/statservice-rec.js +0 -292
  140. package/lib/pack/statservice-rec_dep.js +0 -151
  141. package/lib/pack/statsql-pack.js +0 -69
  142. package/lib/pack/statsql-rec.js +0 -100
  143. package/lib/pack/statuseragent-pack.js +0 -44
  144. package/lib/pack/tagctr.js +0 -15
  145. package/lib/pack/text-pack.js +0 -50
  146. package/lib/pack/time-count.js +0 -25
  147. package/lib/pack/websocket.js +0 -15
  148. package/lib/pack/zip-pack.js +0 -70
  149. package/lib/pii/pii-item.js +0 -31
  150. package/lib/pii/pii-mask.js +0 -174
  151. package/lib/plugin/plugin-loadermanager.js +0 -57
  152. package/lib/plugin/plugin.js +0 -75
  153. package/lib/service/tx-record.js +0 -332
  154. package/lib/stat/stat-error.js +0 -116
  155. package/lib/stat/stat-httpc.js +0 -98
  156. package/lib/stat/stat-remote-ip.js +0 -46
  157. package/lib/stat/stat-remote-ipurl.js +0 -88
  158. package/lib/stat/stat-sql.js +0 -113
  159. package/lib/stat/stat-tranx.js +0 -58
  160. package/lib/stat/stat-tx-caller.js +0 -160
  161. package/lib/stat/stat-tx-domain.js +0 -111
  162. package/lib/stat/stat-tx-referer.js +0 -112
  163. package/lib/stat/stat-useragent.js +0 -48
  164. package/lib/stat/timingsender.js +0 -76
  165. package/lib/step/activestack-step.js +0 -38
  166. package/lib/step/dbc-step.js +0 -36
  167. package/lib/step/http-stepx.js +0 -67
  168. package/lib/step/message-step.js +0 -40
  169. package/lib/step/method-stepx.js +0 -45
  170. package/lib/step/resultset-step.js +0 -40
  171. package/lib/step/securemsg-step.js +0 -44
  172. package/lib/step/socket-step.js +0 -46
  173. package/lib/step/sql-stepx.js +0 -68
  174. package/lib/step/sqlxtype.js +0 -16
  175. package/lib/step/step.js +0 -66
  176. package/lib/step/stepenum.js +0 -54
  177. package/lib/topology/link.js +0 -63
  178. package/lib/topology/nodeinfo.js +0 -123
  179. package/lib/topology/status-detector.js +0 -111
  180. package/lib/util/anylist.js +0 -103
  181. package/lib/util/cardinality/hyperloglog.js +0 -106
  182. package/lib/util/cardinality/murmurhash.js +0 -31
  183. package/lib/util/cardinality/registerset.js +0 -75
  184. package/lib/util/errordata.js +0 -21
  185. package/lib/util/iputil_x.js +0 -527
  186. package/lib/util/kube-util.js +0 -73
  187. package/lib/util/paramsecurity.js +0 -80
  188. package/lib/util/pre-process.js +0 -13
  189. package/lib/util/process-seq.js +0 -166
  190. package/lib/util/property-util.js +0 -36
  191. package/lib/util/request-queue.js +0 -70
  192. package/lib/util/requestdouble-queue.js +0 -72
  193. package/lib/util/resourceprofile.js +0 -157
  194. package/lib/util/stop-watch.js +0 -30
  195. package/lib/util/system-util.js +0 -10
  196. package/lib/util/userid-util.js +0 -57
@@ -1,125 +0,0 @@
1
- /**
2
- * Copyright 2025 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 CounterTask = require('./counter-task'),
8
- DataPackSender = require('../../data/datapack-sender'),
9
- conf = require('../../conf/configure'),
10
- DateUtil = require('../../util/dateutil'),
11
- Logger = require('../../logger'),
12
- fs = require('fs'),
13
- TagCountPack = require('../../pack/tagcount-pack'),
14
- OType = require('../../pack/otype'),
15
- APEnum = require('../../pack/apenum'),
16
- Util = require('../../util/index');
17
-
18
- function MeteringInfo() {
19
- CounterTask.call(this);
20
- this.first_connected = true;
21
- this.lastTime = DateUtil.getFiveMinUnit(DateUtil.currentTime());
22
- this.hostUUID = null;
23
- this.csp = null;
24
- this.hostUUIDFileName = '/sys/class/dmi/id/product_uuid';
25
- }
26
-
27
- MeteringInfo.prototype = new CounterTask();
28
- MeteringInfo.prototype.constructor = MeteringInfo;
29
-
30
- MeteringInfo.prototype.process = function (p) {
31
- if (!conf.getProperty('metering_tagcount_enabled', false)) {
32
- return;
33
- }
34
-
35
- if (this.first_connected) {
36
- this.first_connected = false;
37
- this.doProcess(p);
38
- return;
39
- }
40
-
41
- const now = DateUtil.getFiveMinUnit(DateUtil.currentTime());
42
- if (this.lastTime >= now) {
43
- return;
44
- }
45
-
46
- this.lastTime = now;
47
- this.doProcess(p);
48
- };
49
-
50
- MeteringInfo.prototype.doProcess = function (p) {
51
- const host_uuid = this.getHostUUID(this.hostUUIDFileName);
52
- if(!host_uuid)
53
- return;
54
-
55
- const pk = new TagCountPack();
56
- pk.category = 'metering';
57
- pk.time = DateUtil.currentTime() / 300000 * 300000;
58
-
59
- pk.putTagInt('otype', OType.AP);
60
- pk.putTagInt('subtype', APEnum.AP_NODE);
61
- pk.putTagInt('ip', p.host_ip);
62
- pk.putTagString('host_uuid', host_uuid);
63
- pk.putTagString('_no_5m_hour_', "");
64
-
65
- const csp = this.getCsp();
66
- if (csp) {
67
- pk.putTagString('csp', csp)
68
- }
69
-
70
- pk.putTagFloat('mcore', p.metering)
71
-
72
- DataPackSender.sendTagCounterPack(pk);
73
- };
74
-
75
- MeteringInfo.prototype.hasHostUUID = function (fileName) {
76
- try{
77
- return fs.existsSync(fileName);
78
- }catch (e) {
79
- Logger.printError("WHATAP-081", "hasHostUUID error", e, false);
80
- return false;
81
- }
82
- };
83
-
84
- MeteringInfo.prototype.getHostUUID = function (fileName) {
85
- const hostUUID = this.getHostUUIDValue();
86
- if (hostUUID) {
87
- return hostUUID;
88
- }
89
-
90
- const hasHostUUIDFile = this.hasHostUUID(fileName);
91
- if (hasHostUUIDFile) {
92
- try {
93
- const data = fs.readFileSync(fileName, 'utf8').trim();
94
- if (data && data.length > 0) {
95
- this.hostUUID = data;
96
- return this.hostUUID;
97
- } else {
98
- Logger.print('WHATAP-082', `cannot read ${fileName}`, false);
99
- }
100
- } catch (error) {
101
- Logger.printError('WHATAP-083', `error reading ${fileName}`, error, false);
102
- }
103
- } else {
104
- Logger.print('WHATAP-084', `cannot find ${fileName}`, false);
105
- }
106
- return null;
107
- };
108
-
109
- MeteringInfo.prototype.getHostUUIDValue = function () {
110
- return this.hostUUID;
111
- };
112
-
113
- MeteringInfo.prototype.getCsp = function () {
114
- if(process.env["ECS_CONTAINER_METADATA_URI"]) {
115
- this.csp = "aws";
116
- return this.csp;
117
- }
118
- if(Util.cloudPlatformCheck()) {
119
- this.csp = "kic";
120
- return this.csp;
121
- }
122
- return null;
123
- };
124
-
125
- module.exports = MeteringInfo;
@@ -1,29 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var CounterTask = require('./counter-task'),
8
- ResourceProfile = require('./../../util/resourceprofile'),
9
- Long = require('long');
10
-
11
- function ProcCpu() {
12
- CounterTask.call(this);
13
- this.oldCpu = 0;
14
- }
15
-
16
- ProcCpu.prototype = new CounterTask();
17
- ProcCpu.prototype.constructor = ProcCpu;
18
- ProcCpu.prototype.process = function (p) {
19
- var cpu = ResourceProfile.getCPU().times; /*long*/
20
- if(this.oldCpu<=0) {
21
- this.oldCpu = cpu;
22
- return;
23
- }
24
- var dTime = cpu - this.oldCpu;
25
- this.oldCpu = cpu;
26
- p.cputime = dTime;
27
- };
28
-
29
- module.exports = ProcCpu;
@@ -1,31 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var CounterTask = require('./counter-task'),
8
- MeterUser = require('../meter/meter-users'),
9
- RealTimeUserPack= require('../../pack/realtimeuser-pack'),
10
- DataPackSender = require('../../data/datapack-sender'),
11
- Long = require('long');
12
-
13
- function RealTimeUser() {
14
-
15
- }
16
- RealTimeUser.prototype = new CounterTask();
17
- RealTimeUser.prototype.constructor = RealTimeUser;
18
- RealTimeUser.prototype.process = function (p) {
19
- var hll = MeterUser.getRealtimeUsers();
20
- if(hll == null) {
21
- return;
22
- }
23
-
24
- var pk = new RealTimeUserPack();
25
- pk.time = p.time;
26
- pk.cadinality=hll.cardinality();
27
- pk.logbits = hll.getBytes();
28
- DataPackSender.sendRealtimeUserPack(pk);
29
- };
30
-
31
- module.exports = RealTimeUser;
@@ -1,39 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var CounterTask = require('../counter-task'),
8
- conf = require('../../../conf/configure'),
9
- SecurityMaster = require('../../../net/security-master'),
10
- AwsEcsClientThread = require('./util/awsEcsClientThread');
11
-
12
- function SystemECSTask() {
13
- CounterTask.call(this);
14
- }
15
-
16
- SystemECSTask.prototype = new CounterTask();
17
- SystemECSTask.prototype.constructor = SystemECSTask;
18
- SystemECSTask.prototype.process = function (p) {
19
- p.host_ip = SecurityMaster.IP;
20
-
21
- var ecs = AwsEcsClientThread;
22
-
23
- setTimeout(() => {
24
- p.cpu = ecs.cpu * conf.correction_factor_cpu;
25
- p.cpu_sys = ecs.cpu_sys;
26
- p.cpu_usr = ecs.cpu_user;
27
- p.mem = ecs.mem_pct;
28
-
29
- if (ecs.millicore > 0) {
30
- p.metering = ecs.millicore / 1024;
31
- p.cpu_cores = Math.ceil(p.metering);
32
- } else {
33
- p.metering = p.cpu_cores;
34
- }
35
- }, 500);
36
-
37
- };
38
-
39
- module.exports = SystemECSTask;
@@ -1,53 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var CounterTask = require('../counter-task'),
8
- StatSql = require('../../../stat/stat-sql'),
9
- conf = require('../../../conf/configure'),
10
- ConfSysMon = require('../../../conf/conf-sys-mon'),
11
- SecurityMaster = require('../../../net/security-master'),
12
- TraceContextManager = require('../../../trace/trace-context-manager'),
13
- MeterActiveX = require('../../meter/meter-activex'),
14
- ActiveStackPack = require('../../../pack/activestack-pack'),
15
- ParamPack = require('../../../pack/param-pack'),
16
- EventPack = require('../../../pack/event-pack'),
17
- ActiveStackStep = require('../../../step/activestack-step'),
18
- DataPackSender = require('../../../data/datapack-sender'),
19
- DataTextAgent = require('../../../data/datatext-agent'),
20
- EventLevel = require('../../../data/event-level'),
21
- MeterUsers = require('../../meter/meter-users'),
22
- KeyGen = require('../../../util/keygen'),
23
- TextTypes = require('../../../lang/text-types'),
24
- ResourceProfile = require('../../../util/resourceprofile'),
25
- Logger = require('../../../logger'),
26
- HashUtil = require('../../../util/hashutil'),
27
- KubeUtil = require('../../../util/kube-util'),
28
- KubeClient = require('../../../kube/kube-client'),
29
- DateUtil = require('../../../util/dateutil'),
30
- Long = require('long');
31
-
32
- function SystemKubeTask() {
33
- CounterTask.call(this);
34
-
35
- this.last_metering = -1;
36
- }
37
-
38
- SystemKubeTask.prototype = new CounterTask();
39
- SystemKubeTask.prototype.constructor = SystemKubeTask;
40
- SystemKubeTask.prototype.process = function (p) {
41
- p.cpu_cores = 1; // static one core in nodejs
42
- p.host_ip = SecurityMaster.IP;
43
- var now = Date.now();
44
- p.cpu = 0;
45
- p.mem = 0;
46
- if (p.metering != 0) {
47
- this.last_metering = p.metering;
48
- } else {
49
- p.metering = this.last_metering;
50
- }
51
- };
52
-
53
- module.exports = SystemKubeTask;
@@ -1,218 +0,0 @@
1
- var http = require('http');
2
- /**
3
- * Copyright 2016 the WHATAP project authors. All rights reserved.
4
- * Use of this source code is governed by a license that
5
- * can be found in the LICENSE file.
6
- */
7
-
8
- var CounterTask = require('../../counter-task'),
9
- conf = require('../../../../conf/configure'),
10
- Logger = require('../../../../logger'),
11
- DateUtil = require('../../../../util/dateutil');
12
-
13
- function AwsEcsClientThread() {
14
- if (typeof AwsEcsClientThread.instance === "object") {
15
- return AwsEcsClientThread.instance;
16
- }
17
-
18
- this.millicore = 0;
19
- this.last_milli_check = 0;
20
- this.check = AwsEcsClientThread.CHECK_MAX;
21
-
22
-
23
- this.cpu = 0;
24
- this.cpu_sys = 0;
25
- this.cpu_user = 0;
26
- this.mem_pct = 0;
27
-
28
- var self = this;
29
- setTimeout(function () {
30
- self.run();
31
- }, 100);
32
- AwsEcsClientThread.instance = this;
33
- };
34
- AwsEcsClientThread.prototype = new AwsEcsClientThread();
35
-
36
- AwsEcsClientThread.prototype.run = function () {
37
- var self = this;
38
- try {
39
- if (conf.aws_ecs_enabled) {
40
- self.intervalIndex = setInterval(function () {
41
- var meta_uri = process.env["ECS_CONTAINER_METADATA_URI"];
42
- if (meta_uri != null) {
43
- self.getCpuLimit(meta_uri);
44
- self.process(meta_uri);
45
- }
46
- }, conf.getProperty('aws_ecs_stat_interval', 3000));
47
- }
48
- } catch (e) {
49
- Logger.printError('WHATAP ECS-ERR ', 'run exception', e, true);
50
- }
51
- }
52
-
53
- AwsEcsClientThread.prototype.stop = function () {
54
- if (this.intervalIndex) {
55
- clearInterval(this.intervalIndex);
56
- this.intervalIndex = undefined;
57
- }
58
- }
59
-
60
- AwsEcsClientThread.prototype.getCpuLimit = function (meta_uri) {
61
- var self = this;
62
-
63
- if (this.check < 0)
64
- return;
65
- var now = Date.now();
66
- if (now - DateUtil.MILLIS_PER_HOUR * 8 < this.last_milli_check)
67
- return;
68
-
69
- // var json = JSON.parse('{"DockerId":"e9950915-abaa-467f-9898-3bd0d4e6d0aa","Name":"web-application","DockerName":"ecs-web-application-1","Image":"nginx:latest","ImageID":"sha256:123456789abcdef...","Labels":{"com.amazonaws.ecs.cluster":"default","com.amazonaws.ecs.task-arn":"arn:aws:ecs:us-east-1:123456789012:task/default/1234567890abcdef","com.amazonaws.ecs.task-definition-family":"web-application","com.amazonaws.ecs.task-definition-version":"1"},"DesiredStatus":"RUNNING","KnownStatus":"RUNNING","Limits":{"CPU":256,"Memory":512},"CreatedAt":"2024-01-01T00:00:00.000Z","StartedAt":"2024-01-01T00:00:01.000Z","Type":"NORMAL","Networks":[{"NetworkMode":"awsvpc","IPv4Addresses":["172.31.10.100"],"AttachmentIndex":0,"MACAddress":"0a:1b:2c:3d:4e:5f","IPv4SubnetCIDRBlock":"172.31.0.0/20","DomainNameServers":["169.254.169.253"],"DomainNameSearchList":["us-east-1.compute.internal"],"PrivateDNSName":"ip-172-31-10-100.us-east-1.compute.internal","SubnetGatewayIpv4Address":"172.31.0.1/20"}],"ContainerARN":"arn:aws:ecs:us-east-1:123456789012:container/1234567890abcdef","LogDriver":"awslogs","LogOptions":{"awslogs-group":"/ecs/web-application","awslogs-region":"us-east-1","awslogs-stream":"ecs/web-application/1234567890abcdef"}}');
70
- // 2025-01-23 ECS fargate
71
- // var json = JSON.parse('{"DockerId":"a663f01570b14228b0795db9c8d11e16-2785547837","Name":"test_container","DockerName":"test_container","Image":"whataphub/ecs_sample:v0.0.4","ImageID":"sha256:748b5cd202288478bbdbd4baf8fe17c8b660163c24c513db5ccbe7a1bdcae0e0","Labels":{"com.amazonaws.ecs.cluster":"arn:aws:ecs:ap-northeast-2:592247757306:cluster/ecs_sample","com.amazonaws.ecs.container-name":"test_container","com.amazonaws.ecs.task-arn":"arn:aws:ecs:ap-northeast-2:592247757306:task/ecs_sample/a663f01570b14228b0795db9c8d11e16","com.amazonaws.ecs.task-definition-family":"ecs_task_sample","com.amazonaws.ecs.task-definition-version":"4"},"DesiredStatus":"RUNNING","KnownStatus":"RUNNING","Limits":{"CPU":2},"CreatedAt":"2025-01-23T04:42:03.843875803Z","StartedAt":"2025-01-23T04:42:03.843875803Z","Type":"NORMAL","Networks":[{"NetworkMode":"awsvpc","IPv4Addresses":["172.31.63.147"]}]}');
72
- // if (json && json["Limits"]) {
73
- // this.millicore = json.Limits.CPU;
74
- // if (this.millicore < 128) {
75
- // this.millicore *= 1024;
76
- // }
77
- // Logger.print("SysCPU", " ECS CPU Limits : " + (this.millicore / 1024) + "core", false)
78
- // }
79
-
80
- read(meta_uri, function(json){
81
- if (json && json["Limits"]) {
82
- this.millicore = json.Limits.CPU;
83
- if (this.millicore < 128) {
84
- this.millicore *= 1024;
85
- }
86
- Logger.print("WHATAP-811", "ECS CPU Limits : " + (this.millicore / 1024) + "core", false)
87
- }
88
- }, function(){
89
- self.millicore = 0;
90
- if (--self.check >= 0) {
91
- Logger.printError('WHATAP-819' , 'not receive limit cpu', e , true);
92
- }
93
- })
94
- }
95
-
96
- AwsEcsClientThread.prototype.process = function (meta_uri) {
97
- var self = this;
98
-
99
- fetch(meta_uri + '/stats', {timeout: 3000})
100
- .then(response => response.text())
101
- .then(stats => {
102
- if (!stats || stats.length === 0) {
103
- self.reset();
104
- return;
105
- }
106
-
107
- // let stats = '{"blkio_stats":{"io_merged_recursive":[],"io_queue_recursive":[],"io_service_bytes_recursive":[{"major":259,"minor":3,"op":"Read","value":0},{"major":259,"minor":3,"op":"Write","value":45514752},{"major":259,"minor":3,"op":"Sync","value":4268032},{"major":259,"minor":3,"op":"Async","value":41246720},{"major":259,"minor":3,"op":"Discard","value":0},{"major":259,"minor":3,"op":"Total","value":45514752}],"io_service_time_recursive":[],"io_serviced_recursive":[{"major":259,"minor":3,"op":"Read","value":0},{"major":259,"minor":3,"op":"Write","value":342},{"major":259,"minor":3,"op":"Sync","value":272},{"major":259,"minor":3,"op":"Async","value":70},{"major":259,"minor":3,"op":"Discard","value":0},{"major":259,"minor":3,"op":"Total","value":342}],"io_time_recursive":[],"io_wait_time_recursive":[],"sectors_recursive":[]},"cpu_stats":{"cpu_usage":{"percpu_usage":[5585610339,5944268076],"total_usage":15373171220,"usage_in_kernelmode":2150000000,"usage_in_usermode":7990000000},"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"id":"10b741d47dc649d5b321f83c7c14c950-441560335","memory_stats":{"limit":9223372036854772000,"max_usage":246165504,"stats":{"active_anon":0,"active_file":27439104,"cache":56365056,"dirty":0,"hierarchical_memory_limit":2147483648,"hierarchical_memsw_limit":9223372036854772000,"inactive_anon":98267136,"inactive_file":28925952,"mapped_file":0,"pgfault":303666,"pgmajfault":0,"pgpgin":199749,"pgpgout":161965,"rss":98402304,"rss_huge":0,"total_active_anon":0,"total_active_file":27439104,"total_cache":56365056,"total_dirty":0,"total_inactive_anon":98267136,"total_inactive_file":28925952,"total_mapped_file":0,"total_pgfault":303666,"total_pgmajfault":0,"total_pgpgin":199749,"total_pgpgout":161965,"total_rss":98402304,"total_rss_huge":0,"total_unevictable":0,"total_writeback":135168,"unevictable":0,"writeback":135168},"usage":168361984},"name":"simple-user-app","networks":{"eth1":{"rx_bytes":1604876131,"rx_dropped":0,"rx_errors":0,"rx_packets":1076062,"tx_bytes":6252490,"tx_dropped":0,"tx_errors":0,"tx_packets":74457}},"num_procs":0,"pids_stats":{},"precpu_stats":{"cpu_usage":{"percpu_usage":[5570558410,5925648831],"total_usage":15328276321,"usage_in_kernelmode":2140000000,"usage_in_usermode":7970000000},"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"preread":"2023-05-30T11:29:20.720196524Z","read":"2023-05-30T11:29:30.719936356Z","storage_stats":{}}';
108
- // 2025-01-23 ECS fargate
109
- // var stats = '{"read":"2025-01-23T04:42:03.844081622Z","preread":"0001-01-01T00:00:00Z","pids_stats":{},"blkio_stats":{"io_service_bytes_recursive":[],"io_serviced_recursive":[],"io_queue_recursive":[],"io_service_time_recursive":[],"io_wait_time_recursive":[],"io_merged_recursive":[],"io_time_recursive":[],"sectors_recursive":[]},"num_procs":0,"storage_stats":{},"cpu_stats":{"cpu_usage":{"total_usage":33451672,"percpu_usage":[22728826,10722846],"usage_in_kernelmode":10000000,"usage_in_usermode":20000000},"system_cpu_usage":397640000000,"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"precpu_stats":{"cpu_usage":{"total_usage":0,"usage_in_kernelmode":0,"usage_in_usermode":0},"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"memory_stats":{"usage":765952,"max_usage":5267456,"stats":{"active_anon":0,"active_file":0,"cache":0,"dirty":0,"hierarchical_memory_limit":4294967296,"hierarchical_memsw_limit":9223372036854771712,"inactive_anon":135168,"inactive_file":0,"mapped_file":0,"pgfault":2112,"pgmajfault":0,"pgpgin":1452,"pgpgout":1452,"rss":270336,"rss_huge":0,"total_active_anon":0,"total_active_file":0,"total_cache":0,"total_dirty":0,"total_inactive_anon":135168,"total_inactive_file":0,"total_mapped_file":0,"total_pgfault":2112,"total_pgmajfault":0,"total_pgpgin":1452,"total_pgpgout":1452,"total_rss":270336,"total_rss_huge":0,"total_unevictable":0,"total_writeback":0,"unevictable":0,"writeback":0},"limit":9223372036854771712},"name":"test_container","id":"a663f01570b14228b0795db9c8d11e16-2785547837","networks":{"eth1":{"rx_bytes":463375353,"rx_packets":310281,"rx_errors":0,"rx_dropped":0,"tx_bytes":250514,"tx_packets":2681,"tx_errors":0,"tx_dropped":0}}}';
110
- // var stats = '{"read":"2025-01-23T04:52:53.853606208Z","preread":"2025-01-23T04:52:43.853359478Z","pids_stats":{},"blkio_stats":{"io_service_bytes_recursive":[],"io_serviced_recursive":[],"io_queue_recursive":[],"io_service_time_recursive":[],"io_wait_time_recursive":[],"io_merged_recursive":[],"io_time_recursive":[],"sectors_recursive":[]},"num_procs":0,"storage_stats":{},"cpu_stats":{"cpu_usage":{"total_usage":8111895890,"percpu_usage":[3973083470,4138812420],"usage_in_kernelmode":2220000000,"usage_in_usermode":5910000000},"system_cpu_usage":1692450000000,"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"precpu_stats":{"cpu_usage":{"total_usage":8023476115,"percpu_usage":[3922781879,4100694236],"usage_in_kernelmode":2180000000,"usage_in_usermode":5820000000},"system_cpu_usage":1672470000000,"online_cpus":2,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"memory_stats":{"usage":66977792,"max_usage":98480128,"stats":{"active_anon":0,"active_file":0,"cache":0,"dirty":0,"hierarchical_memory_limit":4294967296,"hierarchical_memsw_limit":9223372036854771712,"inactive_anon":61906944,"inactive_file":0,"mapped_file":0,"pgfault":463386,"pgmajfault":0,"pgpgin":147477,"pgpgout":132323,"rss":62042112,"rss_huge":0,"total_active_anon":0,"total_active_file":0,"total_cache":0,"total_dirty":0,"total_inactive_anon":61906944,"total_inactive_file":0,"total_mapped_file":0,"total_pgfault":463386,"total_pgmajfault":0,"total_pgpgin":147477,"total_pgpgout":132323,"total_rss":62042112,"total_rss_huge":0,"total_unevictable":0,"total_writeback":0,"unevictable":0,"writeback":0},"limit":9223372036854771712},"name":"test_container","id":"a663f01570b14228b0795db9c8d11e16-2785547837","networks":{"eth1":{"rx_bytes":463489958,"rx_packets":311334,"rx_errors":0,"rx_dropped":0,"tx_bytes":1962223,"tx_packets":4432,"tx_errors":0,"tx_dropped":0}}}'
111
- const o = JSON.parse(stats);
112
-
113
- if (conf.getProperty('debug_aws_ecs_enabled', false)) {
114
- Logger.print("AwsEcsClient", 30, "meta_uri=" + meta_uri + " stats\n" + JSON.stringify(o, null, 4));
115
- }
116
-
117
- const precpu_stats = o.precpu_stats || {};
118
- const cpu_stats = o.cpu_stats || {};
119
- const memory_stats = o.memory_stats || {};
120
-
121
- const system_cpu_usage = delta(precpu_stats, cpu_stats, "system_cpu_usage");
122
-
123
- if (system_cpu_usage > 0) {
124
- const precpu_usage = precpu_stats.cpu_usage || {};
125
- const cpu_usage = cpu_stats.cpu_usage || {};
126
-
127
- const usage_tot = delta(precpu_usage, cpu_usage, "total_usage");
128
- const usage_sys = delta(precpu_usage, cpu_usage, "usage_in_kernelmode");
129
- const usage_usr = delta(precpu_usage, cpu_usage, "usage_in_usermode");
130
-
131
- self.cpu = (usage_tot * 100.0) / system_cpu_usage;
132
- self.cpu_sys = (usage_sys * 100.0) / system_cpu_usage;
133
- self.cpu_user = (usage_usr * 100.0) / system_cpu_usage;
134
- } else {
135
- self.reset();
136
- }
137
-
138
- if (memory_stats) {
139
- const mem_usage = memory_stats.usage || 0;
140
- const memory_stats_stats = memory_stats.stats;
141
-
142
- if (memory_stats_stats) {
143
- const mem_limit = memory_stats_stats.hierarchical_memory_limit || 0;
144
- self.mem_pct = (mem_usage * 100.0) / mem_limit;
145
- } else {
146
- self.mem_pct = 0;
147
- }
148
- } else {
149
- self.mem_pct = 0;
150
- }
151
- })
152
- .catch(error => {
153
- Logger.printError("WHATAP-819", "ECS Process error: " + error, false)
154
- self.reset();
155
- });
156
- };
157
-
158
- AwsEcsClientThread.prototype.reset = function () {
159
- this.cpu = 0;
160
- this.cpu_sys = 0;
161
- this.cpu_user = 0;
162
- };
163
-
164
- // reset 함수 추가
165
- AwsEcsClientThread.prototype.reset = function () {
166
- this.cpu = 0;
167
- this.cpu_sys = 0;
168
- this.cpu_user = 0;
169
- };
170
-
171
- AwsEcsClientThread.CHECK_MAX = 3;
172
-
173
- function read(url, succ, fail) {
174
- http.get(url, function (res) {
175
- var statusCode = res.statusCode;
176
-
177
- if (statusCode !== 200) {
178
- if (fail) fail();
179
-
180
- Logger.printError('WHATAP-999', 'read http call (not 200) ', e, true);
181
- return;
182
- }
183
-
184
- res.setEncoding('utf8');
185
-
186
- var rawData = '';
187
- res.on('data', function (chunk) {
188
- rawData += chunk;
189
- });
190
- res.on('end', function () {
191
- try {
192
- var stats = JSON.parse(rawData);
193
- if (succ) succ(stats);
194
- } catch (e) {
195
- if (fail) fail(e);
196
- Logger.printError('WHATAP-999', 'read http call (not application/json) ', e, true);
197
- }
198
- });
199
- }).on('error', (e) => {
200
- if (fail) fail(e);
201
- Logger.printError('WHATAP-999', 'read http call ', e, true);
202
- });
203
- }
204
-
205
- function delta(j1, j2, key) {
206
- if (!j1 || !j2)
207
- return 0;
208
-
209
- var v1 = j1[key];
210
- var v2 = j2[key];
211
-
212
- if(v1 && v2)
213
- return v2 - v1;
214
- else
215
- return 0;
216
- }
217
-
218
- module.exports = new AwsEcsClientThread();
@@ -1,14 +0,0 @@
1
- var fs = require('fs')
2
- ;
3
-
4
- var LinuxProcStatUtil = {
5
- isLinux: function(){
6
- try{
7
- return fs.existsSync('/proc/stat')
8
- }catch(e){
9
- return false;
10
- }
11
- }
12
- }
13
-
14
- module.exports = LinuxProcStatUtil;
@@ -1,62 +0,0 @@
1
- /**
2
- * Copyright 2016 the WHATAP project authors. All rights reserved.
3
- * Use of this source code is governed by a license that
4
- * can be found in the LICENSE file.
5
- */
6
-
7
- var CounterTask = require('./counter-task'),
8
- MeterUser = require('../meter/meter-users'),
9
- // ResSysCpuPack= require('../../pack/ResSysCpu-pack'),
10
- SystemECSTask = require('./res/systemECSTask'),
11
- SystemKubeTask = require('./res/systemKubeTask'),
12
- ConfSysMon = require('../../conf/conf-sys-mon'),
13
- DataPackSender = require('../../data/datapack-sender'),
14
- Long = require('long');
15
-
16
- function ResSysCpu() {
17
- // this.systype = ConfSysMon.SysType.NONE;
18
- this.update();
19
- }
20
- ResSysCpu.prototype = new CounterTask();
21
- ResSysCpu.prototype.constructor = ResSysCpu;
22
- ResSysCpu.prototype.process = function (p) {
23
-
24
- this.init();
25
-
26
- if(this.sysmon) this.sysmon.process(p);
27
- };
28
-
29
- ResSysCpu.prototype.init = function () {
30
- // // WatchDog을 시작시킴
31
- // if (ConfWatchLog.watchlog_enabled) {
32
- // WatchLogManager.getInstance();
33
- // GcWatchManager.getInstance();
34
- // }
35
- // if (conf.WHATAP_MICRO_ENABLED) {
36
- // KubeClient.getInstance();
37
- // }
38
- // if (ConfSysMon.aws_ecs_enabled) {
39
- // AwsEcsClientThread.getInstance();
40
- // }
41
- }
42
-
43
- ResSysCpu.prototype.update = function () {
44
- var thisType = ConfSysMon.findType();
45
-
46
- if (this.systype == thisType)
47
- return;
48
- this.systype = thisType;
49
-
50
- switch (thisType) {
51
- case ConfSysMon.SysType.ECS:
52
- this.sysmon = new SystemECSTask();
53
- Logger.print('WHATAP SysCpu ' , "System CPU collected by 'ECS' task", undefined , true);
54
- break;
55
- case ConfSysMon.SysType.KUBE:
56
- this.sysmon = new SystemKubeTask();
57
- Logger.print('WHATAP SysCpu ' , "System CPU collected by 'KUBE", undefined , true);
58
- break;
59
- }
60
- }
61
-
62
- module.exports = ResSysCpu;