whatap 0.5.11 → 0.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/conf/config-default.js +2 -0
- package/lib/core/agent.js +4 -1
- package/lib/counter/counter-manager.js +4 -0
- package/lib/counter/task/metering-info.js +118 -0
- package/lib/observers/http-observer.js +1 -0
- package/lib/observers/oracle-observer.js +656 -0
- package/lib/observers/prisma-observer.js +20 -269
- package/lib/observers/socket.io-observer.js +213 -74
- package/lib/observers/websocket-observer.js +164 -67
- package/lib/pack/apenum.js +8 -0
- package/lib/pack/otype.js +7 -0
- package/lib/pack/tagcount-pack.js +51 -50
- package/lib/util/dateutil.js +33 -1
- package/lib/util/escape-literal-sql.js +5 -5
- package/package.json +2 -2
|
@@ -275,6 +275,8 @@ var ConfigDefault = {
|
|
|
275
275
|
|
|
276
276
|
"prisma_read_func_name": str("prisma_read_func_name", "read"),
|
|
277
277
|
"prisma_database_url_name": str("prisma_database_url_name", "DATABASE_URL"),
|
|
278
|
+
|
|
279
|
+
"metering_tagcount_enabled": bool("metering_tagcount_enabled", false)
|
|
278
280
|
};
|
|
279
281
|
|
|
280
282
|
ConfigDefault._hook_method_ignore_prefix = ConfigDefault.hook_method_ignore_prefixes.split(',');
|
package/lib/core/agent.js
CHANGED
|
@@ -32,7 +32,9 @@ var Interceptor = require('./interceptor').Interceptor,
|
|
|
32
32
|
ScheduleObserver = require('../observers/schedule-observer').ScheduleObserver,
|
|
33
33
|
// GRpcObserver = require('../observers/grpc-observer').GRpcObserver,
|
|
34
34
|
ApolloObserver = require('../observers/apollo-server-observer').ApolloServerObserver,
|
|
35
|
-
PrismaObserver = require('../observers/prisma-observer').PrismaObserver
|
|
35
|
+
PrismaObserver = require('../observers/prisma-observer').PrismaObserver,
|
|
36
|
+
OracleObserver = require('../observers/oracle-observer').OracleObserver;
|
|
37
|
+
|
|
36
38
|
|
|
37
39
|
|
|
38
40
|
var Configuration = require('./../conf/configure'),
|
|
@@ -279,6 +281,7 @@ NodeAgent.prototype.loadObserves = function() {
|
|
|
279
281
|
// observes.push(GRpcObserver);
|
|
280
282
|
observes.push(ApolloObserver);
|
|
281
283
|
observes.push(PrismaObserver);
|
|
284
|
+
observes.push(OracleObserver);
|
|
282
285
|
|
|
283
286
|
var packageToObserve = {};
|
|
284
287
|
observes.forEach(function(observeObj) {
|
|
@@ -17,6 +17,7 @@ var CounterPack = require('../pack/counter-pack'),
|
|
|
17
17
|
GCStat = require('./task/gcstat'),
|
|
18
18
|
Sql = require('./task/sql'),
|
|
19
19
|
HttpC = require('./task/httpc'),
|
|
20
|
+
// MeteringInfo = require('./task/metering-info'),
|
|
20
21
|
StatError = require('../stat/stat-error'),
|
|
21
22
|
TagCounterPack = require('../pack/tagcount-pack'),
|
|
22
23
|
TraceContextManager = require('../trace/trace-context-manager'),
|
|
@@ -52,6 +53,9 @@ CounterManager.prototype.run = function () {
|
|
|
52
53
|
tasks.push(new GCStat());
|
|
53
54
|
tasks.push(new Sql());
|
|
54
55
|
tasks.push(new HttpC());
|
|
56
|
+
|
|
57
|
+
// metering
|
|
58
|
+
// tasks.push(new MeteringInfo());
|
|
55
59
|
self.intervalIndex = setInterval(function(){
|
|
56
60
|
self.process(tasks);
|
|
57
61
|
},5000);
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
|
|
17
|
+
function MeteringInfo() {
|
|
18
|
+
CounterTask.call(this);
|
|
19
|
+
this.first_connected = true;
|
|
20
|
+
this.lastTime = DateUtil.getFiveMinUnit(DateUtil.currentTime());
|
|
21
|
+
this.hostUUID = null;
|
|
22
|
+
this.csp = null;
|
|
23
|
+
this.hostUUIDFileName = '/sys/class/dmi/id/product_uuid';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
MeteringInfo.prototype = new CounterTask();
|
|
27
|
+
MeteringInfo.prototype.constructor = MeteringInfo;
|
|
28
|
+
|
|
29
|
+
MeteringInfo.prototype.process = function (p) {
|
|
30
|
+
if (!conf.getProperty('metering_tagcount_enabled', false)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (this.first_connected) {
|
|
35
|
+
this.first_connected = false;
|
|
36
|
+
this.doProcess(p);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const now = DateUtil.getFiveMinUnit(DateUtil.currentTime());
|
|
41
|
+
if (this.lastTime >= now) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
this.lastTime = now;
|
|
46
|
+
this.doProcess(p);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
MeteringInfo.prototype.doProcess = function (p) {
|
|
50
|
+
const pk = new TagCountPack();
|
|
51
|
+
pk.category = 'metering';
|
|
52
|
+
pk.time = DateUtil.currentTime() / 300000 * 300000;
|
|
53
|
+
|
|
54
|
+
pk.putTagInt('otype', OType.AP);
|
|
55
|
+
pk.putTagInt('subtype', APEnum.AP_NODE);
|
|
56
|
+
pk.putTagInt('ip', p.host_ip);
|
|
57
|
+
|
|
58
|
+
const host_uuid = this.getHostUUID(this.hostUUIDFileName);
|
|
59
|
+
if (host_uuid) {
|
|
60
|
+
pk.putTagString('host_uuid', host_uuid);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const csp = this.getCsp();
|
|
64
|
+
if (csp) {
|
|
65
|
+
pk.putTagString('csp', csp)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
pk.putTagFloat(p.metering)
|
|
69
|
+
|
|
70
|
+
DataPackSender.sendTagCounterPack(pk);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
MeteringInfo.prototype.hasHostUUID = function (fileName) {
|
|
74
|
+
try{
|
|
75
|
+
return fs.existsSync(fileName);
|
|
76
|
+
}catch (e) {
|
|
77
|
+
Logger.printError("WHATAP-081", "hasHostUUID error", e, false);
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
MeteringInfo.prototype.getHostUUID = function (fileName) {
|
|
83
|
+
const hostUUID = this.getHostUUIDValue();
|
|
84
|
+
if (hostUUID) {
|
|
85
|
+
return hostUUID;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const hasHostUUIDFile = this.hasHostUUID(fileName);
|
|
89
|
+
if (hasHostUUIDFile) {
|
|
90
|
+
try {
|
|
91
|
+
const data = fs.readFileSync(fileName);
|
|
92
|
+
|
|
93
|
+
if (data && data.length > 0) {
|
|
94
|
+
this.hostUUID = data.toString().trim();
|
|
95
|
+
return this.hostUUID;
|
|
96
|
+
} else {
|
|
97
|
+
Logger.print('WHATAP-082', 'cannot read /sys/class/dmi/id/product_uuid', false);
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
Logger.printError('WHATAP-083', 'error reading /sys/class/dmi/id/product_uuid ', error, false);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
Logger.print('WHATAP-084', 'cannot find /sys/class/dmi/id/product_uuid', false);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return null;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
MeteringInfo.prototype.getHostUUIDValue = function () {
|
|
110
|
+
return this.hostUUID;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
MeteringInfo.prototype.getCsp = function () {
|
|
114
|
+
|
|
115
|
+
return null;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
module.exports = MeteringInfo;
|
|
@@ -513,6 +513,7 @@ HttpObserver.prototype.__endTransaction = function(error, ctx, req, res) {
|
|
|
513
513
|
if(wtx.malloc < 0) { wtx.malloc = 0; }
|
|
514
514
|
wtx.originUrl = ctx.originUrl;
|
|
515
515
|
|
|
516
|
+
wtx.cipher = HashUtil.hash(ParamSecurity.key);
|
|
516
517
|
wtx.seq = ctx.txid;
|
|
517
518
|
wtx.sqlCount = ctx.sql_count;
|
|
518
519
|
wtx.sqlTime = ctx.sql_time;
|