matterbridge 3.5.0-dev-20260119-f9ea00e → 3.5.1-dev-20260121-22e98b4
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/CHANGELOG.md +133 -117
- package/bin/mb_coap.js +1 -1
- package/bin/mb_mdns.js +1 -1
- package/dist/broadcastServer.js +1 -2
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +1 -5
- package/dist/cliHistory.js +1 -1
- package/dist/deviceManager.js +1 -1
- package/dist/frontend.js +2 -7
- package/dist/helpers.js +1 -1
- package/dist/matterNode.js +1 -5
- package/dist/matterbridge.js +14 -18
- package/dist/matterbridgeEndpoint.d.ts +2 -0
- package/dist/matterbridgeEndpoint.js +41 -2
- package/dist/matterbridgeEndpointHelpers.js +1 -3
- package/dist/matterbridgePlatform.js +1 -2
- package/dist/{dgram/mb_mdns.js → mb_mdns.js} +13 -1
- package/dist/pluginManager.js +3 -4
- package/dist/{utils/spawn.js → spawn.js} +2 -2
- package/dist/update.js +6 -7
- package/dist/utils/export.d.ts +1 -12
- package/dist/utils/export.js +1 -12
- package/dist/workerGlobalPrefix.js +1 -3
- package/frontend/build/assets/index.js +4 -4
- package/frontend/package.json +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +5 -5
- package/dist/dgram/coap.d.ts +0 -34
- package/dist/dgram/coap.js +0 -252
- package/dist/dgram/dgram.d.ts +0 -45
- package/dist/dgram/dgram.js +0 -251
- package/dist/dgram/mdns.d.ts +0 -188
- package/dist/dgram/mdns.js +0 -702
- package/dist/dgram/multicast.d.ts +0 -18
- package/dist/dgram/multicast.js +0 -118
- package/dist/dgram/unicast.d.ts +0 -11
- package/dist/dgram/unicast.js +0 -40
- package/dist/utils/colorUtils.d.ts +0 -24
- package/dist/utils/colorUtils.js +0 -187
- package/dist/utils/commandLine.d.ts +0 -6
- package/dist/utils/commandLine.js +0 -63
- package/dist/utils/copyDirectory.d.ts +0 -2
- package/dist/utils/copyDirectory.js +0 -39
- package/dist/utils/createDirectory.d.ts +0 -2
- package/dist/utils/createDirectory.js +0 -21
- package/dist/utils/createZip.d.ts +0 -1
- package/dist/utils/createZip.js +0 -69
- package/dist/utils/deepCopy.d.ts +0 -1
- package/dist/utils/deepCopy.js +0 -40
- package/dist/utils/deepEqual.d.ts +0 -1
- package/dist/utils/deepEqual.js +0 -58
- package/dist/utils/error.d.ts +0 -3
- package/dist/utils/error.js +0 -12
- package/dist/utils/format.d.ts +0 -4
- package/dist/utils/format.js +0 -29
- package/dist/utils/hex.d.ts +0 -4
- package/dist/utils/hex.js +0 -118
- package/dist/utils/inspector.d.ts +0 -24
- package/dist/utils/inspector.js +0 -200
- package/dist/utils/isValid.d.ts +0 -10
- package/dist/utils/isValid.js +0 -69
- package/dist/utils/network.d.ts +0 -25
- package/dist/utils/network.js +0 -193
- package/dist/utils/tracker.d.ts +0 -52
- package/dist/utils/tracker.js +0 -201
- package/dist/utils/wait.d.ts +0 -3
- package/dist/utils/wait.js +0 -73
- /package/dist/{dgram/mb_coap.d.ts → mb_coap.d.ts} +0 -0
- /package/dist/{dgram/mb_coap.js → mb_coap.js} +0 -0
- /package/dist/{dgram/mb_mdns.d.ts → mb_mdns.d.ts} +0 -0
- /package/dist/{utils/spawn.d.ts → spawn.d.ts} +0 -0
package/dist/utils/network.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import { AnsiLogger, BLUE, CYAN, nf } from 'node-ansi-logger';
|
|
3
|
-
export function getInterfaceDetails() {
|
|
4
|
-
const result = { interfaceName: '', ipv4Address: undefined, ipv6Address: undefined, macAddress: undefined };
|
|
5
|
-
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
6
|
-
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
7
|
-
continue;
|
|
8
|
-
for (const detail of interfaceDetails) {
|
|
9
|
-
if (detail.internal)
|
|
10
|
-
continue;
|
|
11
|
-
if (!result.interfaceName)
|
|
12
|
-
result.interfaceName = interfaceName;
|
|
13
|
-
if (interfaceName === result.interfaceName && !result.ipv4Address && detail.family === 'IPv4')
|
|
14
|
-
result.ipv4Address = detail.address;
|
|
15
|
-
if (interfaceName === result.interfaceName && !result.ipv6Address && detail.family === 'IPv6')
|
|
16
|
-
result.ipv6Address = detail.address;
|
|
17
|
-
if (interfaceName === result.interfaceName && !result.macAddress)
|
|
18
|
-
result.macAddress = detail.mac;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
if (result.interfaceName)
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
export function getInterfaceName() {
|
|
25
|
-
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
26
|
-
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
27
|
-
continue;
|
|
28
|
-
for (const detail of interfaceDetails) {
|
|
29
|
-
if (!detail.internal)
|
|
30
|
-
return interfaceName;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
export function getIpv4InterfaceAddress() {
|
|
35
|
-
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
36
|
-
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
37
|
-
continue;
|
|
38
|
-
for (const detail of interfaceDetails) {
|
|
39
|
-
if (detail.family === 'IPv4' && !detail.internal)
|
|
40
|
-
return detail.address;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export function getIpv6InterfaceAddress(scope = false) {
|
|
45
|
-
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
46
|
-
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
47
|
-
continue;
|
|
48
|
-
for (const detail of interfaceDetails) {
|
|
49
|
-
if (detail.family === 'IPv6' && !detail.internal) {
|
|
50
|
-
const address = detail.address;
|
|
51
|
-
if (!scope)
|
|
52
|
-
return address;
|
|
53
|
-
if (address.includes('%'))
|
|
54
|
-
return address;
|
|
55
|
-
const isWindows = os.platform() === 'win32';
|
|
56
|
-
const zoneId = isWindows ? detail.scopeid : interfaceName;
|
|
57
|
-
if (zoneId !== undefined && zoneId !== null && `${zoneId}`.length > 0) {
|
|
58
|
-
return `${address}%${zoneId}`;
|
|
59
|
-
}
|
|
60
|
-
return address;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export function getMacAddress() {
|
|
66
|
-
for (const [interfaceName, interfaceDetails] of Object.entries(os.networkInterfaces())) {
|
|
67
|
-
if (!interfaceName || !interfaceDetails || interfaceDetails.length === 0)
|
|
68
|
-
continue;
|
|
69
|
-
for (const detail of interfaceDetails) {
|
|
70
|
-
if (!detail.internal)
|
|
71
|
-
return detail.mac;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
export function logInterfaces() {
|
|
76
|
-
const log = new AnsiLogger({ logName: 'MatterbridgeUtils', logTimestampFormat: 4, logLevel: "info" });
|
|
77
|
-
log.logLevel = "info";
|
|
78
|
-
log.logName = 'LogInterfaces';
|
|
79
|
-
log.info('Available Network Interfaces:');
|
|
80
|
-
const availableAddresses = Object.entries(os.networkInterfaces());
|
|
81
|
-
for (const [ifaceName, ifaces] of availableAddresses) {
|
|
82
|
-
if (ifaces && ifaces.length > 0) {
|
|
83
|
-
log.info(`Network interface ${BLUE}${ifaceName}${nf}:`);
|
|
84
|
-
ifaces.forEach((iface) => {
|
|
85
|
-
log.info(`- ${CYAN}${iface.family}${nf} address ${CYAN}${iface.address}${nf} netmask ${CYAN}${iface.netmask}${nf} mac ${CYAN}${iface.mac}${nf}` +
|
|
86
|
-
`${iface.scopeid ? ` scopeid ${CYAN}${iface.scopeid}${nf}` : ''}${iface.cidr ? ` cidr ${CYAN}${iface.cidr}${nf}` : ''} ${CYAN}${iface.internal ? 'internal' : 'external'}${nf}`);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
export async function resolveHostname(hostname, family = 4) {
|
|
92
|
-
const dns = await import('node:dns');
|
|
93
|
-
try {
|
|
94
|
-
const addresses = await dns.promises.lookup(hostname.toLowerCase(), { family });
|
|
95
|
-
return addresses.address;
|
|
96
|
-
}
|
|
97
|
-
catch (_error) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
|
|
102
|
-
const https = await import('node:https');
|
|
103
|
-
return new Promise((resolve, reject) => {
|
|
104
|
-
const url = `https://registry.npmjs.org/${packageName}`;
|
|
105
|
-
const controller = new AbortController();
|
|
106
|
-
const timeoutId = setTimeout(() => {
|
|
107
|
-
controller.abort();
|
|
108
|
-
reject(new Error(`Request timed out after ${timeout / 1000} seconds`));
|
|
109
|
-
}, timeout);
|
|
110
|
-
const req = https.get(url, { signal: controller.signal }, (res) => {
|
|
111
|
-
let data = '';
|
|
112
|
-
if (res.statusCode !== 200) {
|
|
113
|
-
clearTimeout(timeoutId);
|
|
114
|
-
res.resume();
|
|
115
|
-
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
res.on('data', (chunk) => {
|
|
119
|
-
data += chunk;
|
|
120
|
-
});
|
|
121
|
-
res.on('end', () => {
|
|
122
|
-
clearTimeout(timeoutId);
|
|
123
|
-
try {
|
|
124
|
-
const jsonData = JSON.parse(data);
|
|
125
|
-
const version = jsonData['dist-tags']?.[tag];
|
|
126
|
-
if (version) {
|
|
127
|
-
resolve(version);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
reject(new Error(`Tag "${tag}" not found for package "${packageName}"`));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
reject(new Error(`Failed to parse response JSON: ${error instanceof Error ? error.message : error}`));
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
req.on('error', (error) => {
|
|
139
|
-
clearTimeout(timeoutId);
|
|
140
|
-
reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
145
|
-
const https = await import('node:https');
|
|
146
|
-
return new Promise((resolve, reject) => {
|
|
147
|
-
const url = `https://matterbridge.io/${branch}_${file}`;
|
|
148
|
-
const controller = new AbortController();
|
|
149
|
-
const timeoutId = setTimeout(() => {
|
|
150
|
-
controller.abort();
|
|
151
|
-
reject(new Error(`Request timed out after ${timeout / 1000} seconds`));
|
|
152
|
-
}, timeout);
|
|
153
|
-
const req = https.get(url, { signal: controller.signal }, (res) => {
|
|
154
|
-
let data = '';
|
|
155
|
-
if (res.statusCode !== 200) {
|
|
156
|
-
clearTimeout(timeoutId);
|
|
157
|
-
res.resume();
|
|
158
|
-
reject(new Error(`Failed to fetch data. Status code: ${res.statusCode}`));
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
res.on('data', (chunk) => {
|
|
162
|
-
data += chunk;
|
|
163
|
-
});
|
|
164
|
-
res.on('end', () => {
|
|
165
|
-
clearTimeout(timeoutId);
|
|
166
|
-
try {
|
|
167
|
-
const jsonData = JSON.parse(data);
|
|
168
|
-
resolve(jsonData);
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
reject(new Error(`Failed to parse response JSON: ${error instanceof Error ? error.message : error}`));
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
req.on('error', (error) => {
|
|
176
|
-
clearTimeout(timeoutId);
|
|
177
|
-
reject(new Error(`Request failed: ${error instanceof Error ? error.message : error}`));
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
export async function getGlobalNodeModules() {
|
|
182
|
-
const { exec } = await import('node:child_process');
|
|
183
|
-
return new Promise((resolve, reject) => {
|
|
184
|
-
exec('npm root -g', (error, stdout) => {
|
|
185
|
-
if (error) {
|
|
186
|
-
reject(error);
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
resolve(stdout.trim());
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
});
|
|
193
|
-
}
|
package/dist/utils/tracker.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'node:events';
|
|
2
|
-
export type TrackerSnapshot = {
|
|
3
|
-
timestamp: number;
|
|
4
|
-
freeMemory: number;
|
|
5
|
-
peakFreeMemory: number;
|
|
6
|
-
totalMemory: number;
|
|
7
|
-
peakTotalMemory: number;
|
|
8
|
-
osCpu: number;
|
|
9
|
-
peakOsCpu: number;
|
|
10
|
-
processCpu: number;
|
|
11
|
-
peakProcessCpu: number;
|
|
12
|
-
rss: number;
|
|
13
|
-
peakRss: number;
|
|
14
|
-
heapUsed: number;
|
|
15
|
-
peakHeapUsed: number;
|
|
16
|
-
heapTotal: number;
|
|
17
|
-
peakHeapTotal: number;
|
|
18
|
-
external: number;
|
|
19
|
-
peakExternal: number;
|
|
20
|
-
arrayBuffers: number;
|
|
21
|
-
peakArrayBuffers: number;
|
|
22
|
-
};
|
|
23
|
-
interface TrackerEvents {
|
|
24
|
-
start: [];
|
|
25
|
-
stop: [];
|
|
26
|
-
uptime: [os: number, process: number];
|
|
27
|
-
cpu: [os: number, process: number];
|
|
28
|
-
memory: [free: number, total: number, rss: number, heapUsed: number, heapTotal: number, external: number, arrayBuffers: number];
|
|
29
|
-
snapshot: [snapshot: TrackerSnapshot];
|
|
30
|
-
reset_peaks: [];
|
|
31
|
-
reset_peaks_done: [];
|
|
32
|
-
gc: [];
|
|
33
|
-
gc_done: [type: 'major' | 'minor', execution: 'sync' | 'async'];
|
|
34
|
-
}
|
|
35
|
-
export declare class Tracker extends EventEmitter<TrackerEvents> {
|
|
36
|
-
private readonly name;
|
|
37
|
-
private readonly debug;
|
|
38
|
-
private readonly verbose;
|
|
39
|
-
private trackerInterval?;
|
|
40
|
-
static historyIndex: number;
|
|
41
|
-
static readonly historySize = 2880;
|
|
42
|
-
static readonly history: TrackerSnapshot[];
|
|
43
|
-
private prevCpus;
|
|
44
|
-
private prevCpuUsage;
|
|
45
|
-
private log;
|
|
46
|
-
constructor(name?: string, debug?: boolean, verbose?: boolean);
|
|
47
|
-
start(sampleIntervalMs?: number): void;
|
|
48
|
-
resetPeaks(): void;
|
|
49
|
-
runGarbageCollector(type?: 'major' | 'minor', execution?: 'sync' | 'async'): void;
|
|
50
|
-
stop(): void;
|
|
51
|
-
}
|
|
52
|
-
export {};
|
package/dist/utils/tracker.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
if (process.argv.includes('--loader') || process.argv.includes('-loader'))
|
|
2
|
-
console.log('\u001B[32mTracker loaded.\u001B[40;0m');
|
|
3
|
-
import os from 'node:os';
|
|
4
|
-
import EventEmitter from 'node:events';
|
|
5
|
-
import { AnsiLogger, BRIGHT, CYAN, RESET, YELLOW, db, RED } from 'node-ansi-logger';
|
|
6
|
-
import { formatPercent, formatBytes, formatTimeStamp } from './format.js';
|
|
7
|
-
export class Tracker extends EventEmitter {
|
|
8
|
-
name;
|
|
9
|
-
debug;
|
|
10
|
-
verbose;
|
|
11
|
-
trackerInterval;
|
|
12
|
-
static historyIndex = 0;
|
|
13
|
-
static historySize = 2880;
|
|
14
|
-
static history = Array.from({ length: this.historySize }, () => ({
|
|
15
|
-
timestamp: 0,
|
|
16
|
-
freeMemory: 0,
|
|
17
|
-
peakFreeMemory: 0,
|
|
18
|
-
totalMemory: 0,
|
|
19
|
-
peakTotalMemory: 0,
|
|
20
|
-
osCpu: 0,
|
|
21
|
-
peakOsCpu: 0,
|
|
22
|
-
processCpu: 0,
|
|
23
|
-
peakProcessCpu: 0,
|
|
24
|
-
rss: 0,
|
|
25
|
-
peakRss: 0,
|
|
26
|
-
heapUsed: 0,
|
|
27
|
-
peakHeapUsed: 0,
|
|
28
|
-
heapTotal: 0,
|
|
29
|
-
peakHeapTotal: 0,
|
|
30
|
-
external: 0,
|
|
31
|
-
peakExternal: 0,
|
|
32
|
-
arrayBuffers: 0,
|
|
33
|
-
peakArrayBuffers: 0,
|
|
34
|
-
}));
|
|
35
|
-
prevCpus = os.cpus();
|
|
36
|
-
prevCpuUsage = process.cpuUsage();
|
|
37
|
-
log;
|
|
38
|
-
constructor(name = 'Tracker', debug = false, verbose = false) {
|
|
39
|
-
super();
|
|
40
|
-
this.name = name;
|
|
41
|
-
this.debug = debug;
|
|
42
|
-
this.verbose = verbose;
|
|
43
|
-
if (process.argv.includes('--debug') || process.argv.includes('-debug') || process.argv.includes('--verbose') || process.argv.includes('-verbose')) {
|
|
44
|
-
this.debug = true;
|
|
45
|
-
}
|
|
46
|
-
if (process.argv.includes('--verbose') || process.argv.includes('-verbose')) {
|
|
47
|
-
this.verbose = true;
|
|
48
|
-
}
|
|
49
|
-
this.log = new AnsiLogger({ logName: name, logTimestampFormat: 4, logLevel: this.debug ? "debug" : "info" });
|
|
50
|
-
this.log.logNameColor = YELLOW;
|
|
51
|
-
if (this.verbose) {
|
|
52
|
-
this.log.debug(`os.cpus():\n${RESET}`, os.cpus());
|
|
53
|
-
this.log.debug(`process.cpuUsage():\n${RESET}`, process.cpuUsage());
|
|
54
|
-
this.log.debug(`process.memoryUsage():\n${RESET}`, process.memoryUsage());
|
|
55
|
-
}
|
|
56
|
-
this.on('start', () => {
|
|
57
|
-
this.start();
|
|
58
|
-
});
|
|
59
|
-
this.on('stop', () => {
|
|
60
|
-
this.stop();
|
|
61
|
-
});
|
|
62
|
-
this.on('reset_peaks', () => {
|
|
63
|
-
this.resetPeaks();
|
|
64
|
-
});
|
|
65
|
-
this.on('gc', () => {
|
|
66
|
-
this.runGarbageCollector();
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
start(sampleIntervalMs = 10000) {
|
|
70
|
-
if (this.trackerInterval)
|
|
71
|
-
return;
|
|
72
|
-
this.log.debug(`Tracker starting...`);
|
|
73
|
-
let tryGcCount = 0;
|
|
74
|
-
this.prevCpus = os.cpus();
|
|
75
|
-
this.prevCpuUsage = process.cpuUsage();
|
|
76
|
-
this.trackerInterval = setInterval(() => {
|
|
77
|
-
tryGcCount += sampleIntervalMs / 1000;
|
|
78
|
-
if (tryGcCount > 60 * 60) {
|
|
79
|
-
this.runGarbageCollector();
|
|
80
|
-
tryGcCount = 0;
|
|
81
|
-
}
|
|
82
|
-
const entry = Tracker.history[Tracker.historyIndex];
|
|
83
|
-
const prevEntry = Tracker.history[(Tracker.historyIndex + Tracker.historySize - 1) % Tracker.historySize];
|
|
84
|
-
entry.timestamp = Date.now();
|
|
85
|
-
this.emit('uptime', os.uptime(), process.uptime());
|
|
86
|
-
const currentCpus = os.cpus();
|
|
87
|
-
const loads = currentCpus.map((cpu, idx) => {
|
|
88
|
-
const prev = this.prevCpus[idx]?.times;
|
|
89
|
-
if (!prev)
|
|
90
|
-
return 0;
|
|
91
|
-
const cur = cpu.times;
|
|
92
|
-
const idleDelta = cur.idle - prev.idle;
|
|
93
|
-
const busyDelta = cur.user - prev.user + (cur.nice - prev.nice) + (cur.sys - prev.sys) + (cur.irq - prev.irq);
|
|
94
|
-
const totalDelta = busyDelta + idleDelta;
|
|
95
|
-
if (totalDelta <= 0)
|
|
96
|
-
return 0;
|
|
97
|
-
return busyDelta / totalDelta;
|
|
98
|
-
});
|
|
99
|
-
this.prevCpus = currentCpus;
|
|
100
|
-
const avgLoad = loads.length === 0 ? 0 : loads.reduce((sum, value) => sum + value, 0) / loads.length;
|
|
101
|
-
const osCpu = Number((avgLoad * 100).toFixed(2));
|
|
102
|
-
entry.osCpu = osCpu;
|
|
103
|
-
entry.peakOsCpu = Math.max(prevEntry.peakOsCpu, osCpu);
|
|
104
|
-
const diff = process.cpuUsage(this.prevCpuUsage);
|
|
105
|
-
this.prevCpuUsage = process.cpuUsage();
|
|
106
|
-
const totalMs = (diff.user + diff.system) / 1000;
|
|
107
|
-
const processCpu = Number((((totalMs / sampleIntervalMs) * 100) / currentCpus.length).toFixed(2));
|
|
108
|
-
entry.processCpu = processCpu;
|
|
109
|
-
entry.peakProcessCpu = Math.max(prevEntry.peakProcessCpu, processCpu);
|
|
110
|
-
this.emit('cpu', entry.osCpu, entry.processCpu);
|
|
111
|
-
entry.freeMemory = os.freemem();
|
|
112
|
-
entry.peakFreeMemory = Math.max(prevEntry.peakFreeMemory, entry.freeMemory);
|
|
113
|
-
entry.totalMemory = os.totalmem();
|
|
114
|
-
entry.peakTotalMemory = Math.max(prevEntry.peakTotalMemory, entry.totalMemory);
|
|
115
|
-
const mem = process.memoryUsage();
|
|
116
|
-
entry.rss = mem.rss;
|
|
117
|
-
entry.peakRss = Math.max(prevEntry.peakRss, mem.rss);
|
|
118
|
-
entry.heapUsed = mem.heapUsed;
|
|
119
|
-
entry.peakHeapUsed = Math.max(prevEntry.peakHeapUsed, mem.heapUsed);
|
|
120
|
-
entry.heapTotal = mem.heapTotal;
|
|
121
|
-
entry.peakHeapTotal = Math.max(prevEntry.peakHeapTotal, mem.heapTotal);
|
|
122
|
-
entry.external = mem.external;
|
|
123
|
-
entry.peakExternal = Math.max(prevEntry.peakExternal, mem.external);
|
|
124
|
-
entry.arrayBuffers = mem.arrayBuffers;
|
|
125
|
-
entry.peakArrayBuffers = Math.max(prevEntry.peakArrayBuffers, mem.arrayBuffers);
|
|
126
|
-
this.emit('memory', entry.freeMemory, entry.totalMemory, entry.rss, entry.heapUsed, entry.heapTotal, entry.external, entry.arrayBuffers);
|
|
127
|
-
this.emit('snapshot', entry);
|
|
128
|
-
if (this.debug) {
|
|
129
|
-
this.log.debug(`Time: ${formatTimeStamp(entry.timestamp)} ` +
|
|
130
|
-
`os ${CYAN}${BRIGHT}${formatPercent(entry.osCpu)}${RESET}${db} (${entry.peakOsCpu > prevEntry.peakOsCpu ? RED : ''}${formatPercent(entry.peakOsCpu)}${db}) ` +
|
|
131
|
-
`process ${CYAN}${BRIGHT}${formatPercent(entry.processCpu)}${RESET}${db} (${entry.peakProcessCpu > prevEntry.peakProcessCpu ? RED : ''}${formatPercent(entry.peakProcessCpu)}${db}) ` +
|
|
132
|
-
`rss: ${CYAN}${BRIGHT}${formatBytes(entry.rss)}${RESET}${db} (${entry.peakRss > prevEntry.peakRss ? RED : ''}${formatBytes(entry.peakRss)}${db}) ` +
|
|
133
|
-
`heapUsed: ${CYAN}${BRIGHT}${formatBytes(entry.heapUsed)}${RESET}${db} (${entry.peakHeapUsed > prevEntry.peakHeapUsed ? RED : ''}${formatBytes(entry.peakHeapUsed)}${db}) ` +
|
|
134
|
-
`heapTotal: ${CYAN}${BRIGHT}${formatBytes(entry.heapTotal)}${RESET}${db} (${entry.peakHeapTotal > prevEntry.peakHeapTotal ? RED : ''}${formatBytes(entry.peakHeapTotal)}${db}) ` +
|
|
135
|
-
`external: ${CYAN}${BRIGHT}${formatBytes(entry.external)}${RESET}${db} (${entry.peakExternal > prevEntry.peakExternal ? RED : ''}${formatBytes(entry.peakExternal)}${db}) ` +
|
|
136
|
-
`arrayBuffers: ${CYAN}${BRIGHT}${formatBytes(entry.arrayBuffers)}${RESET}${db} (${entry.peakArrayBuffers > prevEntry.peakArrayBuffers ? RED : ''}${formatBytes(entry.peakArrayBuffers)}${db})`);
|
|
137
|
-
}
|
|
138
|
-
Tracker.historyIndex = (Tracker.historyIndex + 1) % Tracker.historySize;
|
|
139
|
-
}, sampleIntervalMs);
|
|
140
|
-
this.log.debug(`Tracker started`);
|
|
141
|
-
}
|
|
142
|
-
resetPeaks() {
|
|
143
|
-
const prevHistoryIndex = (Tracker.historyIndex + Tracker.historySize - 1) % Tracker.historySize;
|
|
144
|
-
Tracker.history[prevHistoryIndex].peakOsCpu = 0;
|
|
145
|
-
Tracker.history[prevHistoryIndex].peakProcessCpu = 0;
|
|
146
|
-
Tracker.history[prevHistoryIndex].peakRss = 0;
|
|
147
|
-
Tracker.history[prevHistoryIndex].peakHeapUsed = 0;
|
|
148
|
-
Tracker.history[prevHistoryIndex].peakHeapTotal = 0;
|
|
149
|
-
Tracker.history[prevHistoryIndex].peakExternal = 0;
|
|
150
|
-
Tracker.history[prevHistoryIndex].peakArrayBuffers = 0;
|
|
151
|
-
if (this.debug)
|
|
152
|
-
this.log.debug(`${CYAN}${BRIGHT}Peaks reset at ${new Date(Date.now()).toLocaleString()}.${RESET}${db}`);
|
|
153
|
-
this.emit('reset_peaks_done');
|
|
154
|
-
}
|
|
155
|
-
runGarbageCollector(type = 'major', execution = 'async') {
|
|
156
|
-
if (global.gc && typeof global.gc === 'function') {
|
|
157
|
-
try {
|
|
158
|
-
global.gc({ type, execution });
|
|
159
|
-
if (this.debug)
|
|
160
|
-
this.log.debug(`${CYAN}${BRIGHT}Garbage collection (${type}-${execution}) triggered at ${new Date(Date.now()).toLocaleString()}.${RESET}${db}`);
|
|
161
|
-
this.emit('gc_done', type, execution);
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
global.gc();
|
|
165
|
-
if (this.debug)
|
|
166
|
-
this.log.debug(`${CYAN}${BRIGHT}Garbage collection (minor-async) triggered at ${new Date(Date.now()).toLocaleString()}.${RESET}${db}`);
|
|
167
|
-
this.emit('gc_done', 'minor', 'async');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
if (this.debug)
|
|
172
|
-
this.log.debug(`${CYAN}${BRIGHT}Garbage collection not exposed. Start Node.js with --expose-gc to enable manual garbage collection.${RESET}${db}`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
stop() {
|
|
176
|
-
this.log.debug(`Tracker stopping...`);
|
|
177
|
-
if (this.trackerInterval) {
|
|
178
|
-
clearInterval(this.trackerInterval);
|
|
179
|
-
this.trackerInterval = undefined;
|
|
180
|
-
}
|
|
181
|
-
if (this.debug) {
|
|
182
|
-
this.log.debug(`Tracker history for ${YELLOW}${BRIGHT}${this.name}:${RESET}`);
|
|
183
|
-
this.log.debug('Timestamp Host cpu Process cpu Rss Heap Used Heap Total External ArrayBuffers');
|
|
184
|
-
for (let i = 0; i < Tracker.historySize; i++) {
|
|
185
|
-
const index = (Tracker.historyIndex + i) % Tracker.historySize;
|
|
186
|
-
const entry = Tracker.history[index];
|
|
187
|
-
if (entry.timestamp === 0)
|
|
188
|
-
continue;
|
|
189
|
-
this.log.debug(`${formatTimeStamp(entry.timestamp)} ` +
|
|
190
|
-
`${CYAN}${BRIGHT}${formatPercent(entry.osCpu).padStart(8)}${RESET} (${formatPercent(entry.peakOsCpu).padStart(8)}) ` +
|
|
191
|
-
`${CYAN}${BRIGHT}${formatPercent(entry.processCpu).padStart(8)}${RESET} (${formatPercent(entry.peakProcessCpu).padStart(8)}) ` +
|
|
192
|
-
`${CYAN}${BRIGHT}${formatBytes(entry.rss).padStart(9)}${RESET} (${formatBytes(entry.peakRss).padStart(9)}) ` +
|
|
193
|
-
`${CYAN}${BRIGHT}${formatBytes(entry.heapUsed).padStart(9)}${RESET} (${formatBytes(entry.peakHeapUsed).padStart(9)}) ` +
|
|
194
|
-
`${CYAN}${BRIGHT}${formatBytes(entry.heapTotal).padStart(9)}${RESET} (${formatBytes(entry.peakHeapTotal).padStart(9)}) ` +
|
|
195
|
-
`${CYAN}${BRIGHT}${formatBytes(entry.external).padStart(9)}${RESET} (${formatBytes(entry.peakExternal).padStart(9)}) ` +
|
|
196
|
-
`${CYAN}${BRIGHT}${formatBytes(entry.arrayBuffers).padStart(9)}${RESET} (${formatBytes(entry.peakArrayBuffers).padStart(9)})`);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
this.log.debug(`Tracker stopped`);
|
|
200
|
-
}
|
|
201
|
-
}
|
package/dist/utils/wait.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare function waiter(name: string, check: () => boolean, exitWithReject?: boolean, resolveTimeout?: number, resolveInterval?: number, debug?: boolean): Promise<boolean>;
|
|
2
|
-
export declare function wait(timeout?: number, name?: string, debug?: boolean): Promise<void>;
|
|
3
|
-
export declare function withTimeout<T>(promise: Promise<T>, timeoutMillisecs?: number, reThrow?: boolean): Promise<T>;
|
package/dist/utils/wait.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { AnsiLogger } from 'node-ansi-logger';
|
|
2
|
-
export async function waiter(name, check, exitWithReject = false, resolveTimeout = 5000, resolveInterval = 500, debug = false) {
|
|
3
|
-
const log = new AnsiLogger({ logName: 'Waiter', logTimestampFormat: 4, logLevel: "debug" });
|
|
4
|
-
if (check()) {
|
|
5
|
-
if (debug)
|
|
6
|
-
log.debug(`Waiter "${name}" already true`);
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
if (debug)
|
|
10
|
-
log.debug(`Waiter "${name}" started...`);
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const timeoutId = setTimeout(() => {
|
|
13
|
-
if (debug)
|
|
14
|
-
log.debug(`Waiter "${name}" finished for timeout...`);
|
|
15
|
-
clearTimeout(timeoutId);
|
|
16
|
-
clearInterval(intervalId);
|
|
17
|
-
if (exitWithReject)
|
|
18
|
-
reject(new Error(`Waiter "${name}" finished due to timeout`));
|
|
19
|
-
else
|
|
20
|
-
resolve(false);
|
|
21
|
-
}, resolveTimeout).unref();
|
|
22
|
-
const intervalId = setInterval(async () => {
|
|
23
|
-
if (check()) {
|
|
24
|
-
if (debug)
|
|
25
|
-
log.debug(`Waiter "${name}" finished for true condition...`);
|
|
26
|
-
clearTimeout(timeoutId);
|
|
27
|
-
clearInterval(intervalId);
|
|
28
|
-
resolve(true);
|
|
29
|
-
}
|
|
30
|
-
await Promise.resolve();
|
|
31
|
-
}, resolveInterval).unref();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
export async function wait(timeout = 1000, name, debug = false) {
|
|
35
|
-
const log = new AnsiLogger({ logName: 'Wait', logTimestampFormat: 4, logLevel: "debug" });
|
|
36
|
-
if (debug)
|
|
37
|
-
log.debug(`Wait "${name}" started...`);
|
|
38
|
-
return new Promise((resolve) => {
|
|
39
|
-
const timeoutId = setTimeout(() => {
|
|
40
|
-
if (debug)
|
|
41
|
-
log.debug(`Wait "${name}" finished...`);
|
|
42
|
-
clearTimeout(timeoutId);
|
|
43
|
-
resolve();
|
|
44
|
-
}, timeout).unref();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
export function withTimeout(promise, timeoutMillisecs = 10000, reThrow = true) {
|
|
48
|
-
return new Promise((resolve, reject) => {
|
|
49
|
-
const timer = setTimeout(() => {
|
|
50
|
-
if (reThrow) {
|
|
51
|
-
reject(new Error('Operation timed out'));
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
resolve(undefined);
|
|
55
|
-
}
|
|
56
|
-
}, timeoutMillisecs).unref();
|
|
57
|
-
promise
|
|
58
|
-
.then((result) => {
|
|
59
|
-
clearTimeout(timer);
|
|
60
|
-
resolve(result);
|
|
61
|
-
return result;
|
|
62
|
-
})
|
|
63
|
-
.catch((error) => {
|
|
64
|
-
clearTimeout(timer);
|
|
65
|
-
if (reThrow) {
|
|
66
|
-
reject(error);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
resolve(undefined);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|