matterbridge 2.1.6-dev.2 → 2.1.6-dev.4
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 +6 -2
- package/dist/cli.js +148 -3
- package/dist/frontend.js +32 -106
- package/dist/matter/export.js +1 -1
- package/dist/matterbridge.js +9 -1
- package/dist/pluginManager.js +67 -56
- package/frontend/build/asset-manifest.json +3 -3
- package/frontend/build/index.html +1 -1
- package/frontend/build/matterbridge 32x32.png +0 -0
- package/frontend/build/matterbridge 64x64.png +0 -0
- package/frontend/build/matterbridge.svg +50 -0
- package/frontend/build/static/js/{main.a241d4f0.js → main.257513e8.js} +13 -13
- package/frontend/build/static/js/main.257513e8.js.map +1 -0
- package/npm-shrinkwrap.json +44 -44
- package/package.json +2 -2
- package/frontend/build/static/js/main.a241d4f0.js.map +0 -1
- /package/frontend/build/static/js/{main.a241d4f0.js.LICENSE.txt → main.257513e8.js.LICENSE.txt} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -33,18 +33,22 @@ matterbridge-zigbee2mqtt v. 2.4.4
|
|
|
33
33
|
matterbridge-somfy-tahoma v. 1.2.3
|
|
34
34
|
matterbridge-hass v. 0.0.8
|
|
35
35
|
|
|
36
|
-
## [2.1.6] - 2025-02-
|
|
36
|
+
## [2.1.6] - 2025-02-15
|
|
37
37
|
|
|
38
38
|
### Added
|
|
39
39
|
|
|
40
|
-
- [docker]: Added health check directly
|
|
40
|
+
- [docker]: Added health check directly in the docker image. No need to change configuration.
|
|
41
41
|
- [platform]: Saving in the storage the selects for faster loading of plugins.
|
|
42
42
|
- [icon]: Added matterbridge svg icon (thanks: https://github.com/robvanoostenrijk https://github.com/stuntguy3000).
|
|
43
|
+
- [frontend]: Added processUptime.
|
|
43
44
|
- [frontend]: Frontend v.2.4.2.
|
|
45
|
+
- [PluginManager]: Refactor PluginManager to optimize memory and load time.
|
|
44
46
|
|
|
45
47
|
### Changed
|
|
46
48
|
|
|
47
49
|
- [package]: Update matter.js to 0.12.4-alpha.0-20250212-b2729c9eb
|
|
50
|
+
- [package]: Update matter.js to 0.12.4-alpha.0-20250213-1187f81eb
|
|
51
|
+
- [package]: Update matter.js to 0.12.4-alpha.0-20250215-5af08a8d6
|
|
48
52
|
|
|
49
53
|
<a href="https://www.buymeacoffee.com/luligugithub">
|
|
50
54
|
<img src="./yellow-button.png" alt="Buy me a coffee" width="120">
|
package/dist/cli.js
CHANGED
|
@@ -1,16 +1,144 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Matterbridge } from './matterbridge.js';
|
|
3
|
-
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
export const cliEmitter = new EventEmitter();
|
|
5
|
+
export let instance;
|
|
6
|
+
let session;
|
|
7
|
+
let memoryCheckInterval;
|
|
8
|
+
let prevCpus;
|
|
9
|
+
export let lastCpuUsage = 0;
|
|
4
10
|
const cli = '\u001B[32m';
|
|
5
11
|
const er = '\u001B[38;5;9m';
|
|
6
12
|
const rs = '\u001B[40;0m';
|
|
13
|
+
const db = '\u001B[38;5;245m';
|
|
14
|
+
const CYAN = '\u001B[36m';
|
|
15
|
+
const YELLOW = '\u001B[33m';
|
|
16
|
+
const BRIGHT = '\u001B[1m';
|
|
7
17
|
async function main() {
|
|
18
|
+
await startCpuMemoryCheck();
|
|
19
|
+
if (process.argv.includes('-inspector'))
|
|
20
|
+
await startInspector();
|
|
8
21
|
if (process.argv.includes('-debug'))
|
|
9
|
-
console.log(cli + `CLI:
|
|
22
|
+
console.log(cli + `CLI: Matterbridge.loadInstance() called` + rs);
|
|
10
23
|
instance = await Matterbridge.loadInstance(true);
|
|
11
24
|
registerHandlers();
|
|
12
25
|
if (process.argv.includes('-debug'))
|
|
13
|
-
console.log(cli + `CLI:
|
|
26
|
+
console.log(cli + `CLI: Matterbridge.loadInstance() exited` + rs);
|
|
27
|
+
}
|
|
28
|
+
async function startCpuMemoryCheck() {
|
|
29
|
+
const os = await import('node:os');
|
|
30
|
+
if (process.argv.includes('-debug'))
|
|
31
|
+
console.log(cli + `CLI: Cpu memory check started` + rs);
|
|
32
|
+
prevCpus = os.cpus();
|
|
33
|
+
clearInterval(memoryCheckInterval);
|
|
34
|
+
const formatMemoryUsage = (bytes) => {
|
|
35
|
+
if (bytes >= 1024 ** 3) {
|
|
36
|
+
return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
|
|
37
|
+
}
|
|
38
|
+
else if (bytes >= 1024 ** 2) {
|
|
39
|
+
return `${(bytes / 1024 ** 2).toFixed(2)} MB`;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return `${(bytes / 1024).toFixed(2)} KB`;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const formatOsUpTime = (seconds) => {
|
|
46
|
+
if (seconds >= 86400) {
|
|
47
|
+
const days = Math.floor(seconds / 86400);
|
|
48
|
+
return `${days} day${days !== 1 ? 's' : ''}`;
|
|
49
|
+
}
|
|
50
|
+
if (seconds >= 3600) {
|
|
51
|
+
const hours = Math.floor(seconds / 3600);
|
|
52
|
+
return `${hours} hour${hours !== 1 ? 's' : ''}`;
|
|
53
|
+
}
|
|
54
|
+
if (seconds >= 60) {
|
|
55
|
+
const minutes = Math.floor(seconds / 60);
|
|
56
|
+
return `${minutes} minute${minutes !== 1 ? 's' : ''}`;
|
|
57
|
+
}
|
|
58
|
+
return `${seconds} second${seconds !== 1 ? 's' : ''}`;
|
|
59
|
+
};
|
|
60
|
+
const interval = () => {
|
|
61
|
+
const systemUptime = formatOsUpTime(Math.floor(os.uptime()));
|
|
62
|
+
const processUptime = formatOsUpTime(Math.floor(process.uptime()));
|
|
63
|
+
cliEmitter.emit('uptime', systemUptime, processUptime);
|
|
64
|
+
const totalMememory = formatMemoryUsage(os.totalmem());
|
|
65
|
+
const freeMemory = formatMemoryUsage(os.freemem());
|
|
66
|
+
const memoryUsageRaw = process.memoryUsage();
|
|
67
|
+
const rss = formatMemoryUsage(memoryUsageRaw.rss);
|
|
68
|
+
const heapTotal = formatMemoryUsage(memoryUsageRaw.heapTotal);
|
|
69
|
+
const heapUsed = formatMemoryUsage(memoryUsageRaw.heapUsed);
|
|
70
|
+
const external = formatMemoryUsage(memoryUsageRaw.external);
|
|
71
|
+
const arrayBuffers = formatMemoryUsage(memoryUsageRaw.arrayBuffers);
|
|
72
|
+
cliEmitter.emit('memory', totalMememory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers);
|
|
73
|
+
const currCpus = os.cpus();
|
|
74
|
+
let cpuUsageLog;
|
|
75
|
+
if (currCpus.length !== prevCpus.length) {
|
|
76
|
+
prevCpus = currCpus;
|
|
77
|
+
if (process.argv.includes('-debug'))
|
|
78
|
+
console.log(cli + `CLI: Cpu check length failed, resetting previous cpus` + rs);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let totalIdle = 0, totalTick = 0;
|
|
82
|
+
prevCpus.forEach((prevCpu, i) => {
|
|
83
|
+
const currCpu = currCpus[i];
|
|
84
|
+
const idleDiff = currCpu.times.idle - prevCpu.times.idle;
|
|
85
|
+
const totalDiff = Object.keys(currCpu.times).reduce((acc, key) => acc + (currCpu.times[key] - prevCpu.times[key]), 0);
|
|
86
|
+
totalIdle += idleDiff;
|
|
87
|
+
totalTick += totalDiff;
|
|
88
|
+
});
|
|
89
|
+
const cpuUsage = 100 - (totalIdle / totalTick) * 100;
|
|
90
|
+
if (totalTick === 0 || isNaN(cpuUsage) || !isFinite(cpuUsage) || cpuUsage <= 0) {
|
|
91
|
+
if (process.argv.includes('-debug') && lastCpuUsage != 0)
|
|
92
|
+
console.log(cli + `CLI: Cpu check failed, using previous cpus` + rs);
|
|
93
|
+
cpuUsageLog = lastCpuUsage.toFixed(2);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
cpuUsageLog = cpuUsage.toFixed(2);
|
|
97
|
+
lastCpuUsage = cpuUsage;
|
|
98
|
+
cliEmitter.emit('cpu', lastCpuUsage);
|
|
99
|
+
}
|
|
100
|
+
prevCpus = currCpus;
|
|
101
|
+
if (process.argv.includes('-debug'))
|
|
102
|
+
console.log(`${YELLOW}${BRIGHT}Cpu usage:${db} ${CYAN}${cpuUsageLog.padStart(6, ' ')} %${db} ${YELLOW}${BRIGHT}Memory usage:${db} rss ${CYAN}${rss}${db} heapTotal ${CYAN}${heapTotal}${db} heapUsed ${CYAN}${heapUsed}${db} external ${external} arrayBuffers ${arrayBuffers}` +
|
|
103
|
+
rs);
|
|
104
|
+
};
|
|
105
|
+
interval();
|
|
106
|
+
memoryCheckInterval = setInterval(interval, 10 * 1000);
|
|
107
|
+
}
|
|
108
|
+
async function stopCpuMemoryCheck() {
|
|
109
|
+
if (process.argv.includes('-debug'))
|
|
110
|
+
console.log(cli + `CLI: Cpu memory check stopped` + rs);
|
|
111
|
+
clearInterval(memoryCheckInterval);
|
|
112
|
+
}
|
|
113
|
+
async function startInspector() {
|
|
114
|
+
const { Session } = await import('node:inspector');
|
|
115
|
+
if (process.argv.includes('-debug'))
|
|
116
|
+
console.log(cli + `CLI: Starting heap sampling...` + rs);
|
|
117
|
+
session = new Session();
|
|
118
|
+
session.connect();
|
|
119
|
+
session.post('HeapProfiler.startSampling', {}, (err) => {
|
|
120
|
+
if (err)
|
|
121
|
+
console.error(err);
|
|
122
|
+
else
|
|
123
|
+
console.log(cli + `CLI: Heap sampling started` + rs);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
async function stopInspector() {
|
|
127
|
+
const { writeFileSync } = await import('node:fs');
|
|
128
|
+
if (process.argv.includes('-debug'))
|
|
129
|
+
console.log(cli + `CLI: Stopping heap sampling...` + rs);
|
|
130
|
+
session?.post('HeapProfiler.stopSampling', (err, result) => {
|
|
131
|
+
if (err) {
|
|
132
|
+
console.error(err);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const profile = JSON.stringify(result.profile, null, 2);
|
|
136
|
+
writeFileSync('heap-sampling-profile.heapsnapshot', profile);
|
|
137
|
+
console.log(cli + `CLI: Heap sampling profile saved to heap-sampling-profile.heapsnapshot` + rs);
|
|
138
|
+
}
|
|
139
|
+
session?.disconnect();
|
|
140
|
+
session = undefined;
|
|
141
|
+
});
|
|
14
142
|
}
|
|
15
143
|
function registerHandlers() {
|
|
16
144
|
if (instance)
|
|
@@ -19,10 +147,17 @@ function registerHandlers() {
|
|
|
19
147
|
instance.on('restart', async () => restart());
|
|
20
148
|
if (instance)
|
|
21
149
|
instance.on('update', async () => update());
|
|
150
|
+
if (instance)
|
|
151
|
+
instance.on('startmemorycheck', async () => start());
|
|
152
|
+
if (instance)
|
|
153
|
+
instance.on('stopmemorycheck', async () => stop());
|
|
22
154
|
}
|
|
23
155
|
async function shutdown() {
|
|
24
156
|
if (process.argv.includes('-debug'))
|
|
25
157
|
console.log(cli + 'CLI: received shutdown event, exiting...' + rs);
|
|
158
|
+
if (process.argv.includes('-inspector'))
|
|
159
|
+
await stopInspector();
|
|
160
|
+
await stopCpuMemoryCheck();
|
|
26
161
|
process.exit(0);
|
|
27
162
|
}
|
|
28
163
|
async function restart() {
|
|
@@ -37,6 +172,16 @@ async function update() {
|
|
|
37
172
|
instance = await Matterbridge.loadInstance(true);
|
|
38
173
|
registerHandlers();
|
|
39
174
|
}
|
|
175
|
+
async function start() {
|
|
176
|
+
if (process.argv.includes('-debug'))
|
|
177
|
+
console.log(cli + 'CLI: received start memory check event' + rs);
|
|
178
|
+
startCpuMemoryCheck();
|
|
179
|
+
}
|
|
180
|
+
async function stop() {
|
|
181
|
+
if (process.argv.includes('-debug'))
|
|
182
|
+
console.log(cli + 'CLI: received stop memory check event' + rs);
|
|
183
|
+
stopCpuMemoryCheck();
|
|
184
|
+
}
|
|
40
185
|
process.title = 'matterbridge';
|
|
41
186
|
main().catch((error) => {
|
|
42
187
|
console.error(er + `CLI: Matterbridge.loadInstance() failed with error: ${error}` + rs);
|
package/dist/frontend.js
CHANGED
|
@@ -6,15 +6,16 @@ import WebSocket, { WebSocketServer } from 'ws';
|
|
|
6
6
|
import os from 'os';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { promises as fs } from 'fs';
|
|
9
|
-
import { AnsiLogger, CYAN, db,
|
|
10
|
-
import { createZip, deepCopy,
|
|
9
|
+
import { AnsiLogger, stringify, debugStringify, CYAN, db, er, nf, rs, UNDERLINE, UNDERLINEOFF, wr, YELLOW } from './logger/export.js';
|
|
10
|
+
import { createZip, deepCopy, hasParameter, isValidNumber, isValidObject, isValidString } from './utils/utils.js';
|
|
11
11
|
import { plg } from './matterbridgeTypes.js';
|
|
12
12
|
export const WS_ID_LOG = 0;
|
|
13
13
|
export const WS_ID_REFRESH_NEEDED = 1;
|
|
14
14
|
export const WS_ID_RESTART_NEEDED = 2;
|
|
15
15
|
export const WS_ID_CPU_UPDATE = 3;
|
|
16
16
|
export const WS_ID_MEMORY_UPDATE = 4;
|
|
17
|
-
export const
|
|
17
|
+
export const WS_ID_UPTIME_UPDATE = 5;
|
|
18
|
+
export const WS_ID_SNACKBAR = 6;
|
|
18
19
|
export class Frontend {
|
|
19
20
|
matterbridge;
|
|
20
21
|
log;
|
|
@@ -171,9 +172,16 @@ export class Frontend {
|
|
|
171
172
|
this.webSocketServer.on('error', (ws, error) => {
|
|
172
173
|
this.log.error(`WebSocketServer error: ${error}`);
|
|
173
174
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
const { cliEmitter } = await import('./cli.js');
|
|
176
|
+
cliEmitter.on('uptime', (systemUptime, processUptime) => {
|
|
177
|
+
this.wssSendUptimeUpdate(systemUptime, processUptime);
|
|
178
|
+
});
|
|
179
|
+
cliEmitter.on('memory', (totalMememory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers) => {
|
|
180
|
+
this.wssSendMemoryUpdate(totalMememory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers);
|
|
181
|
+
});
|
|
182
|
+
cliEmitter.on('cpu', (cpuUsage) => {
|
|
183
|
+
this.wssSendCpuUpdate(cpuUsage);
|
|
184
|
+
});
|
|
177
185
|
this.expressApp.post('/api/login', express.json(), async (req, res) => {
|
|
178
186
|
const { password } = req.body;
|
|
179
187
|
this.log.debug('The frontend sent /api/login', password);
|
|
@@ -752,17 +760,6 @@ export class Frontend {
|
|
|
752
760
|
this.log.debug(`Frontend initialized on port ${YELLOW}${this.port}${db} static ${UNDERLINE}${path.join(this.matterbridge.rootDirectory, 'frontend/build')}${UNDERLINEOFF}${rs}`);
|
|
753
761
|
}
|
|
754
762
|
async stop() {
|
|
755
|
-
if (hasParameter('memorycheck')) {
|
|
756
|
-
this.wssSendSnackbarMessage('Memory check started', getIntParameter('memorycheck') ?? 5 * 60 * 1000);
|
|
757
|
-
await new Promise((resolve) => {
|
|
758
|
-
this.log.debug(`***Memory check started for ${getIntParameter('memorycheck') ?? 5 * 60 * 1000} ms`);
|
|
759
|
-
setTimeout(() => {
|
|
760
|
-
this.wssSendSnackbarMessage('Memory check stopped', 10);
|
|
761
|
-
this.log.debug(`***Memory check stopped after ${getIntParameter('memorycheck') ?? 5 * 60 * 1000} ms`);
|
|
762
|
-
resolve();
|
|
763
|
-
}, getIntParameter('memorycheck') ?? 5 * 60 * 1000);
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
763
|
if (this.httpServer) {
|
|
767
764
|
this.httpServer.close();
|
|
768
765
|
this.httpServer.removeAllListeners();
|
|
@@ -796,9 +793,6 @@ export class Frontend {
|
|
|
796
793
|
});
|
|
797
794
|
this.webSocketServer = undefined;
|
|
798
795
|
}
|
|
799
|
-
if (hasParameter('memorydump')) {
|
|
800
|
-
this.stopCpuMemoryDump();
|
|
801
|
-
}
|
|
802
796
|
}
|
|
803
797
|
formatMemoryUsage = (bytes) => {
|
|
804
798
|
if (bytes >= 1024 ** 3) {
|
|
@@ -811,8 +805,7 @@ export class Frontend {
|
|
|
811
805
|
return `${(bytes / 1024).toFixed(2)} KB`;
|
|
812
806
|
}
|
|
813
807
|
};
|
|
814
|
-
formatOsUpTime = () => {
|
|
815
|
-
const seconds = os.uptime();
|
|
808
|
+
formatOsUpTime = (seconds) => {
|
|
816
809
|
if (seconds >= 86400) {
|
|
817
810
|
const days = Math.floor(seconds / 86400);
|
|
818
811
|
return `${days} day${days !== 1 ? 's' : ''}`;
|
|
@@ -827,86 +820,13 @@ export class Frontend {
|
|
|
827
820
|
}
|
|
828
821
|
return `${seconds} second${seconds !== 1 ? 's' : ''}`;
|
|
829
822
|
};
|
|
830
|
-
getCpuUsage = () => {
|
|
831
|
-
const currCpus = os.cpus();
|
|
832
|
-
if (currCpus.length !== this.prevCpus.length) {
|
|
833
|
-
this.prevCpus = deepCopy(currCpus);
|
|
834
|
-
this.log.debug(`***Cpu usage reset. Current cpus: ${currCpus.length}. Previous cpus: ${this.prevCpus.length}.`);
|
|
835
|
-
return this.lastCpuUsage.toFixed(2);
|
|
836
|
-
}
|
|
837
|
-
let totalIdle = 0, totalTick = 0;
|
|
838
|
-
this.prevCpus.forEach((prevCpu, i) => {
|
|
839
|
-
const currCpu = currCpus[i];
|
|
840
|
-
const idleDiff = currCpu.times.idle - prevCpu.times.idle;
|
|
841
|
-
const totalDiff = Object.keys(currCpu.times).reduce((acc, key) => acc + (currCpu.times[key] - prevCpu.times[key]), 0);
|
|
842
|
-
totalIdle += idleDiff;
|
|
843
|
-
totalTick += totalDiff;
|
|
844
|
-
});
|
|
845
|
-
const cpuUsage = 100 - (totalIdle / totalTick) * 100;
|
|
846
|
-
if (totalTick === 0 || isNaN(cpuUsage) || !isFinite(cpuUsage) || cpuUsage <= 0) {
|
|
847
|
-
this.log.debug('***Invalid cpu usage. Returning the previous one.');
|
|
848
|
-
return this.lastCpuUsage.toFixed(2);
|
|
849
|
-
}
|
|
850
|
-
this.prevCpus = deepCopy(currCpus);
|
|
851
|
-
this.lastCpuUsage = cpuUsage;
|
|
852
|
-
return cpuUsage.toFixed(2);
|
|
853
|
-
};
|
|
854
|
-
startCpuMemoryDump() {
|
|
855
|
-
clearInterval(this.memoryInterval);
|
|
856
|
-
clearTimeout(this.memoryTimeout);
|
|
857
|
-
const interval = () => {
|
|
858
|
-
const cpuUsage = this.getCpuUsage();
|
|
859
|
-
const memoryUsageRaw = process.memoryUsage();
|
|
860
|
-
this.memoryData.push({ ...memoryUsageRaw, cpu: cpuUsage });
|
|
861
|
-
const memoryUsage = {
|
|
862
|
-
rss: this.formatMemoryUsage(memoryUsageRaw.rss),
|
|
863
|
-
heapTotal: this.formatMemoryUsage(memoryUsageRaw.heapTotal),
|
|
864
|
-
heapUsed: this.formatMemoryUsage(memoryUsageRaw.heapUsed),
|
|
865
|
-
external: this.formatMemoryUsage(memoryUsageRaw.external),
|
|
866
|
-
arrayBuffers: this.formatMemoryUsage(memoryUsageRaw.arrayBuffers),
|
|
867
|
-
};
|
|
868
|
-
this.log.debug(`***Cpu usage: ${CYAN}${cpuUsage.padStart(6, ' ')} %${db} - Memory usage: rss ${CYAN}${memoryUsage.rss}${db} heapTotal ${CYAN}${memoryUsage.heapTotal}${db} heapUsed ${CYAN}${memoryUsage.heapUsed}${db} external ${memoryUsage.external} arrayBuffers ${memoryUsage.arrayBuffers}`);
|
|
869
|
-
this.matterbridge.systemInformation.freeMemory = this.formatMemoryUsage(os.freemem());
|
|
870
|
-
this.matterbridge.systemInformation.totalMemory = this.formatMemoryUsage(os.totalmem());
|
|
871
|
-
this.matterbridge.systemInformation.systemUptime = this.formatOsUpTime();
|
|
872
|
-
this.matterbridge.systemInformation.cpuUsed = cpuUsage;
|
|
873
|
-
this.matterbridge.systemInformation.rss = this.formatMemoryUsage(process.memoryUsage().rss);
|
|
874
|
-
this.matterbridge.systemInformation.heapTotal = this.formatMemoryUsage(process.memoryUsage().heapTotal);
|
|
875
|
-
this.matterbridge.systemInformation.heapUsed = this.formatMemoryUsage(process.memoryUsage().heapUsed);
|
|
876
|
-
this.wssSendCpuUpdate(this.matterbridge.systemInformation.cpuUsed);
|
|
877
|
-
this.wssSendMemoryUpdate(this.matterbridge.systemInformation.freeMemory, this.matterbridge.systemInformation.totalMemory, this.matterbridge.systemInformation.systemUptime, this.matterbridge.systemInformation.rss, this.matterbridge.systemInformation.heapUsed, this.matterbridge.systemInformation.heapTotal);
|
|
878
|
-
};
|
|
879
|
-
interval();
|
|
880
|
-
this.memoryInterval = setInterval(interval, getIntParameter('memoryinterval') ?? 1000);
|
|
881
|
-
this.memoryInterval.unref();
|
|
882
|
-
this.memoryTimeout = setTimeout(() => {
|
|
883
|
-
this.stopCpuMemoryDump();
|
|
884
|
-
}, getIntParameter('memorytimeout') ?? 600000);
|
|
885
|
-
this.memoryTimeout.unref();
|
|
886
|
-
}
|
|
887
|
-
stopCpuMemoryDump() {
|
|
888
|
-
clearInterval(this.memoryInterval);
|
|
889
|
-
this.memoryInterval = undefined;
|
|
890
|
-
clearTimeout(this.memoryTimeout);
|
|
891
|
-
this.memoryTimeout = undefined;
|
|
892
|
-
for (const memory of this.memoryData) {
|
|
893
|
-
const memoryUsage = {
|
|
894
|
-
rss: this.formatMemoryUsage(memory.rss),
|
|
895
|
-
heapTotal: this.formatMemoryUsage(memory.heapTotal),
|
|
896
|
-
heapUsed: this.formatMemoryUsage(memory.heapUsed),
|
|
897
|
-
external: this.formatMemoryUsage(memory.external),
|
|
898
|
-
arrayBuffers: this.formatMemoryUsage(memory.arrayBuffers),
|
|
899
|
-
};
|
|
900
|
-
console.log(`${YELLOW}Cpu usage:${db} ${CYAN}${memory.cpu.padStart(6, ' ')} %${db} - ${YELLOW}Memory usage:${db} rss ${CYAN}${memoryUsage.rss}${db} heapTotal ${CYAN}${memoryUsage.heapTotal}${db} heapUsed ${CYAN}${memoryUsage.heapUsed}${db} external ${memoryUsage.external} arrayBuffers ${memoryUsage.arrayBuffers}${rs}`);
|
|
901
|
-
}
|
|
902
|
-
this.memoryData = [];
|
|
903
|
-
this.prevCpus = [];
|
|
904
|
-
}
|
|
905
823
|
async getApiSettings() {
|
|
824
|
+
const { lastCpuUsage } = await import('./cli.js');
|
|
906
825
|
this.matterbridge.systemInformation.totalMemory = this.formatMemoryUsage(os.totalmem());
|
|
907
826
|
this.matterbridge.systemInformation.freeMemory = this.formatMemoryUsage(os.freemem());
|
|
908
|
-
this.matterbridge.systemInformation.systemUptime = this.formatOsUpTime();
|
|
909
|
-
this.matterbridge.systemInformation.
|
|
827
|
+
this.matterbridge.systemInformation.systemUptime = this.formatOsUpTime(os.uptime());
|
|
828
|
+
this.matterbridge.systemInformation.processUptime = this.formatOsUpTime(Math.floor(process.uptime()));
|
|
829
|
+
this.matterbridge.systemInformation.cpuUsage = lastCpuUsage.toFixed(2) + ' %';
|
|
910
830
|
this.matterbridge.systemInformation.rss = this.formatMemoryUsage(process.memoryUsage().rss);
|
|
911
831
|
this.matterbridge.systemInformation.heapTotal = this.formatMemoryUsage(process.memoryUsage().heapTotal);
|
|
912
832
|
this.matterbridge.systemInformation.heapUsed = this.formatMemoryUsage(process.memoryUsage().heapUsed);
|
|
@@ -1391,21 +1311,27 @@ export class Frontend {
|
|
|
1391
1311
|
}
|
|
1392
1312
|
});
|
|
1393
1313
|
}
|
|
1394
|
-
wssSendCpuUpdate(
|
|
1314
|
+
wssSendCpuUpdate(cpuUsage) {
|
|
1315
|
+
this.log.debug('Sending a cpu update message to all connected clients');
|
|
1316
|
+
this.webSocketServer?.clients.forEach((client) => {
|
|
1317
|
+
if (client.readyState === WebSocket.OPEN) {
|
|
1318
|
+
client.send(JSON.stringify({ id: WS_ID_CPU_UPDATE, src: 'Matterbridge', dst: 'Frontend', method: 'cpu_update', params: { cpuUsage } }));
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
wssSendMemoryUpdate(totalMemory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers) {
|
|
1395
1323
|
this.log.debug('Sending a memory update message to all connected clients');
|
|
1396
|
-
this.matterbridge.matterbridgeInformation.restartRequired = true;
|
|
1397
1324
|
this.webSocketServer?.clients.forEach((client) => {
|
|
1398
1325
|
if (client.readyState === WebSocket.OPEN) {
|
|
1399
|
-
client.send(JSON.stringify({ id:
|
|
1326
|
+
client.send(JSON.stringify({ id: WS_ID_MEMORY_UPDATE, src: 'Matterbridge', dst: 'Frontend', method: 'memory_update', params: { totalMemory, freeMemory, rss, heapTotal, heapUsed, external, arrayBuffers } }));
|
|
1400
1327
|
}
|
|
1401
1328
|
});
|
|
1402
1329
|
}
|
|
1403
|
-
|
|
1404
|
-
this.log.debug('Sending a
|
|
1405
|
-
this.matterbridge.matterbridgeInformation.restartRequired = true;
|
|
1330
|
+
wssSendUptimeUpdate(systemUptime, processUptime) {
|
|
1331
|
+
this.log.debug('Sending a uptime update message to all connected clients');
|
|
1406
1332
|
this.webSocketServer?.clients.forEach((client) => {
|
|
1407
1333
|
if (client.readyState === WebSocket.OPEN) {
|
|
1408
|
-
client.send(JSON.stringify({ id:
|
|
1334
|
+
client.send(JSON.stringify({ id: WS_ID_UPTIME_UPDATE, src: 'Matterbridge', dst: 'Frontend', method: 'uptime_update', params: { systemUptime, processUptime } }));
|
|
1409
1335
|
}
|
|
1410
1336
|
});
|
|
1411
1337
|
}
|
package/dist/matter/export.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from '@matter/main';
|
|
2
2
|
export { SemanticNamespace, ClosureTag, CompassDirectionTag, CompassLocationTag, DirectionTag, ElectricalMeasurementTag, LaundryTag, LevelTag, LocationTag, NumberTag, PositionTag, PowerSourceTag, RefrigeratorTag, RoomAirConditionerTag, SwitchesTag, } from '@matter/main';
|
|
3
3
|
export { AttributeElement, ClusterElement, ClusterModel, CommandElement, EventElement, FieldElement } from '@matter/main/model';
|
|
4
|
-
export { logEndpoint, MdnsService } from '@matter/main/protocol';
|
|
4
|
+
export { logEndpoint, MdnsService, Val } from '@matter/main/protocol';
|
package/dist/matterbridge.js
CHANGED
|
@@ -35,7 +35,8 @@ export class Matterbridge extends EventEmitter {
|
|
|
35
35
|
totalMemory: '',
|
|
36
36
|
freeMemory: '',
|
|
37
37
|
systemUptime: '',
|
|
38
|
-
|
|
38
|
+
processUptime: '',
|
|
39
|
+
cpuUsage: '',
|
|
39
40
|
rss: '',
|
|
40
41
|
heapTotal: '',
|
|
41
42
|
heapUsed: '',
|
|
@@ -126,6 +127,12 @@ export class Matterbridge extends EventEmitter {
|
|
|
126
127
|
constructor() {
|
|
127
128
|
super();
|
|
128
129
|
}
|
|
130
|
+
emit(eventName, ...args) {
|
|
131
|
+
return super.emit(eventName, ...args);
|
|
132
|
+
}
|
|
133
|
+
on(eventName, listener) {
|
|
134
|
+
return super.on(eventName, listener);
|
|
135
|
+
}
|
|
129
136
|
getDevices() {
|
|
130
137
|
return this.devices.array();
|
|
131
138
|
}
|
|
@@ -1443,6 +1450,7 @@ export class Matterbridge extends EventEmitter {
|
|
|
1443
1450
|
sanitizeFabrics(serverNode.state.commissioning.fabrics, true);
|
|
1444
1451
|
}
|
|
1445
1452
|
this.frontend.wssSendRefreshRequired();
|
|
1453
|
+
this.frontend.wssSendSnackbarMessage(`${storeId} is online`);
|
|
1446
1454
|
});
|
|
1447
1455
|
serverNode.lifecycle.offline.on(() => {
|
|
1448
1456
|
this.log.notice(`Server node for ${storeId} is offline`);
|