iosignal 5.0.1 → 5.1.1

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.
@@ -1,154 +0,0 @@
1
- import { memoryUsage } from 'process';
2
- import { ENC_MODE } from '../common/constants.js'
3
-
4
- const MAX = 10
5
- let period = 10000
6
-
7
- export class Metric {
8
- constructor(manager) {
9
- this.manager = manager;
10
-
11
- this.metricsPack = {
12
- remotes: [0],
13
- channels: [0],
14
- txBytes: [0],
15
- rxBytes: [0],
16
- unixTime: [Math.floor(Date.now() / 1000)],
17
- period: 0
18
- }
19
-
20
- this.tickId = setInterval(e => {
21
-
22
- this.metricsPack.remotes.push(this.manager.remotes.size)
23
- if (this.metricsPack.remotes.length > MAX) this.metricsPack.remotes.shift()
24
-
25
- this.metricsPack.channels.push(this.manager.channel_map.size)
26
- if (this.metricsPack.channels.length > MAX) this.metricsPack.channels.shift()
27
-
28
-
29
- this.metricsPack.txBytes.push(this.manager.txBytes)
30
- if (this.metricsPack.txBytes.length > MAX) this.metricsPack.txBytes.shift()
31
-
32
- this.metricsPack.rxBytes.push(this.manager.rxBytes)
33
- if (this.metricsPack.rxBytes.length > MAX) this.metricsPack.rxBytes.shift()
34
-
35
- this.metricsPack.unixTime = Math.floor(Date.now() / 1000)
36
- this.metricsPack.period = period;
37
- this.manager.txBytes = 0
38
- this.manager.rxBytes = 0
39
-
40
-
41
- }, 10000)
42
- }
43
-
44
-
45
-
46
- oneline(prn) {
47
- let memoryUse = memoryUsage();
48
- let memoryInfo = [{
49
- ...memoryUse
50
- }]
51
-
52
- if (prn) console.table(memoryInfo, ['rss', 'heapTotal', 'heapUsed', 'external', 'arrayBuffers']);
53
-
54
- let metric = [{
55
- lastSSID: this.manager.lastSSID,
56
- remotes: this.manager.remotes.size,
57
- channels: this.manager.channel_map.size,
58
- txBytes: this.manager.txBytes,
59
- rxBytes: this.manager.rxBytes,
60
- }]
61
-
62
- if (prn) console.table(metric, ['lastSSID', 'remotes', 'channels', 'txBytes', 'rxBytes']);
63
-
64
- return metric[0]
65
- }
66
-
67
- getRemotes(prn) {
68
- let remoteList = Array.from(this.manager.remotes.values())
69
- let remoteStates = remoteList.map(v => {
70
- return "#" + v.ssid + ":" + v.cid + "(" + v.state + ")"
71
- })
72
- if (prn) console.table(remoteStates)
73
- return remoteStates
74
- }
75
-
76
- getCIdList(prn) {
77
- let CIdList = Array.from(this.manager.cid2remote.keys())
78
- if (prn) console.table(CIdList)
79
- return CIdList
80
- }
81
-
82
- getChannelList(prn) {
83
- let chList = Array.from(this.manager.channel_map.keys())
84
- if (prn) console.table(chList)
85
- return chList
86
- }
87
-
88
- getSubscribers(ch) {
89
- let list = [];
90
- if (this.manager.channel_map.has(ch)) {
91
- let subscribers = this.manager.channel_map.get(ch) //set
92
- subscribers.forEach(c => {
93
- list.push(c.cid)
94
- })
95
- }
96
- // console.log(list)
97
- return list
98
- }
99
-
100
- getRemoteByCId(cid, mode = 1) {
101
-
102
- if (this.manager.cid2remote.has(cid)) {
103
- let remote = this.manager.cid2remote.get(cid)
104
- if (mode == 1) {
105
- return {
106
- ip: remote.ip,
107
- id: remote.cid,
108
- ssid: remote.ssid,
109
- cid: remote.cid,
110
- uptime: Math.trunc((Date.now() - remote.socket.openTime) / 1000),
111
- tx: remote.socket.txCounter,
112
- rx: remote.socket.rxCounter,
113
- txBytes: remote.socket.bytesWritten || remote.socket._socket?.bytesWritten,
114
- rxBytes: remote.socket.bytesRead || remote.socket._socket?.bytesRead
115
- }
116
- } else if (mode == 2) {
117
- return {
118
- ip: remote.ip,
119
- uptime: Math.trunc((Date.now() - remote.socket.openTime) / 1000),
120
- nick: remote.nick,
121
- ssid: remote.ssid
122
- }
123
- } else if (mode == 3) {
124
- return {
125
- ip: remote.ip,
126
- uptime: Math.trunc((Date.now() - remote.socket.openTime) / 1000),
127
- nick: remote.nick,
128
- ssid: remote.ssid,
129
- isSecure: remote.TLS,
130
- isAuth: remote.boho.isAuthorized,
131
- encMode: ENC_MODE[remote.encMode]
132
- }
133
- } else if (mode == 4) {
134
- let channels = Array.from(remote.channels.keys())
135
- let set_memory = Array.from(remote.memory.keys())
136
- let retain_signal = Array.from(remote.retain_signal.keys())
137
- return {
138
- ip: remote.ip,
139
- uptime: Math.trunc((Date.now() - remote.socket.openTime) / 1000),
140
- channels: channels,
141
- set: set_memory,
142
- retain: retain_signal
143
- }
144
- }
145
-
146
- } else {
147
- return { result: "nop" }
148
- }
149
-
150
- }
151
-
152
-
153
- }
154
-