badmfck-api-server 4.1.52 → 4.1.57
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/dist/apiServer/APIService.d.ts +3 -4
- package/dist/apiServer/APIService.js +19 -9
- package/dist/apiServer/BaseEndpoint.d.ts +2 -2
- package/dist/apiServer/LocalRequest.d.ts +1 -1
- package/dist/apiServer/LogService.js +17 -7
- package/dist/apiServer/MonitorService.d.ts +0 -1
- package/dist/apiServer/MonitorService.js +17 -7
- package/dist/apiServer/MysqlService.d.ts +1 -2
- package/dist/apiServer/MysqlService.js +17 -7
- package/dist/apiServer/TimeframeService.js +17 -7
- package/dist/apiServer/db/MysqlAdapter.d.ts +1 -1
- package/dist/apiServer/db/MysqlAdapter.js +37 -12
- package/dist/apiServer/deployment/Activate.d.ts +3 -9
- package/dist/apiServer/deployment/Activate.js +3 -13
- package/dist/apiServer/deployment/ConfigService.d.ts +26 -26
- package/dist/apiServer/deployment/ConfigService.js +17 -7
- package/dist/apiServer/deployment/Deploy.d.ts +2 -9
- package/dist/apiServer/deployment/Deploy.js +3 -97
- package/dist/apiServer/deployment/DeployerService.d.ts +9 -9
- package/dist/apiServer/deployment/cli.d.ts +2 -0
- package/dist/apiServer/deployment/cli.js +63 -0
- package/dist/apiServer/deployment/resolveConfig.d.ts +12 -0
- package/dist/apiServer/deployment/resolveConfig.js +104 -0
- package/dist/apiServer/documentation/index.html +25 -25
- package/dist/apiServer/external/ExternalService.js +17 -7
- package/dist/apiServer/external/MicroserviceClient.js +17 -7
- package/dist/apiServer/external/MicroserviceHost.js +17 -7
- package/dist/apiServer/external/MicroserviceHostController.js +17 -7
- package/dist/apiServer/helper/JSONStableStringify.js +1 -2
- package/dist/apiServer/helper/YYYYMMDDHH.js +2 -3
- package/dist/apiServer/helper/ZipUtils.d.ts +0 -2
- package/dist/apiServer/monitor/Monitor.d.ts +1 -0
- package/dist/apiServer/monitor/Monitor.js +5 -0
- package/dist/apiServer/monitor/ProcessMonitor.d.ts +45 -1
- package/dist/apiServer/monitor/ProcessMonitor.js +147 -0
- package/dist/apiServer/monitor/SystemInfo.d.ts +7 -8
- package/dist/apiServer/monitor/SystemInfo.js +1 -2
- package/dist/apiServer/monitor/index.html +54 -54
- package/dist/apiServer/structures/Interfaces.d.ts +0 -1
- package/package.json +5 -2
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.MicroserviceHostController = void 0;
|
|
27
37
|
const BaseEndpoint_1 = require("../BaseEndpoint");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSONStableStringify =
|
|
3
|
+
exports.JSONStableStringify = JSONStableStringify;
|
|
4
4
|
function JSONStableStringify(obj) {
|
|
5
5
|
if (obj === null || typeof obj !== "object") {
|
|
6
6
|
return JSON.stringify(obj);
|
|
@@ -13,4 +13,3 @@ function JSONStableStringify(obj) {
|
|
|
13
13
|
keys.map(k => JSON.stringify(k) + ":" + JSONStableStringify(obj[k])).join(",") +
|
|
14
14
|
"}");
|
|
15
15
|
}
|
|
16
|
-
exports.JSONStableStringify = JSONStableStringify;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.YYYYMMDDHH = YYYYMMDDHH;
|
|
4
|
+
exports.YYYYMMDDHH_toDate = YYYYMMDDHH_toDate;
|
|
4
5
|
function YYYYMMDDHH(date, format = "yyyymmddhh") {
|
|
5
6
|
const year = date.getFullYear();
|
|
6
7
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
@@ -20,7 +21,6 @@ function YYYYMMDDHH(date, format = "yyyymmddhh") {
|
|
|
20
21
|
return `${year}${month}${day}${hours}`;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
exports.YYYYMMDDHH = YYYYMMDDHH;
|
|
24
24
|
function YYYYMMDDHH_toDate(yyyymmddhh) {
|
|
25
25
|
const str = String(yyyymmddhh);
|
|
26
26
|
const year = parseInt(str.slice(0, 4), 10);
|
|
@@ -29,4 +29,3 @@ function YYYYMMDDHH_toDate(yyyymmddhh) {
|
|
|
29
29
|
const hours = parseInt(str.slice(8, 10), 10);
|
|
30
30
|
return new Date(year, month, day, hours);
|
|
31
31
|
}
|
|
32
|
-
exports.YYYYMMDDHH_toDate = YYYYMMDDHH_toDate;
|
|
@@ -23,6 +23,7 @@ export declare class Monitor extends BaseEndpoint {
|
|
|
23
23
|
outgoingNetlog(req: HTTPRequestVO): Promise<TransferPacketVO>;
|
|
24
24
|
sysinfo(req: HTTPRequestVO): Promise<TransferPacketVO>;
|
|
25
25
|
procinfo(req: HTTPRequestVO): Promise<TransferPacketVO>;
|
|
26
|
+
fdreport(req: HTTPRequestVO): Promise<TransferPacketVO>;
|
|
26
27
|
httpstats(req: HTTPRequestVO): Promise<TransferPacketVO>;
|
|
27
28
|
inventory(req: HTTPRequestVO): Promise<TransferPacketVO>;
|
|
28
29
|
metrics(req: HTTPRequestVO): Promise<TransferPacketVO>;
|
|
@@ -45,6 +45,7 @@ class Monitor extends BaseEndpoint_1.BaseEndpoint {
|
|
|
45
45
|
{ ignoreInterceptor: true, endpoint: "outgoingnetlog", handler: this.outgoingNetlog },
|
|
46
46
|
{ ignoreInterceptor: true, endpoint: "sysinfo", handler: this.sysinfo },
|
|
47
47
|
{ ignoreInterceptor: true, endpoint: "procinfo", handler: this.procinfo },
|
|
48
|
+
{ ignoreInterceptor: true, endpoint: "fdreport", handler: this.fdreport },
|
|
48
49
|
{ ignoreInterceptor: true, endpoint: "inventory", handler: this.inventory },
|
|
49
50
|
{ ignoreInterceptor: true, endpoint: "httpstats", handler: this.httpstats },
|
|
50
51
|
{ ignoreInterceptor: true, endpoint: "metrics", handler: this.metrics, validationModel: {
|
|
@@ -140,6 +141,10 @@ class Monitor extends BaseEndpoint_1.BaseEndpoint {
|
|
|
140
141
|
await this.checkAuthentication(req);
|
|
141
142
|
return { data: await ProcessMonitor_1.ProcessMonitor.getSnapshot() };
|
|
142
143
|
}
|
|
144
|
+
async fdreport(req) {
|
|
145
|
+
await this.checkAuthentication(req);
|
|
146
|
+
return { data: await ProcessMonitor_1.ProcessMonitor.getFdReport() };
|
|
147
|
+
}
|
|
143
148
|
async httpstats(req) {
|
|
144
149
|
await this.checkAuthentication(req);
|
|
145
150
|
return { data: Http_1.Http.getHttpStats() };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
export declare class ProcessMonitor {
|
|
3
2
|
private static _inited;
|
|
4
3
|
private static _eld;
|
|
@@ -10,7 +9,11 @@ export declare class ProcessMonitor {
|
|
|
10
9
|
private static _eluPrev;
|
|
11
10
|
private static _elu;
|
|
12
11
|
private static _processStartedAt;
|
|
12
|
+
private static _fdHistory;
|
|
13
|
+
private static _fdHistoryMax;
|
|
14
|
+
private static _fdSampleEveryMs;
|
|
13
15
|
static init(): void;
|
|
16
|
+
private static _sampleFdSeries;
|
|
14
17
|
private static _sampleCpu;
|
|
15
18
|
private static _sampleELU;
|
|
16
19
|
private static _mapGcKind;
|
|
@@ -99,6 +102,14 @@ export declare class ProcessMonitor {
|
|
|
99
102
|
limitSoft: number | null;
|
|
100
103
|
limitHard: number | null;
|
|
101
104
|
};
|
|
105
|
+
sockets: {
|
|
106
|
+
total: number;
|
|
107
|
+
byState: Record<string, number>;
|
|
108
|
+
topRemotes: Array<{
|
|
109
|
+
host: string;
|
|
110
|
+
established: number;
|
|
111
|
+
}>;
|
|
112
|
+
} | null;
|
|
102
113
|
io: Record<string, number> | null;
|
|
103
114
|
limits: Record<string, {
|
|
104
115
|
soft: string;
|
|
@@ -106,10 +117,43 @@ export declare class ProcessMonitor {
|
|
|
106
117
|
unit: string;
|
|
107
118
|
}> | null;
|
|
108
119
|
}>;
|
|
120
|
+
static getFdReport(): Promise<{
|
|
121
|
+
now: {
|
|
122
|
+
ts: number;
|
|
123
|
+
fdOpen: number | null;
|
|
124
|
+
limitSoft: number | null;
|
|
125
|
+
limitHard: number | null;
|
|
126
|
+
sockets: {
|
|
127
|
+
total: number;
|
|
128
|
+
byState: Record<string, number>;
|
|
129
|
+
topRemotes: Array<{
|
|
130
|
+
host: string;
|
|
131
|
+
established: number;
|
|
132
|
+
}>;
|
|
133
|
+
} | null;
|
|
134
|
+
};
|
|
135
|
+
sampleEveryMs: number;
|
|
136
|
+
historyMax: number;
|
|
137
|
+
history: {
|
|
138
|
+
ts: number;
|
|
139
|
+
fdOpen: number | null;
|
|
140
|
+
fdSoftLimit: number | null;
|
|
141
|
+
socketTotal: number | null;
|
|
142
|
+
byState: Record<string, number>;
|
|
143
|
+
topRemote: {
|
|
144
|
+
host: string;
|
|
145
|
+
established: number;
|
|
146
|
+
} | null;
|
|
147
|
+
rss: number;
|
|
148
|
+
}[];
|
|
149
|
+
}>;
|
|
109
150
|
private static _readProcStatus;
|
|
110
151
|
private static _readProcIo;
|
|
111
152
|
private static _readProcLimits;
|
|
112
153
|
private static _countFds;
|
|
154
|
+
private static _readSocketBreakdown;
|
|
155
|
+
private static _tcpState;
|
|
156
|
+
private static _parseHexAddr;
|
|
113
157
|
private static _parseLimitValue;
|
|
114
158
|
private static _toMsFinite;
|
|
115
159
|
private static _safePercentileMs;
|
|
@@ -25,6 +25,9 @@ class ProcessMonitor {
|
|
|
25
25
|
static _eluPrev = perf_hooks_1.performance.eventLoopUtilization();
|
|
26
26
|
static _elu = { idle: 0, active: 0, utilizationPct: 0 };
|
|
27
27
|
static _processStartedAt = Date.now() - process.uptime() * 1000;
|
|
28
|
+
static _fdHistory = [];
|
|
29
|
+
static _fdHistoryMax = 300;
|
|
30
|
+
static _fdSampleEveryMs = Math.max(1, parseInt(process.env.MONITOR_FD_SAMPLE_MINUTES || "10", 10) || 10) * 60 * 1000;
|
|
28
31
|
static init() {
|
|
29
32
|
if (this._inited)
|
|
30
33
|
return;
|
|
@@ -62,6 +65,28 @@ class ProcessMonitor {
|
|
|
62
65
|
const eluTimer = setInterval(() => this._sampleELU(), 5000);
|
|
63
66
|
if (eluTimer.unref)
|
|
64
67
|
eluTimer.unref();
|
|
68
|
+
this._sampleFdSeries().catch(() => { });
|
|
69
|
+
const fdTimer = setInterval(() => this._sampleFdSeries().catch(() => { }), this._fdSampleEveryMs);
|
|
70
|
+
if (fdTimer.unref)
|
|
71
|
+
fdTimer.unref();
|
|
72
|
+
}
|
|
73
|
+
static async _sampleFdSeries() {
|
|
74
|
+
const fdOpen = await this._countFds();
|
|
75
|
+
const sockets = await this._readSocketBreakdown();
|
|
76
|
+
const limits = await this._readProcLimits();
|
|
77
|
+
const softRaw = limits?.["Max open files"]?.soft;
|
|
78
|
+
const mem = process.memoryUsage();
|
|
79
|
+
this._fdHistory.push({
|
|
80
|
+
ts: Date.now(),
|
|
81
|
+
fdOpen,
|
|
82
|
+
fdSoftLimit: softRaw ? this._parseLimitValue(softRaw) : null,
|
|
83
|
+
socketTotal: sockets ? sockets.total : null,
|
|
84
|
+
byState: sockets ? sockets.byState : {},
|
|
85
|
+
topRemote: sockets && sockets.topRemotes.length > 0 ? sockets.topRemotes[0] : null,
|
|
86
|
+
rss: mem.rss,
|
|
87
|
+
});
|
|
88
|
+
if (this._fdHistory.length > this._fdHistoryMax)
|
|
89
|
+
this._fdHistory.shift();
|
|
65
90
|
}
|
|
66
91
|
static _sampleCpu() {
|
|
67
92
|
const now = process.cpuUsage();
|
|
@@ -137,6 +162,7 @@ class ProcessMonitor {
|
|
|
137
162
|
const fdOpen = await this._countFds();
|
|
138
163
|
const fdSoft = limitsParsed?.["Max open files"]?.soft;
|
|
139
164
|
const fdHard = limitsParsed?.["Max open files"]?.hard;
|
|
165
|
+
const sockets = await this._readSocketBreakdown();
|
|
140
166
|
const h = this._eld;
|
|
141
167
|
const eventLoop = h ? {
|
|
142
168
|
minMs: this._toMsFinite(h.min),
|
|
@@ -212,10 +238,32 @@ class ProcessMonitor {
|
|
|
212
238
|
limitSoft: fdSoft ? this._parseLimitValue(fdSoft) : null,
|
|
213
239
|
limitHard: fdHard ? this._parseLimitValue(fdHard) : null,
|
|
214
240
|
},
|
|
241
|
+
sockets,
|
|
215
242
|
io,
|
|
216
243
|
limits: limitsParsed,
|
|
217
244
|
};
|
|
218
245
|
}
|
|
246
|
+
static async getFdReport() {
|
|
247
|
+
const [sockets, limits, fdOpen] = await Promise.all([
|
|
248
|
+
this._readSocketBreakdown(),
|
|
249
|
+
this._readProcLimits(),
|
|
250
|
+
this._countFds(),
|
|
251
|
+
]);
|
|
252
|
+
const softRaw = limits?.["Max open files"]?.soft;
|
|
253
|
+
const hardRaw = limits?.["Max open files"]?.hard;
|
|
254
|
+
return {
|
|
255
|
+
now: {
|
|
256
|
+
ts: Date.now(),
|
|
257
|
+
fdOpen,
|
|
258
|
+
limitSoft: softRaw ? this._parseLimitValue(softRaw) : null,
|
|
259
|
+
limitHard: hardRaw ? this._parseLimitValue(hardRaw) : null,
|
|
260
|
+
sockets,
|
|
261
|
+
},
|
|
262
|
+
sampleEveryMs: this._fdSampleEveryMs,
|
|
263
|
+
historyMax: this._fdHistoryMax,
|
|
264
|
+
history: this._fdHistory,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
219
267
|
static async _readProcStatus() {
|
|
220
268
|
try {
|
|
221
269
|
const txt = await promises_1.default.readFile(`/proc/${process.pid}/status`, "utf-8");
|
|
@@ -278,6 +326,105 @@ class ProcessMonitor {
|
|
|
278
326
|
return null;
|
|
279
327
|
}
|
|
280
328
|
}
|
|
329
|
+
static async _readSocketBreakdown() {
|
|
330
|
+
try {
|
|
331
|
+
const fdDir = `/proc/${process.pid}/fd`;
|
|
332
|
+
const fds = await promises_1.default.readdir(fdDir);
|
|
333
|
+
const inodes = new Set();
|
|
334
|
+
await Promise.all(fds.map(async (fd) => {
|
|
335
|
+
try {
|
|
336
|
+
const link = await promises_1.default.readlink(`${fdDir}/${fd}`);
|
|
337
|
+
const m = link.match(/^socket:\[(\d+)\]$/);
|
|
338
|
+
if (m)
|
|
339
|
+
inodes.add(m[1]);
|
|
340
|
+
}
|
|
341
|
+
catch { }
|
|
342
|
+
}));
|
|
343
|
+
if (inodes.size === 0)
|
|
344
|
+
return { total: 0, byState: {}, topRemotes: [] };
|
|
345
|
+
const byState = {};
|
|
346
|
+
const remoteEstab = {};
|
|
347
|
+
let total = 0;
|
|
348
|
+
for (const [file, isV6] of [["/proc/net/tcp", false], ["/proc/net/tcp6", true]]) {
|
|
349
|
+
let txt;
|
|
350
|
+
try {
|
|
351
|
+
txt = await promises_1.default.readFile(file, "utf-8");
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
for (const line of txt.split("\n").slice(1)) {
|
|
357
|
+
const parts = line.trim().split(/\s+/);
|
|
358
|
+
if (parts.length < 10)
|
|
359
|
+
continue;
|
|
360
|
+
const inode = parts[9];
|
|
361
|
+
if (!inodes.has(inode))
|
|
362
|
+
continue;
|
|
363
|
+
total++;
|
|
364
|
+
const state = this._tcpState(parts[3]);
|
|
365
|
+
byState[state] = (byState[state] ?? 0) + 1;
|
|
366
|
+
if (state === "ESTABLISHED") {
|
|
367
|
+
const host = this._parseHexAddr((parts[2] ?? "").split(":")[0], isV6);
|
|
368
|
+
remoteEstab[host] = (remoteEstab[host] ?? 0) + 1;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
const topRemotes = Object.entries(remoteEstab)
|
|
373
|
+
.map(([host, established]) => ({ host, established }))
|
|
374
|
+
.sort((a, b) => b.established - a.established)
|
|
375
|
+
.slice(0, 10);
|
|
376
|
+
return { total, byState, topRemotes };
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
static _tcpState(hex) {
|
|
383
|
+
switch ((hex || "").toUpperCase()) {
|
|
384
|
+
case "01": return "ESTABLISHED";
|
|
385
|
+
case "02": return "SYN_SENT";
|
|
386
|
+
case "03": return "SYN_RECV";
|
|
387
|
+
case "04": return "FIN_WAIT1";
|
|
388
|
+
case "05": return "FIN_WAIT2";
|
|
389
|
+
case "06": return "TIME_WAIT";
|
|
390
|
+
case "07": return "CLOSE";
|
|
391
|
+
case "08": return "CLOSE_WAIT";
|
|
392
|
+
case "09": return "LAST_ACK";
|
|
393
|
+
case "0A": return "LISTEN";
|
|
394
|
+
case "0B": return "CLOSING";
|
|
395
|
+
case "0C": return "NEW_SYN_RECV";
|
|
396
|
+
default: return "UNKNOWN(" + hex + ")";
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
static _parseHexAddr(hex, isV6) {
|
|
400
|
+
try {
|
|
401
|
+
if (!isV6) {
|
|
402
|
+
if (hex.length !== 8)
|
|
403
|
+
return hex;
|
|
404
|
+
return [
|
|
405
|
+
parseInt(hex.slice(6, 8), 16),
|
|
406
|
+
parseInt(hex.slice(4, 6), 16),
|
|
407
|
+
parseInt(hex.slice(2, 4), 16),
|
|
408
|
+
parseInt(hex.slice(0, 2), 16),
|
|
409
|
+
].join(".");
|
|
410
|
+
}
|
|
411
|
+
if (hex.length !== 32)
|
|
412
|
+
return hex;
|
|
413
|
+
const bytes = [];
|
|
414
|
+
for (let w = 0; w < 4; w++) {
|
|
415
|
+
const word = hex.slice(w * 8, w * 8 + 8);
|
|
416
|
+
for (let b = 3; b >= 0; b--)
|
|
417
|
+
bytes.push(parseInt(word.slice(b * 2, b * 2 + 2), 16));
|
|
418
|
+
}
|
|
419
|
+
const hextets = [];
|
|
420
|
+
for (let i = 0; i < 16; i += 2)
|
|
421
|
+
hextets.push((((bytes[i] << 8) | bytes[i + 1]) >>> 0).toString(16));
|
|
422
|
+
return hextets.join(":");
|
|
423
|
+
}
|
|
424
|
+
catch {
|
|
425
|
+
return hex;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
281
428
|
static _parseLimitValue(v) {
|
|
282
429
|
if (v === "unlimited")
|
|
283
430
|
return -1;
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
export declare function collectSystemInfo(): Promise<{
|
|
3
2
|
cpu: {
|
|
4
|
-
usage: {
|
|
5
|
-
userPct: number;
|
|
6
|
-
systemPct: number;
|
|
7
|
-
idlePct: number;
|
|
8
|
-
iowaitPct: number;
|
|
9
|
-
} | null;
|
|
10
3
|
count: number;
|
|
11
4
|
models: Record<string, number>;
|
|
12
5
|
loadAvg: number[];
|
|
13
6
|
platform: NodeJS.Platform;
|
|
14
7
|
arch: NodeJS.Architecture;
|
|
15
8
|
uptimeSec: number;
|
|
9
|
+
usage: {
|
|
10
|
+
userPct: number;
|
|
11
|
+
systemPct: number;
|
|
12
|
+
idlePct: number;
|
|
13
|
+
iowaitPct: number;
|
|
14
|
+
} | null;
|
|
16
15
|
};
|
|
17
16
|
memory: {
|
|
18
17
|
total: number;
|
|
@@ -61,9 +60,9 @@ export declare function collectSystemInfo(): Promise<{
|
|
|
61
60
|
error: string;
|
|
62
61
|
processes?: undefined;
|
|
63
62
|
} | {
|
|
63
|
+
error?: undefined;
|
|
64
64
|
installed: boolean;
|
|
65
65
|
processes: any;
|
|
66
|
-
error?: undefined;
|
|
67
66
|
} | {
|
|
68
67
|
installed: boolean;
|
|
69
68
|
error: string;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.collectSystemInfo =
|
|
6
|
+
exports.collectSystemInfo = collectSystemInfo;
|
|
7
7
|
const os_1 = __importDefault(require("os"));
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
9
|
const util_1 = require("util");
|
|
@@ -215,4 +215,3 @@ async function collectSystemInfo() {
|
|
|
215
215
|
pm2: pm2Data,
|
|
216
216
|
};
|
|
217
217
|
}
|
|
218
|
-
exports.collectSystemInfo = collectSystemInfo;
|